-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.tbs
More file actions
280 lines (205 loc) · 4.94 KB
/
Copy pathmain.tbs
File metadata and controls
280 lines (205 loc) · 4.94 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
include "global.tbh"
dim current_probe_info as probe_info
dim led_probe_timer, led_detect_timer as byte
dim pattern_timer as dword = sys.timercount32
'====================================================================
sub on_sys_init()
init_sockets()
init_LEDS()
dhcp_start(PL_SOCK_INTERFACE_NET,"","")
end sub
sub on_sys_timer()
dhcp_proc_timer()
select case current_probe_info.probe_type
case NONE:
detect_probe_type()
case else:
get_probe_reading()
end select
end sub
sub on_sock_data_arrival()
dhcp_proc_data()
end sub
sub detect_probe_type()
detect_probe_leds()
if tbt28_init(YES)=OK then
current_probe_info.probe_type=LIGHT
end if
if tbt29_init(YES)=OK then
current_probe_info.probe_type=TEMP
end if
if tbt30_init(YES)=OK then
current_probe_info.probe_type=TEMP_HUM
end if
if tbt35_init(YES)=OK then
current_probe_info.probe_type=PRESSURE
end if
if tbt36_init(NO)=OK then
current_probe_info.probe_type=ACCELEROMETER
end if
current_probe_info.reading=""
end sub
sub get_probe_reading()
polling_probe_leds()
select case current_probe_info.probe_type
case LIGHT:
if tbt28_check()<>OK then
current_probe_info.probe_type=NONE
end if
case TEMP:
if tbt29_check()<>OK then
current_probe_info.probe_type=NONE
end if
case TEMP_HUM:
if tbt30_check()<>OK then
current_probe_info.probe_type=NONE
end if
case PRESSURE:
if tbt35_check()<>OK then
current_probe_info.probe_type=NONE
end if
case ACCELEROMETER:
if tbt36_check()<>OK then
current_probe_info.probe_type=NONE
end if
end select
end sub
function parse_two_decimal_places(s as string) as string
dim decpoint as byte
decpoint=instr(1,s,".",1)
dim digitsafterpoint as byte=len(s)-decpoint
if decpoint=0 then
s=s+".00"
else if digitsafterpoint=1 then
s=s+"0"
else if digitsafterpoint>2 then
s=left(s,len(s)-digitsafterpoint+2)
end if
parse_two_decimal_places=s
end function
sub init_LEDS()
beep.divider=0
io.num=46
io.enabled=YES
io.num=47
io.enabled=YES
io.num=48
io.enabled=YES
set_LED(&b00000)
beep.divider=21600
beep.play("BB",PL_BEEP_CANINT)
pat.play(PAT_THREE_SHORT_BOTH,PL_PAT_CANINT)
sys.timercountms=0
while sys.timercountms<2000
wend
pat.play(PAT_ONE_SHORT_GREEN,PL_PAT_CANINT)
end sub
sub set_LED(pattern as byte)
dim f,x as byte
dim s as string(8)
s=mid(bin(pattern),3,8)
s=strgen(8-len(s),"0")+s
'make 5 clocks
io.num=PL_IO_NUM_47
for f=0 to 4
x=1-val(mid(s,f+4,1))
io.lineset(PL_IO_NUM_48,x)
io.state=LOW
io.state=HIGH
next f
end sub
sub polling_probe_leds()
pat.play(PAT_GREEN_ON,PL_PAT_CANINT)
led_probe_timer=led_probe_timer+1
if led_probe_timer>=2 then
set_LED(&b00000)
led_probe_timer=0
else
set_LED(&b11111)
end if
end sub
sub detect_probe_leds()
pat.play(PAT_GREEN_ON,PL_PAT_CANINT)
if sys.timercount32-pattern_timer>=1 then
if led_detect_timer<4 then
led_detect_timer=led_detect_timer+1
else
led_detect_timer=0
end if
pattern_timer = sys.timercount32
end if
select case led_detect_timer
case 0:
set_LED(&b00001)
case 1:
set_LED(&b00010)
case 2:
set_LED(&b00100)
case 3:
set_LED(&b01000)
case 4:
set_LED(&b10000)
end select
end sub
sub init_sockets()
dim f as byte
for f=8 to 15
sock.num=f
sock.txbuffrq(4)
sock.varbuffrq(4)
sock.redir(PL_REDIR_SOCK0 + sock.num)
sock.protocol=PL_SOCK_PROTOCOL_TCP
sock.inconmode=PL_SOCK_INCONMODE_ANY_IP_ANY_PORT
sock.allowedinterfaces="NET,WLN"
sock.httpportlist="80,90"
next f
sys.buffalloc()
end sub
sub callback_dhcp_ok(renew as no_yes, interface as pl_sock_interfaces, byref ip as string, byref gateway_ip as string, byref netmask as string, lease_time as dword)
if interface=PL_SOCK_INTERFACE_NET then
if renew=YES and net.ip<>ip then
sys.reboot
end if
if net.ip<>ip then
net.ip=ip
net.gatewayip=gateway_ip
net.netmask=netmask
end if
end if
if interface=PL_SOCK_INTERFACE_WLN then
if renew=YES and wln.ip<>ip then
sys.reboot
end if
if wln.ip<>ip then
wln.ip=ip
wln.gatewayip=gateway_ip
wln.netmask=netmask
end if
end if
pat.play(PAT_TWO_SHORT_GREEN,PL_PAT_CANINT)
end sub
sub callback_dhcp_failure(interface as pl_sock_interfaces,failure_code as en_dhcp_status_codes)
pat.play(PAT_LONG_RED,PL_PAT_CANINT)
end sub
sub callback_dhcp_pre_clear_ip(interface as pl_sock_interfaces)
end sub
sub callback_dhcp_pre_buffrq(required_buff_pages as byte)
end sub
sub callback_dhcp_buff_released()
end sub
sub callback_wln_failure(wln_state as en_wln_status_codes)
end sub
sub callback_wln_ok()
end sub
sub callback_wln_pre_buffrq(required_buff_pages as byte)
end sub
sub callback_wln_mkey_progress_update(progress as byte)
end sub
sub callback_wln_rescan_result(current_rssi as byte, scan_rssi as byte, different_ap as no_yes)
end sub
sub callback_wln_debugprint(print_data as string)
end sub
sub callback_wln_rescan_for_better_ap()
end sub
sub callback_wln_starting_association()
end sub