Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
fr:liste_script [2016/10/14 12:32] mifrey |
fr:liste_script [2016/11/11 00:25] (current) mifrey Correction script panique |
||
---|---|---|---|
Line 225: | Line 225: | ||
**Précisions :** Le script doit être mis dans les conditions d'une règle et être déclenché par tous les poussoirs voulus (je les ai mis tous chez moi). Il retourne true en cas de situation panique. Dans l' | **Précisions :** Le script doit être mis dans les conditions d'une règle et être déclenché par tous les poussoirs voulus (je les ai mis tous chez moi). Il retourne true en cas de situation panique. Dans l' | ||
+ | Afin de d' | ||
+ | < | ||
+ | root@raspberrypi: | ||
+ | Nov 11 00:16:34 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:34 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:34 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:34 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:34 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:34 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:34 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:35 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:35 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:35 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:35 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:35 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:35 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:46 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | |||
+ | ... | ||
+ | </ | ||
__A créer dans CALAOS INSTALLER :__ | __A créer dans CALAOS INSTALLER :__ | ||
Line 235: | Line 255: | ||
<code lua> | <code lua> | ||
-- Detect a panic situation in which switches are pressed several times within a short time. | -- Detect a panic situation in which switches are pressed several times within a short time. | ||
- | -- The script | + | -- The script |
+ | |||
--if true then return false end -- Uncomment to disable the script | --if true then return false end -- Uncomment to disable the script | ||
+ | |||
-- Script start | -- Script start | ||
local script_name = " | local script_name = " | ||
- | print(script_name .. ": | + | print(script_name .. ": |
- | + | ||
- | -- IO id | + | -- IOs id |
local timer_id = " | local timer_id = " | ||
local counter_id = " | local counter_id = " | ||
+ | |||
-- Other variables to define | -- Other variables to define | ||
local panic_count = 12 -- Number of times the state of a switch must change within a specific time (typically 2 seconds) to trigger a panic situation | local panic_count = 12 -- Number of times the state of a switch must change within a specific time (typically 2 seconds) to trigger a panic situation | ||
+ | |||
+ | -- Read IOs | ||
+ | local timer = calaos: | ||
+ | local counter = calaos: | ||
- | -- Print timer and counter value at script start | + | print(script_name .. ": timer = " .. tostring(timer)) |
- | print(script_name .. ": timer = " .. tostring(calaos: | + | print(script_name .. ": counter = " .. tostring(counter)) |
- | print(script_name .. ": counter = " .. tostring(calaos: | + | |
- | -- Get timer status: Timer is false when timer starts | + | |
- | local timer = calaos:getInputValue(timer_id) -- ATTENTION: getInputValue(InputTimer type) returns a string type | + | -- Max time exceeded or first count |
+ | if timer == " | ||
+ | print(script_name .. ": Max time exceeded, restart | ||
+ | -- Restart timer | ||
+ | timer = " | ||
+ | calaos:setOutputValue(timer_id, timer) | ||
+ | print(script_name .. ": Set timer = " .. tostring(timer)) | ||
+ | -- First count | ||
+ | counter = 1; | ||
+ | calaos:setOutputValue(counter_id, counter) | ||
+ | print(script_name .. ": Set counter = " .. tostring(counter)) | ||
+ | print(script_name .. ": End" | ||
+ | return false | ||
+ | -- Max time not exceeded | ||
+ | else | ||
+ | -- Count up | ||
+ | counter = counter + 1 | ||
+ | calaos: | ||
+ | print(script_name .. ": Max time not exceeded, count up. Set counter = " .. tostring(counter)) | ||
- | -- Timer is done, reset timer and counter. | + | -- Counts not reached, wait for the next count. |
- | if timer == " | + | if counter < panic_count |
- | print(script_name .. ": | + | print(script_name .. ": |
- | | + | print(script_name .. ": end") |
- | calaos: | + | return false |
- | print(script_name .. ": timer = " .. tostring(calaos: | + | -- Counts reached, panic mode. |
- | print(script_name .. ": counter = " .. tostring(calaos: | + | else |
- | print(script_name .. ": end" | + | print(script_name .. ": Counts reached, panic mode." |
- | return | + | -- Stop timer |
+ | timer = " | ||
+ | calaos: | ||
+ | print(script_name .. ": | ||
+ | -- Reset counter | ||
+ | counter = 0; | ||
+ | calaos:setOutputValue(counter_id, counter) | ||
+ | print(script_name .. ": | ||
+ | print(script_name .. ": end" | ||
+ | return | ||
+ | end | ||
end | end | ||
- | -- Increment the counter | ||
- | local counter = calaos: | ||
- | calaos: | ||
- | |||
- | -- Timer is not done and counts not reached, continues to count. | ||
- | if counter < panic_count then | ||
- | print(script_name .. ": Timer is not done and counts not reached, continue." | ||
- | print(script_name .. ": timer = " .. tostring(calaos: | ||
- | print(script_name .. ": counter = " .. tostring(calaos: | ||
- | print(script_name .. ": end") | ||
- | return false | ||
- | -- Timer is not done and counts reached, panic mode. | ||
- | else | ||
- | print(script_name .. ": Timer is not done and counts reached, panic mode." | ||
- | print(script_name .. ": timer = " .. tostring(calaos: | ||
- | print(script_name .. ": counter = " .. tostring(calaos: | ||
- | calaos: | ||
- | calaos: | ||
- | print(script_name .. ": end") | ||
- | return true | ||
- | end | ||
print(script_name .. ": Oups, should never be there..." | print(script_name .. ": Oups, should never be there..." | ||
Line 311: | Line 341: | ||
Afin de d' | Afin de d' | ||
< | < | ||
- | root@raspberrypi: | + | root@raspberrypi: |
Oct 14 12:01:59 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | Oct 14 12:01:59 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | ||
Oct 14 12:01:59 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | Oct 14 12:01:59 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: |