From 7554adf9414d7baf351f0b1ae11a9007f2532095 Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Wed, 3 Mar 2010 15:40:23 +0000 Subject: [PATCH] PanicButton Entprellung --- powersensordaemon/COMMANDS.txt | 17 +++++++++++++++++ rf433ctl/rf433ctl.pde | 37 +++++++++++++++++++++++++------------ 2 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 powersensordaemon/COMMANDS.txt diff --git a/powersensordaemon/COMMANDS.txt b/powersensordaemon/COMMANDS.txt new file mode 100644 index 0000000..ced3a29 --- /dev/null +++ b/powersensordaemon/COMMANDS.txt @@ -0,0 +1,17 @@ + +== Commands accepted by daemon == + +COMMAND:= power $LICHTID (on|off) | listen $EVENT | sample $SAMPLEDEV +LICHTID:= werkzeug | stereo | labor | schreibtisch | logo | idee +EVENT:= all | temp | movement | button +SAMPLEDEV:=temp[0-9]+ + +== Replys of daemon == + +CMDREPLY:= ok | error $ERRORSTR +ERRORSTR:=no connection | unknown device | .... + +== Listener Data from Daemon == +(Temperature Data in Degrees Celsius) + +LISTENERDATA:=temp[0-9]+ [0-9]{1,3}\.[0-9]{2} | movement | button[0-9] \ No newline at end of file diff --git a/rf433ctl/rf433ctl.pde b/rf433ctl/rf433ctl.pde index 0a7abac..ef1263c 100644 --- a/rf433ctl/rf433ctl.pde +++ b/rf433ctl/rf433ctl.pde @@ -10,10 +10,11 @@ #define IR_MOVEMENT_PIN 9 #define ONE_WIRE_PIN 8 #define PANIC_BUTTON_PIN 7 +//movement is reported if during IR_SAMPLE_DURATION at least IR_TRESHOLD ir signals are detectd #define IR_SAMPLE_DURATION 20000 #define IR_TRESHOLD 13000 -#define PB_SAMPLE_DURATION 5000 -#define PB_TRESHOLD 5000 +//duration PanicButton needs to be pressed before status change occurs (i.e. for two PanicButton Repots, the buttons needs to be pressed 1000 cycles, releases 1000 cycles and again pressed 1000 cycles) +#define PB_TRESHOLD 1000 OneWire onewire(ONE_WIRE_PIN); DallasTemperature dallas_sensors(&onewire); @@ -227,15 +228,19 @@ void setup() unsigned int ir_time=IR_SAMPLE_DURATION; unsigned int ir_count=0; -unsigned int pb_time=PB_SAMPLE_DURATION; -unsigned int pb_count=0; +boolean pb_last_state=0; +boolean pb_state=0; +boolean pb_postth_state=0; +unsigned int pb_time=0; void loop() { ir_time--; - pb_time--; ir_count += (digitalRead(IR_MOVEMENT_PIN) == HIGH); - pb_count += (digitalRead(PANIC_BUTTON_PIN) == LOW); + + if (pb_time < PB_TRESHOLD) + pb_time++; + pb_state=(digitalRead(PANIC_BUTTON_PIN) == LOW); if (ir_time == 0) { @@ -244,15 +249,23 @@ void loop() ir_time=IR_SAMPLE_DURATION; ir_count=0; } - - if (pb_time == 0) + + if (pb_state == pb_last_state && pb_time >= PB_TRESHOLD) { - if (pb_count >= PB_TRESHOLD) + if (pb_state && ! pb_postth_state) + { + pb_postth_state=1; Serial.println("PanicButton"); - pb_time=PB_SAMPLE_DURATION; - pb_count=0; + } + else if (!pb_state) + pb_postth_state=0; } - + else if (pb_state != pb_last_state) + { + pb_time=0; + pb_last_state=pb_state; + } + if(Serial.available()) { char command = Serial.read(); -- 1.7.10.4