2023-06-06 05:19:51 +02:00
|
|
|
# Kompenzacija propelerjev
|
|
|
|
kompenzacija = 0.5
|
|
|
|
|
|
|
|
# Kako dolgo cakam med ukazi (ms)?
|
|
|
|
cakaj = 3000
|
|
|
|
|
|
|
|
# Kako pogosto grem kar ravno (ms)?
|
2023-06-06 15:57:17 +02:00
|
|
|
kar_naprej_cas = 1.5 * 60 * 1000
|
2023-06-06 05:19:51 +02:00
|
|
|
|
|
|
|
zadnji = 0
|
|
|
|
|
2023-06-06 15:57:17 +02:00
|
|
|
def nic()
|
|
|
|
print('ja, nic')
|
|
|
|
end
|
|
|
|
tasmota.add_cmd('KarNaprej', nic)
|
|
|
|
|
2023-03-21 03:32:00 +01:00
|
|
|
def ugasni_levo()
|
|
|
|
tasmota.set_power(0, false)
|
|
|
|
end
|
|
|
|
|
|
|
|
def ugasni_desno()
|
|
|
|
tasmota.set_power(1, false)
|
|
|
|
end
|
|
|
|
|
2023-06-06 05:19:51 +02:00
|
|
|
def posodobi_zadnji(cas)
|
|
|
|
zadnji = tasmota.millis() + cas
|
2023-06-06 15:57:17 +02:00
|
|
|
tasmota.cmd('KarNaprej')
|
2023-06-06 05:19:51 +02:00
|
|
|
end
|
|
|
|
|
2023-03-21 03:32:00 +01:00
|
|
|
# payload = kako dolgo naj bo vklopljen, v milisekundah
|
|
|
|
def pojdi_levo(cmd, idx, payload, payload_json)
|
2023-06-06 13:26:26 +02:00
|
|
|
if tasmota.millis() < zadnji + cakaj return nil end
|
2023-06-06 05:19:51 +02:00
|
|
|
|
2023-03-21 03:32:00 +01:00
|
|
|
tasmota.set_power(0, true)
|
2023-06-06 05:19:51 +02:00
|
|
|
|
|
|
|
var cas = int(int(payload) * kompenzacija)
|
|
|
|
tasmota.set_timer(cas, ugasni_levo)
|
|
|
|
|
|
|
|
posodobi_zadnji(cas)
|
2023-06-06 15:57:17 +02:00
|
|
|
#kar_naprej()
|
2023-03-21 03:32:00 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# payload = kako dolgo naj bo vklopljen, v milisekundah
|
|
|
|
def pojdi_desno(cmd, idx, payload, payload_json)
|
2023-06-06 13:26:26 +02:00
|
|
|
if tasmota.millis() < zadnji + cakaj return nil end
|
2023-06-06 05:19:51 +02:00
|
|
|
|
2023-03-21 03:32:00 +01:00
|
|
|
tasmota.set_power(1, true)
|
2023-06-06 05:19:51 +02:00
|
|
|
|
|
|
|
var cas = int(payload)
|
|
|
|
tasmota.set_timer(cas, ugasni_desno)
|
|
|
|
|
|
|
|
posodobi_zadnji(cas)
|
2023-03-21 03:32:00 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def ugasni_vse()
|
|
|
|
ugasni_levo()
|
|
|
|
ugasni_desno()
|
|
|
|
end
|
|
|
|
|
|
|
|
# payload = kako dolgo naj bo vklopljen, v milisekundah
|
|
|
|
def pojdi_ravno(cmd, idx, payload, payload_json)
|
2023-06-06 13:26:26 +02:00
|
|
|
if tasmota.millis() < zadnji + cakaj return nil end
|
2023-06-06 05:19:51 +02:00
|
|
|
|
2023-03-21 03:32:00 +01:00
|
|
|
tasmota.set_power(0, true)
|
|
|
|
tasmota.set_power(1, true)
|
2023-06-06 05:19:51 +02:00
|
|
|
|
|
|
|
#tasmota.set_timer(int(payload), ugasni_vse)
|
|
|
|
# Kompenziramo razliko v motorjih
|
2023-06-06 15:57:17 +02:00
|
|
|
var cas = int(payload) * 2
|
2023-06-06 05:19:51 +02:00
|
|
|
tasmota.set_timer(int(cas * kompenzacija), ugasni_levo)
|
|
|
|
tasmota.set_timer(cas, ugasni_desno)
|
|
|
|
|
|
|
|
posodobi_zadnji(cas)
|
|
|
|
end
|
|
|
|
|
|
|
|
def auto_naprej()
|
|
|
|
pojdi_ravno(nil, nil, 1000)
|
|
|
|
end
|
|
|
|
|
|
|
|
def kar_naprej()
|
2023-06-06 15:57:17 +02:00
|
|
|
tasmota.remove_timer("auto_naprej")
|
2023-06-06 05:19:51 +02:00
|
|
|
tasmota.set_timer(kar_naprej_cas, auto_naprej, "auto_naprej")
|
2023-03-21 03:32:00 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
tasmota.add_cmd('PojdiLevo', pojdi_levo)
|
|
|
|
tasmota.add_cmd('PojdiDesno', pojdi_desno)
|
|
|
|
tasmota.add_cmd('PojdiRavno', pojdi_ravno)
|
|
|
|
tasmota.add_cmd('UgasniVse', ugasni_vse)
|
2023-06-06 15:57:17 +02:00
|
|
|
tasmota.add_cmd('KarNaprej', kar_naprej)
|
|
|
|
|
|
|
|
def inicializiraj()
|
|
|
|
tasmota.cmd('WcInit')
|
|
|
|
end
|
|
|
|
tasmota.set_timer(5000, inicializiraj)
|