Skip to content

Commit af0560b

Browse files
committed
Update NeoPool example
1 parent bcc07eb commit af0560b

File tree

1 file changed

+52
-18
lines changed

1 file changed

+52
-18
lines changed

docs/NeoPool.md

+52-18
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,29 @@ Store the following code using the WebGUI "Console" / "Manage File system".
495495

496496
ESP32 file `neopool.be`:
497497
```python
498-
class NeoPoolCommands
498+
# Neopool definitions
499+
var MBF_RELAY_STATE = 0x010E
500+
var MBF_NOTIFICATION = 0x0110
501+
var MBF_CELL_BOOST = 0x020C
502+
503+
var MBF_PAR_TIMER_BLOCK_AUX1_INT1 = 0x04AC
504+
var MBF_PAR_TIMER_BLOCK_AUX2_INT1 = 0x04BB
505+
var MBF_PAR_TIMER_BLOCK_AUX3_INT1 = 0x04CA
506+
var MBF_PAR_TIMER_BLOCK_AUX4_INT1 = 0x04D9
507+
var PAR_TIMER_BLOCK_AUX = [
508+
MBF_PAR_TIMER_BLOCK_AUX1_INT1,
509+
MBF_PAR_TIMER_BLOCK_AUX2_INT1,
510+
MBF_PAR_TIMER_BLOCK_AUX3_INT1,
511+
MBF_PAR_TIMER_BLOCK_AUX4_INT1
512+
]
513+
var MBV_PAR_CTIMER_ALWAYS_ON = 3
514+
var MBV_PAR_CTIMER_ALWAYS_OFF = 4
515+
516+
# NeoPool command class
517+
class Commands
499518
var TEXT_OFF
500519
var TEXT_ON
520+
var TEXT_TOGGLE
501521

502522
# string helper
503523
def ltrim(s)
@@ -514,12 +534,13 @@ class NeoPoolCommands
514534
end
515535

516536
# NPBoost OFF|0|ON|1|REDOX|2
517-
# 0|OFF: Switch boost off
518-
# 1|ON: Switch boost on without redox control
519-
# 2|REDOX: Switch boost on with redox control
537+
# 0|OFF: Switch boost off
538+
# 1|ON: Switch boost on without redox control
539+
# 2|REDOX: Switch boost on with redox control
520540
def NPBoost(cmd, idx, payload)
521541
import string
522542
var ctrl, parm
543+
523544
try
524545
parm = string.toupper(self.trim(payload))
525546
except ..
@@ -536,21 +557,25 @@ class NeoPoolCommands
536557
tasmota.resp_cmnd_error()
537558
return
538559
end
539-
tasmota.cmd(string.format("Backlog NPWrite 0x020C,0x%04X;NPSave;NPExec;NPWrite 0x0110,0x7F", ctrl))
560+
tasmota.cmd(string.format("NPWrite 0x%04X,0x%04X", MBF_CELL_BOOST, ctrl))
561+
tasmota.cmd("NPSave")
562+
tasmota.cmd("NPExec")
563+
tasmota.cmd(string.format("NPWrite 0x%04X,0x7F", MBF_NOTIFICATION))
540564
else
541565
try
542-
ctrl = compile("return "+str(tasmota.cmd("NPRead 0x020C")['NPRead']['Data']))()
566+
ctrl = compile("return "..tasmota.cmd(string.format("NPRead 0x%04X", MBF_CELL_BOOST))['NPRead']['Data'])()
543567
except ..
544568
tasmota.resp_cmnd_error()
545569
return
546570
end
547571
end
548-
tasmota.resp_cmnd(string.format('{"NPBoost":"%s"}', ctrl == 0 ? self.TEXT_OFF : (ctrl & 0x8500) == 0x8500 ? self.TEXT_ON : "REDOX"))
572+
tasmota.resp_cmnd(string.format('{"%s":"%s"}', cmd, ctrl == 0 ? self.TEXT_OFF : (ctrl & 0x8500) == 0x8500 ? self.TEXT_ON : "REDOX"))
549573
end
550574

551-
# NPAux<x> OFF|0|ON|1 (<x> = 1..4)
552-
# 0|OFF: Switch aux x off
553-
# 1|ON: Switch aux x on
575+
# NPAux<x> OFF|0|ON|1 t (<x> = 1..4)
576+
# 0|OFF: Switch Aux x to off
577+
# 1|ON: Switch Aux x to on
578+
# 2|TOGGLE: Toggle Aux x
554579
def NPAux(cmd, idx, payload)
555580
import string
556581
var ctrl, parm
@@ -567,40 +592,49 @@ class NeoPoolCommands
567592
end
568593
if parm != ""
569594
if string.find(parm, 'OFF')>=0 || string.find(parm, self.TEXT_OFF)>=0 || string.find(parm, '0')>=0
570-
ctrl = 4
595+
ctrl = MBV_PAR_CTIMER_ALWAYS_OFF
571596
elif string.find(parm, 'ON')>=0 || string.find(parm, self.TEXT_ON)>=0 || string.find(parm, '1')>=0
572-
ctrl = 3
597+
ctrl = MBV_PAR_CTIMER_ALWAYS_ON
598+
elif string.find(parm, 'TOGGLE')>=0 || string.find(parm, self.TEXT_TOGGLE)>=0 || string.find(parm, '2')>=0
599+
try
600+
ctrl = (compile("return "..tasmota.cmd(string.format("NPRead 0x%04X", MBF_RELAY_STATE))['NPRead']['Data'])() >> (idx+2)) & 1 ? MBV_PAR_CTIMER_ALWAYS_OFF : MBV_PAR_CTIMER_ALWAYS_ON
601+
except ..
602+
tasmota.resp_cmnd_error()
603+
return
604+
end
573605
else
574606
tasmota.resp_cmnd_error()
575607
return
576608
end
577-
tasmota.cmd(string.format("Backlog NPWrite 0x%04X,%d;NPExec", [0x04AC, 0x04BB, 0x04CA, 0x04D9][idx-1], ctrl))
609+
tasmota.cmd(string.format("NPWrite 0x%04X,%d", PAR_TIMER_BLOCK_AUX[idx-1], ctrl))
610+
tasmota.cmd("NPExec")
578611
else
579612
try
580-
ctrl = (compile("return "+str(tasmota.cmd("NPRead 0x010E")['NPRead']['Data']))() >> (idx+2)) & 1
613+
ctrl = (compile("return "..tasmota.cmd(string.format("NPRead 0x%04X", MBF_RELAY_STATE))['NPRead']['Data'])() >> (idx+2)) & 1
581614
except ..
582615
tasmota.resp_cmnd_error()
583616
return
584617
end
585618
end
586-
tasmota.resp_cmnd(string.format('{"NPAux%d":"%s"}', idx, ctrl == (parm != "" ? 4 : 0) ? self.TEXT_OFF : self.TEXT_ON))
587619
end
588620

589621
def init()
622+
# get tasmota settings
590623
self.TEXT_OFF = tasmota.cmd("StateText1")['StateText1']
591624
self.TEXT_ON = tasmota.cmd("StateText2")['StateText2']
592-
# Add commands
625+
self.TEXT_TOGGLE = tasmota.cmd("StateText3")['StateText3']
626+
# add commands
593627
tasmota.add_cmd('NPBoost', / cmd, idx, payload -> self.NPBoost(cmd, idx, payload))
594628
tasmota.add_cmd('NPAux', / cmd, idx, payload -> self.NPAux(cmd, idx, payload))
595629
end
596630

597631
def deinit()
632+
# remove commands
598633
tasmota.remove_cmd('NPBoost')
599634
tasmota.remove_cmd('NPAux')
600635
end
601636
end
602-
603-
neopool_commands = NeoPoolCommands()
637+
commands = Commands()
604638
```
605639

606640
To activate the new commands go to WebGUI "Consoles" / "Berry Scripting console" and execute

0 commit comments

Comments
 (0)