-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathinit.forth
More file actions
72 lines (57 loc) · 1.77 KB
/
Copy pathinit.forth
File metadata and controls
72 lines (57 loc) · 1.77 KB
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
71
72
: between ( n low high -- flag )
>r over r> <= >r >= r> and ;
: 2drop ( x1 x2 -- )
drop drop ;
: 2dup ( x1 x2 -- x1 x2 x1 x2 )
over over ;
: 2over ( x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2 )
3 pick 3 pick ;
: 2swap ( x1 x2 x3 x4 -- x3 x4 x1 x2 )
rot >r rot r> ;
: load-srv ( filename -- ) \ Load a forth file from the server
>r nil server-url @ :: "/" :: r> :: str-join http-get
drop \ drop header
evaluate ; \ evaluate the content
: reload-init ( -- ) \ Reload init.forth
"init.forth" load-srv ;
: play-midi-acquired 0 play-midi ;
: play-midi-ack 4 play-midi ;
: load-info-animation ( filename anim_num -- ) \ Load info animation from the server
>r >r nil server-url @ :: "/" :: r> :: str-join
http-get drop json-parse
r> set-info-animation
;
: get-hour ( -- hour ) \ Get the current hour
time&date drop drop drop swap drop swap drop ;
: get-minute ( -- minute ) \ Get the current minute
time&date drop drop drop drop swap drop ;
: sleeping-time? ( -- flag ) \ Check if current hour is in the sleep interval
wake-up-at @ go-to-bed-at @ = if \ always awake if equal
false
else
get-hour
dup \ dup hour
wake-up-at @ <
swap \ swap hour and flag
go-to-bed-at @ >=
or
then ;
: daytime ( -- ) \ Display the current time (UTC)
utc>string . cr ;
"config.forth" load-srv
"consts.forth" load-srv
"hooks.forth" load-srv
"weather.forth" load-srv
"telnet.forth" load-srv
"crontab.forth" load-srv
"choreography.forth" load-srv
\ "palette.forth" load-srv
: on-connect ( -- )
"interpreter" 23 "telnet" tcp-listen \ start telnet server
"daytime" 21 "daytime" tcp-listen \ start daytime server
"update-weather" weather-time-delay "weather" task-start \ start weather update
"crontab" 59000 "crontab" task-start \ start crontab
crontab
update-weather
sleeping-time? if sleep else wake-up then
;