From 8df3217731eb8b7847b5d4a5de691a391d72f8c6 Mon Sep 17 00:00:00 2001 From: Dooho Yi Date: Thu, 8 Apr 2021 21:23:40 +0900 Subject: [PATCH] watcher added @ roller --- roller/src/main.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/roller/src/main.cpp b/roller/src/main.cpp index ce44dfd..f62ab50 100644 --- a/roller/src/main.cpp +++ b/roller/src/main.cpp @@ -21,7 +21,7 @@ //======================== // #define MY_GROUP_ID (4000) -#define MY_ID (MY_GROUP_ID + 403) +#define MY_ID (MY_GROUP_ID + 1) #define MY_SIGN ("ROLLER") // //======================== @@ -96,6 +96,7 @@ Scheduler runner; #define MOTOR_1B (D5) // my tasks int speed = 0; +bool isactive = false; void set_speed() { int r = speed; // @@ -108,19 +109,34 @@ void set_speed() { } MONITORING_SERIAL.print("set_speed:"); MONITORING_SERIAL.println(r); + isactive = true; } Task set_speed_task(0, TASK_ONCE, &set_speed); // void rest() { analogWrite(MOTOR_1A, LOW); analogWrite(MOTOR_1B, LOW); + isactive = false; } Task rest_task(0, TASK_ONCE, &rest); +// +uint8_t watch_counter = 0; +void watcher() { + if (isactive) { + if (watch_counter > 3) { + rest_task.restartDelayed(10); + watch_counter = 0; + } else { + watch_counter++; + } + } +} +Task watcher_task(1000, TASK_FOREVER, &watcher, &runner, true); //*-*-*-*-*-*-*-*-*-*-*-*-* // extern Task hello_task; -static int hello_delay = 0; +static int hello_delay = 2000; void hello() { // byte mac[6]; @@ -133,7 +149,7 @@ void hello() { count++; hello.h1 = (count % 1000); hello.h2 = speed; - // hello.h3 = 0; + hello.h3 = (isactive ? 1 : 0); // hello.h4 = 0; // uint8_t frm_size = sizeof(Hello) + 2; @@ -192,6 +208,7 @@ void onNoteHandler(Note & n) { // if (n.onoff == 1) { set_speed_task.restartDelayed(10); + watch_counter = 0; } else if (n.onoff == 0) { rest_task.restartDelayed(10); }