-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.toit
70 lines (61 loc) · 1.48 KB
/
main.toit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import gpio
import gpio.pwm
import math
import esp32
import log
import core.utils
import net
import esp32.espnow
import device
import encoding.json
import encoding.ubjson
import system.firmware
import system.api.containers
import system.assets
import system
import system.storage
import encoding.tison
import .sync
import .firefly
import .communication
import .led
// import .ws2812
import .ambient-light
import .upgrade
INTERVAL ::= Duration --us=100
TARGET-SPEED ::= 1000
// Length of a subcycle in us
speed := TARGET-SPEED
CYCLE-LENGTH ::= 5000
// How many cycle steps were taken
cycle-progress := 0
// How many us were already spend in this substep
unprocessed-delta := 0
device-name:
config := {:}
assets.decode.get "config" --if-present=: | encoded |
catch: config = tison.decode encoded
return config.get "name"
main args:
init-communication
print "Hey, my name is $device-name"
enforce-upgrade
//firefly := Firefly device-name 490000;
firefly := Firefly device-name 1000000
firefly.dampening = 0.95
task::
ambient-light-task
task::
receiver-task::
firefly.receive-pulse it
last-time := Time.monotonic-us --since-wakeup=true
while true:
catch --trace:
time := Time.monotonic-us --since-wakeup=true
delta := time - last-time
last-time = time
firefly.tick delta
my-brightness := firefly.brightness
// print brightness
set-brightness (1 + ( math.sin ((my-brightness * 6.14159) / 255.0)))/2.0
sleep INTERVAL