16
16
layout HLayout
17
17
groupbox Group
18
18
label Label
19
- label MasterDeviceLabel
20
19
label RelayStateLabel
21
20
label StatusLabel
22
21
pushbutton ResetConfigButton
23
- pushbutton ScanNetworkButton
24
- pushbutton SelectMasterButton
25
- pushbutton SelectSlaveButton
22
+ pushbutton ScanDevicesButton
23
+ pushbutton ClearSystemButton
26
24
pushbutton DeleteSlaveButton
27
- pushbutton UpdateSlaveButton
25
+ pushbutton UpdateDeviceButton
28
26
pushbutton DeleteFileButton
29
27
pushbutton ExitButton
30
28
pushbutton ScanSystemsButton
31
29
pushbutton RemoveSystemButton
30
+ pushbutton MasterDeviceButton
32
31
pushbutton RelayOffButton
33
32
pushbutton RelayOnButton
34
33
pushbutton SaveWidgetDataButton
59
58
60
59
create LeftPanel type QVBoxLayout
61
60
add LeftPanel to MainPanel
62
- create ResetConfigButton text `Reset config `
61
+ create ResetConfigButton text `Reset everything `
63
62
on click ResetConfigButton go to ResetConfigFileClick
64
63
add ResetConfigButton to LeftPanel
65
64
66
- create ScanNetworkButton text `Scan network `
67
- on click ScanNetworkButton go to ScanNetworkClick
68
- add ScanNetworkButton to LeftPanel
65
+ create ClearSystemButton text `Clear the selected system `
66
+ on click ClearSystemButton go to ClearSystemClick
67
+ add ClearSystemButton to LeftPanel
69
68
70
- create SelectMasterButton text `Select master `
71
- on click SelectMasterButton go to SelectMasterClick
72
- add SelectMasterButton to LeftPanel
69
+ create ScanDevicesButton text `Scan for devices `
70
+ on click ScanDevicesButton go to ScanNetworkClick
71
+ add ScanDevicesButton to LeftPanel
73
72
74
- create SelectSlaveButton text `Select slave`
75
- on click SelectSlaveButton go to SelectSlaveClick
76
- add SelectSlaveButton to LeftPanel
77
-
78
- create UpdateSlaveButton text `Update slave`
79
- on click UpdateSlaveButton go to UpdateSlaveClick
80
- add UpdateSlaveButton to LeftPanel
73
+ create UpdateDeviceButton text `Update device`
74
+ on click UpdateDeviceButton go to UpdateDeviceClick
75
+ add UpdateDeviceButton to LeftPanel
81
76
82
77
create DeleteFileButton text `Delete file`
83
78
add DeleteFileButton to LeftPanel
107
102
create SystemsCombo
108
103
on select SystemsCombo go to SystemsComboSelect
109
104
add stretch SystemsCombo to Layout
110
- create ScanSystemsButton text `Scan`
105
+ create ScanSystemsButton text `System Scan`
111
106
disable ScanSystemsButton
112
107
on click ScanSystemsButton go to ScanSystemsClick
113
108
add ScanSystemsButton to Layout
122
117
add Group to RightPanel
123
118
create Layout type QHBoxLayout
124
119
add Layout to Group
125
- create MasterDeviceLabel text `(none)`
126
- add MasterDeviceLabel to Layout
120
+ create MasterDeviceButton text `(none)`
121
+ add MasterDeviceButton to Layout
122
+ on click MasterDeviceButton go to MasterDeviceClick
127
123
128
124
! Create the Slave Devices group
129
125
create Group title `Slave devices`
133
129
add Layout to Group
134
130
create SlaveList
135
131
add SlaveList to Layout
132
+ on select SlaveList go to SelectSlaveClick
136
133
137
134
! Create the Selected Device group
138
135
create Group title `Selected device`
246
243
variable MasterDevice
247
244
variable MasterSSID
248
245
variable MasterIPAddr
246
+ variable MasterDeviceName
249
247
variable SlaveDevices
250
248
variable RBRFlag
251
249
variable Keys
260
258
! The main program starts here
261
259
Start:
262
260
261
+ ! Disable various buttons
262
+ disable ClearSystemButton
263
+ disable ScanDevicesButton
264
+ disable DeleteSlaveButton
265
+ disable UpdateDeviceButton
266
+ disable DeleteFileButton
267
+
263
268
! Load the main config file or create one if there is none
264
269
put trim system `echo $HOME` cat `/.rbr.conf` into ConfigFile
265
270
load Config from ConfigFile
@@ -311,28 +316,87 @@ Start:
311
316
if Name is not empty
312
317
begin
313
318
select Name in SystemsCombo
319
+ enable ClearSystemButton
314
320
gosub to SetupSystem
315
321
end
316
322
317
323
enable ScanSystemsButton
324
+ enable ScanDevicesButton
318
325
stop
319
326
320
327
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
321
328
! Event handlers
322
329
ResetConfigFileClick:
323
- delete file ConfigFile
324
- disable ScanSystemsButton
325
- go to Start
330
+ create MessageBox on Window
331
+ style question
332
+ title `Master reset`
333
+ message `This will remove all information. Continue?`
334
+ show MessageBox giving Value
335
+ if Value is `Yes`
336
+ begin
337
+ delete file ConfigFile
338
+ disable RemoveSystemButton
339
+ set the text of MasterDeviceButton to `(none)`
340
+ clear SlaveList
341
+ go to Start
342
+ end
343
+ stop
326
344
327
- SelectMasterClick:
328
- log `Select the master device`
345
+ ClearSystemClick:
346
+ create MessageBox on Window
347
+ style question
348
+ title `System clear`
349
+ message `This will remove all devices from ` cat SystemsCombo
350
+ cat `. Continue?`
351
+ show MessageBox giving Value
352
+ if Value is `Yes`
353
+ begin
354
+ put SystemsCombo into Name
355
+ put property Name of Systems into SystemConfig
356
+ put property `mac` of SystemConfig into MAC
357
+ put property `password` of SystemConfig into Password
358
+ put json `{}` into Devices
359
+ set property `devices` of SystemConfig to Devices
360
+ set property Name of Systems to SystemConfig
361
+ set property `systems` of Config to Systems
362
+ post stringify SystemConfig to
363
+ `https://rbrheating.com/ui/resources/php/rest.php/config/`
364
+ cat MAC cat `/` cat Password
365
+ or begin
366
+ log `I couldn't post the config file`
367
+ stop
368
+ end
369
+ disable RemoveSystemButton
370
+ set the text of MasterDeviceButton to `(none)`
371
+ clear SlaveList
372
+ end
373
+ stop
374
+
375
+ ScanNetworkClick:
376
+ log `Scan the network for new devices`
377
+ stop
378
+
379
+ MasterDeviceClick:
380
+ log MasterDeviceButton
381
+ if MasterDeviceButton is not empty
382
+ begin
383
+ log `Select the master device`
384
+ set the text of DeviceNameInput to MasterDeviceName
385
+ enable UpdateDeviceButton
386
+ enable DeleteFileButton
387
+ disable DeleteSlaveButton
388
+ end
329
389
stop
330
390
331
391
SelectSlaveClick:
332
- log `Select a slave device`
392
+ log `Select ` cat SlaveList
393
+ set the text of DeviceNameInput to SlaveList
394
+ enable UpdateDeviceButton
395
+ enable DeleteSlaveButton
396
+ enable DeleteFileButton
333
397
stop
334
398
335
- UpdateSlaveClick :
399
+ UpdateDeviceClick :
336
400
log `Update the files om the selected device`
337
401
stop
338
402
@@ -344,12 +408,6 @@ DeleteSlaveClick:
344
408
log `Delete the selected slave device`
345
409
stop
346
410
347
- ExitClick:
348
- log `Exit the configurator`
349
- save stringify Config to ConfigFile
350
- close Window
351
- exit
352
-
353
411
ScanSystemsClick:
354
412
log `Scan systems`
355
413
gosub to ScanSystems
@@ -358,7 +416,9 @@ ScanSystemsClick:
358
416
stop
359
417
360
418
SystemsComboSelect:
361
- set property `current` of Config to SystemsCombo
419
+ put SystemsCombo into Name
420
+ set property `current` of Config to Name
421
+ gosub to SetupSystem
362
422
stop
363
423
364
424
RemoveSystemClick:
@@ -367,7 +427,7 @@ RemoveSystemClick:
367
427
create MessageBox on Window
368
428
style question
369
429
title `Remove system`
370
- message `Are you sure you want to remove ` cat Name cat `?`
430
+ message `Continue you want to remove ` cat Name cat `?`
371
431
show MessageBox giving Value
372
432
if Value is `Yes`
373
433
begin
@@ -394,6 +454,12 @@ RelayOnClick:
394
454
log `Turn the relay ON`
395
455
stop
396
456
457
+ ExitClick:
458
+ log `Exit the configurator`
459
+ save stringify Config to ConfigFile
460
+ close Window
461
+ exit
462
+
397
463
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
398
464
! Subroutines
399
465
@@ -542,6 +608,7 @@ ScanSystems:
542
608
gosub to Working
543
609
get Result from url `http://` cat IPAddr cat `:17348/cgi-bin/mac.py` timeout 1 or go to SS2
544
610
put trim Result into Result
611
+ log IPAddr cat `: ` cat Result
545
612
put the position of ` ` in Result into P
546
613
put left P of Result into MAC
547
614
increment P
@@ -579,7 +646,9 @@ GetConfigData:
579
646
or log `Can't read the config file for ` cat Name
580
647
! log Value cat newline
581
648
put json Value into Value
582
- set property `devices` of SystemConfig to property `devices` of Value
649
+ if Value has property `devices`
650
+ set property `devices` of SystemConfig to property `devices` of Value
651
+ else set property `devices` of SystemConfig to json `{}`
583
652
set property Name of Systems to SystemConfig
584
653
increment S
585
654
end
@@ -604,11 +673,14 @@ RefreshSystemsCombo:
604
673
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
605
674
! Set up the system, given its name
606
675
SetupSystem:
676
+ if Name is empty return
607
677
put property Name of Systems into System
608
678
put property `devices` of System into Devices
609
679
put the keys of Devices into Keys
610
680
put empty into MasterDevice
681
+ set the text of MasterDeviceButton to `(none)`
611
682
put json `[]` into SlaveDevices
683
+ clear SlaveList
612
684
put 0 into D
613
685
while D is less than the count of Keys
614
686
begin
@@ -619,7 +691,8 @@ SetupSystem:
619
691
put Device into MasterDevice
620
692
put property `ssid` of MasterDevice into MasterSSID
621
693
put property `ipaddr` of MasterDevice into MasterIPAddr
622
- set the text of MasterDeviceLabel to MasterSSID cat ` ` cat Name cat ` ` cat MasterIPAddr
694
+ put Name into MasterDeviceName
695
+ set the text of MasterDeviceButton to MasterSSID cat ` ` cat MasterIPAddr cat ` ` cat Name
623
696
end
624
697
else
625
698
begin
0 commit comments