From fa24699086529c565aa89a60b4bab9c367e136f1 Mon Sep 17 00:00:00 2001 From: Alessandro Monticelli Date: Tue, 5 Dec 2023 14:17:07 +0100 Subject: [PATCH 1/7] [CONF] Remove TimerOne --- smart_bridge/platformio.ini | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/smart_bridge/platformio.ini b/smart_bridge/platformio.ini index 0e3c3a7..8c92aeb 100644 --- a/smart_bridge/platformio.ini +++ b/smart_bridge/platformio.ini @@ -16,6 +16,5 @@ board = uno framework = arduino lib_deps = marcoschwartz/LiquidCrystal_I2C@^1.1.4 - Wire - paulstoffregen/TimerOne@^1.1.1 nabontra/ServoTimer2@0.0.0-alpha+sha.2bf7fb3c17 + Wire From 0342d0adde5abff457f277cc419ba75dc08c4fc2 Mon Sep 17 00:00:00 2001 From: Alessandro Monticelli Date: Tue, 5 Dec 2023 16:18:36 +0100 Subject: [PATCH 2/7] Optimize ram consumption --- smart_bridge/lib/README | 2 +- smart_bridge/src/UI/view.py | 30 ++++---- smart_bridge/src/components/impl/LCD.cpp | 3 +- smart_bridge/src/kernel/DependantTask.h | 2 +- smart_bridge/src/kernel/Scheduler.cpp | 8 +-- smart_bridge/src/kernel/Scheduler.h | 2 +- smart_bridge/src/kernel/SerialReceiver.cpp | 10 +-- smart_bridge/src/main.cpp | 76 ++++++++++----------- smart_bridge/src/tasks/BlinkTask.h | 4 +- smart_bridge/src/tasks/CheckInTask.cpp | 6 +- smart_bridge/src/tasks/CheckInTask.h | 2 +- smart_bridge/src/tasks/CheckOutTask.cpp | 6 +- smart_bridge/src/tasks/CountDown.cpp | 6 +- smart_bridge/src/tasks/ExitTransitTask.cpp | 6 +- smart_bridge/src/tasks/ServoTestTask.cpp | 6 +- smart_bridge/src/tasks/ServoTestTask.h | 2 +- smart_bridge/src/tasks/SleepingTask.cpp | 2 +- smart_bridge/src/tasks/SleepingTask.h | 2 +- smart_bridge/src/tasks/TemperatureTask.cpp | 6 +- smart_bridge/src/tasks/TransitTask.cpp | 22 +++--- smart_bridge/src/tasks/TransitTask.h | 2 +- smart_bridge/src/tasks/WaitForClickTask.cpp | 4 +- smart_bridge/src/tasks/WaitForClickTask.h | 2 +- smart_bridge/src/tasks/WaitingTask.cpp | 3 +- smart_bridge/src/tasks/WaitingTask.h | 2 +- smart_bridge/src/tasks/WashingTask.cpp | 4 +- 26 files changed, 110 insertions(+), 110 deletions(-) diff --git a/smart_bridge/lib/README b/smart_bridge/lib/README index 6debab1..f909a21 100644 --- a/smart_bridge/lib/README +++ b/smart_bridge/lib/README @@ -3,7 +3,7 @@ This directory is intended for project specific (private) libraries. PlatformIO will compile them to static libraries and link into executable file. The source code of each library should be placed in a an own separate directory -("lib/your_library_name/[here are source files]"). +("lib/your_library_name/[here are source files]")). For example, see a structure of the following two libraries `Foo` and `Bar`: diff --git a/smart_bridge/src/UI/view.py b/smart_bridge/src/UI/view.py index c75c87a..4f71fa2 100644 --- a/smart_bridge/src/UI/view.py +++ b/smart_bridge/src/UI/view.py @@ -17,8 +17,8 @@ def create_main_window(): root = tk.Tk() - root.title("Car Washing Dashboard") - root.geometry("600x600") + root.title("Car Washing Dashboard")) + root.geometry("600x600")) root.configure(bg='lightblue') root.resizable(True, True) return root @@ -26,7 +26,7 @@ def create_main_window(): #these elements are not modified by serialLine def configure_static_elements(root): - title = tk.Label(root, text="Car Washing Dashboard", font=('Arial', 20), bg='lightblue', fg="green") + title = tk.Label(root, text="Car Washing Dashboard", font=('Arial', 20), bg='lightblue', fg="green")) title.grid(row=0, column=0) static_elements = [ ("Current Washes Number: ", 1), @@ -37,7 +37,7 @@ def configure_static_elements(root): ] for text, row in static_elements: label = tk.Label(root, text=text, font=('Arial', 14), bg='lightblue') - label.grid(row=row, column=0, pady=20,padx=5, sticky="w") + label.grid(row=row, column=0, pady=20,padx=5, sticky="w")) #these elements are modified by serialLine def configure_dynamic_elements(root): @@ -52,10 +52,10 @@ def configure_dynamic_elements(root): ui_message=tk.StringVar() - wash_counter.set("counter") - progress_status.set("washing state") - current_temperature.set("20") - ui_message.set("message") + wash_counter.set("counter")) + progress_status.set("washing state")) + current_temperature.set("20")) + ui_message.set("message")) dynamic_elements = [ (tk.Label, wash_counter, 1), @@ -66,7 +66,7 @@ def configure_dynamic_elements(root): for element_type, text_var, row in dynamic_elements: element = element_type(root, textvariable=text_var, font=('Arial', 14), bg='lightblue') - element.grid(row=row, column=1, sticky="w") + element.grid(row=row, column=1, sticky="w")) def configure_button(root): @@ -79,7 +79,7 @@ def hide_button(): button.grid_remove() def show_button(): #show button when an error occured - button.grid(row=7, column=1, pady=10, columnspan=2, sticky="n") + button.grid(row=7, column=1, pady=10, columnspan=2, sticky="n")) def maintenance_done_click(): hide_button() @@ -105,13 +105,13 @@ def check_packet(decoded_packet): print(decoded_packet) if ":" in decoded_packet: - splitted_message=decoded_packet.split(":") + splitted_message=decoded_packet.split(":")) message_type=splitted_message[0] message=splitted_message[1] if message_type=="err": show_button() - ui_message.set("Errore nella macchina") + ui_message.set("Errore nella macchina")) elif message_type=="sts": #washing state progress_status.set(message) elif message_type=="cnt": #wash_counter @@ -129,9 +129,9 @@ def check_packet(decoded_packet): def send_packet(packet): try: serialInst.write(packet.encode('utf-8')) - print(f"GUI: Pacchetto inviato con successo: {packet}") + print(f"GUI: Pacchetto inviato con successo: {packet}")) except Exception as e: - print(f"Errore durante l'invio del pacchetto: {e}") + print(f"Errore durante l'invio del pacchetto: {e}")) def update_serial(): @@ -143,7 +143,7 @@ def update_serial(): def start_serial(): global serialInst - serialInst = serial.Serial() + serialInst = // SerialSerial() serialInst.baudrate = 9600 serialInst.port = 'COM3' #COM3 depends on the port where Arduino is connected serialInst.open() diff --git a/smart_bridge/src/components/impl/LCD.cpp b/smart_bridge/src/components/impl/LCD.cpp index 5817db9..e9d342d 100644 --- a/smart_bridge/src/components/impl/LCD.cpp +++ b/smart_bridge/src/components/impl/LCD.cpp @@ -15,7 +15,8 @@ void LCD::clear() void LCD::write(const char *string, int start_col, int start_rows) { - Serial.println("LCD::Sto scrivendo sul display" + String(string)); + Serial.print(F("LCD::Sto scrivendo sul display ")); + Serial.println(String(string)); lcd.setCursor(start_col, start_rows); lcd.print(string); } \ No newline at end of file diff --git a/smart_bridge/src/kernel/DependantTask.h b/smart_bridge/src/kernel/DependantTask.h index da07b89..c889d3b 100644 --- a/smart_bridge/src/kernel/DependantTask.h +++ b/smart_bridge/src/kernel/DependantTask.h @@ -30,7 +30,7 @@ class DependantTask : virtual public Task { if (nDependencies <= MAX_DEPENDENCIES) { - Serial.println("DependantTask::addDependency()"); + Serial.println(F("DependantTask::addDependency()")); this->dependencies[nDependencies++] = dependency; } } diff --git a/smart_bridge/src/kernel/Scheduler.cpp b/smart_bridge/src/kernel/Scheduler.cpp index 87237d3..157a2fd 100644 --- a/smart_bridge/src/kernel/Scheduler.cpp +++ b/smart_bridge/src/kernel/Scheduler.cpp @@ -15,7 +15,7 @@ void Scheduler::addTask(Task *task) { tasks[numTasks++] = task; #ifdef __DEBUG - Serial.println("tasks[" + String(numTasks - 1) + "]: [" + String(reinterpret_cast(tasks[numTasks - 1])) + "]"); + Serial.println(F("tasks[" + String(numTasks - 1) + "]: [" + String(reinterpret_cast(tasks[numTasks - 1])) + "]")); #endif } } @@ -35,16 +35,16 @@ void Scheduler::schedule() if (tasks[i]->updateAndCheckTime(schedulerPeriod)) // Check if it's time to execute { #ifdef __DEBUG - Serial.println("Scheduler::tasks[" + String(i) + "]: " + String(reinterpret_cast(tasks[i])) + " tick"); + Serial.println(F("Scheduler::tasks[" + String(i) + "]: " + String(reinterpret_cast(tasks[i])) + " tick")); #endif tasks[i]->tick(); // Execute task - // Serial.println("Scheduler::numTasks: " + numTasks); + // Serial.println(F("Scheduler::numTasks: " + numTasks); } } else // Task is aperiodic { #ifdef __DEBUG - Serial.println("Scheduler::tasks[" + String(i) + "]: " + String(reinterpret_cast(tasks[i])) + " tick"); + Serial.println(F("Scheduler::tasks[" + String(i) + "]: " + String(reinterpret_cast(tasks[i])) + " tick")); #endif tasks[i]->tick(); // Execute task without checking time } diff --git a/smart_bridge/src/kernel/Scheduler.h b/smart_bridge/src/kernel/Scheduler.h index 574ea73..9d64081 100644 --- a/smart_bridge/src/kernel/Scheduler.h +++ b/smart_bridge/src/kernel/Scheduler.h @@ -3,7 +3,7 @@ #include "Task.h" -#define MAX_TASKS 50 +#define MAX_TASKS 15 /** * @class Scheduler diff --git a/smart_bridge/src/kernel/SerialReceiver.cpp b/smart_bridge/src/kernel/SerialReceiver.cpp index 4ebaea7..323c42c 100644 --- a/smart_bridge/src/kernel/SerialReceiver.cpp +++ b/smart_bridge/src/kernel/SerialReceiver.cpp @@ -7,11 +7,11 @@ bool SerialReceiver::readData() { return true; } - // if (Serial.available() > 0) { //if some data has been received - // String data = Serial.readString(); + // if (// Serialavailable() > 0) { //if some data has been received + // String data = // SerialreadString(); // data.trim(); - // if (data=="mnt:done") { - // Serial.println("Arduino received message: " + data); + // if (data=="mnt:done")) { + // Serial.println(F("Arduino received message: " + data); // return true; // } // } @@ -20,5 +20,5 @@ bool SerialReceiver::readData() { void SerialReceiver::simulateReadData() { this->simulateDataReceived = true; - Serial.println("Arduino received message: simulates mnt:done"); + Serial.println(F("Arduino received message: simulates mnt:done")); } \ No newline at end of file diff --git a/smart_bridge/src/main.cpp b/smart_bridge/src/main.cpp index a3b86ee..84e5997 100644 --- a/smart_bridge/src/main.cpp +++ b/smart_bridge/src/main.cpp @@ -1,71 +1,65 @@ #include "Arduino.h" + #include "config/config.h" + #include "kernel/Scheduler.h" #include "kernel/SerialReceiver.h" + #include "tasks/BlinkTask.h" +#include "tasks/CountDown.h" +#include "tasks/TemperatureTask.h" +#include "tasks/SleepingTask.h" #include "tasks/CheckInTask.h" #include "tasks/TransitTask.h" -#include "tasks/WaitingTask.h" -#include "tasks/WashingTask.h" -#include "tasks/SleepingTask.h" -#include "tasks/CheckOutTask.h" -#include "tasks/CountDown.h" #include "tasks/WaitForClickTask.h" #include "tasks/WashingTask.h" #include "tasks/CheckOutTask.h" #include "tasks/ExitTransitTask.h" -#include "tasks/TemperatureTask.h" - -// #include "tasks/ServoTestTask.h" Scheduler scheduler; SerialReceiver *serialReceiver; -LCD *lcd; void setup() { + Serial.begin(9600); scheduler.init(50); // NOTE: Might be set higher to use less power, needs testing. /**CREATE TASKS**/ - BlinkTask *blinkTaskTransit = new BlinkTask(L2_PIN); - BlinkTask *blinkTaskWashing = new BlinkTask(L2_PIN); - // CountDown *countDownTask = new CountDown(N3); - TemperatureTask *temperatureTask = new TemperatureTask(); - // SleepingTask *sleepingTask = new SleepingTask(); - CheckInTask *checkInTask = new CheckInTask(); - TransitTask *transitTask = new TransitTask(blinkTaskTransit); - WaitForClickTask *waitForClickTask = new WaitForClickTask(); - // WashingTask *washingTask = new WashingTask(blinkTaskTransit, nullptr, temperatureTask); - // CheckOutTask *checkOutTask = new CheckOutTask(); - // ExitTransitTask *exitTransitTask = new ExitTransitTask(); + BlinkTask blinkTask = BlinkTask(L2_PIN); + CountDown countDownTask = CountDown(N3); + TemperatureTask temperatureTask = TemperatureTask(); + SleepingTask sleepingTask = SleepingTask(); + CheckInTask checkInTask = CheckInTask(); + TransitTask transitTask = TransitTask(&blinkTask); + WaitForClickTask waitForClickTask = WaitForClickTask(); + WashingTask washingTask = WashingTask(&blinkTask, &countDownTask, &temperatureTask); + CheckOutTask checkOutTask = CheckOutTask(); + ExitTransitTask exitTransitTask = ExitTransitTask(); - /**DEPENDENCIES**/ - // checkInTask->addDependency(sleepingTask); - transitTask->addDependency(checkInTask); - waitForClickTask->addDependency(transitTask); - //washingTask->addDependency(waitForClickTask); - // checkOutTask->addDependency(washingTask); - // exitTransitTask->addDependency(checkOutTask); + // /**DEPENDENCIES**/ + checkInTask.addDependency(&sleepingTask); + transitTask.addDependency(&checkInTask); + waitForClickTask.addDependency(&transitTask); + washingTask.addDependency(&waitForClickTask); + checkOutTask.addDependency(&washingTask); + exitTransitTask.addDependency(&checkOutTask); - /**ADD TASKS TO THE SCHEDULER**/ - // scheduler.addTask(sleepingTask); - scheduler.addTask(checkInTask); - scheduler.addTask(transitTask); - scheduler.addTask(blinkTaskTransit); - scheduler.addTask(blinkTaskWashing); - // scheduler.addTask(countDownTask); - scheduler.addTask(temperatureTask); - scheduler.addTask(waitForClickTask); - // scheduler.addTask(washingTask); - // scheduler.addTask(checkOutTask); - // scheduler.addTask(exitTransitTask); + // /**ADD TASKS TO THE SCHEDULER**/ + scheduler.addTask(&sleepingTask); + scheduler.addTask(&checkInTask); + scheduler.addTask(&transitTask); + scheduler.addTask(&blinkTask); + scheduler.addTask(&countDownTask); + scheduler.addTask(&temperatureTask); + scheduler.addTask(&waitForClickTask); + scheduler.addTask(&washingTask); + scheduler.addTask(&checkOutTask); + scheduler.addTask(&exitTransitTask); } void loop() { - // serialReceiver->readData(); //@EMANUELE this is a test to try the serialReceiver, it must go instantiate when the arduino is in error state - // read the class briefs scheduler.schedule(); } \ No newline at end of file diff --git a/smart_bridge/src/tasks/BlinkTask.h b/smart_bridge/src/tasks/BlinkTask.h index b6dc58b..9c2f825 100644 --- a/smart_bridge/src/tasks/BlinkTask.h +++ b/smart_bridge/src/tasks/BlinkTask.h @@ -20,7 +20,7 @@ class BlinkTask : public TaskWithState */ BlinkTask(int pin, int period) : TaskWithState() { - Serial.println("BlinkTask created"); + Serial.println(F("BlinkTask created")); this->pin = pin; this->init(period); } @@ -31,7 +31,7 @@ class BlinkTask : public TaskWithState */ BlinkTask(int pin) : TaskWithState() { - Serial.println("BlinkTask created"); + Serial.println(F("BlinkTask created")); this->pin = pin; if (this->isActive()) { diff --git a/smart_bridge/src/tasks/CheckInTask.cpp b/smart_bridge/src/tasks/CheckInTask.cpp index a4612a3..d7d8c17 100644 --- a/smart_bridge/src/tasks/CheckInTask.cpp +++ b/smart_bridge/src/tasks/CheckInTask.cpp @@ -11,7 +11,7 @@ void CheckInTask::tick() lcd->write("SMART WASHING", 0, 1); L1->switchOn(); // Turn on L1 #ifdef __LOG - Serial.println("CheckInTask::Turned on L1"); + Serial.println(F("CheckInTask::Turned on L1")); #endif this->resetTime(); // Reset the elapsed time this->setState(WAITING); // Set the state to WAITING @@ -21,11 +21,11 @@ void CheckInTask::tick() { L1->switchOff(); // Turn off L1 #ifdef __LOG - Serial.println("CheckInTask::Turned off L1"); + Serial.println(F("CheckInTask::Turned off L1")); #endif gate->write(90); // Open the gate #ifdef __LOG - Serial.println("CheckInTask::Opened the gate"); + Serial.println(F("CheckInTask::Opened the gate")); #endif this->setCompleted(); // Mark the task as completed } diff --git a/smart_bridge/src/tasks/CheckInTask.h b/smart_bridge/src/tasks/CheckInTask.h index 51db934..25f1551 100644 --- a/smart_bridge/src/tasks/CheckInTask.h +++ b/smart_bridge/src/tasks/CheckInTask.h @@ -25,7 +25,7 @@ class CheckInTask : public DependantTaskWithState this->gate = new ServoImpl(SERVO_PIN); this->init(); this->setState(STARTED); - Serial.println("CheckInTask created"); + Serial.println(F("CheckInTask created")); }; void tick() override; diff --git a/smart_bridge/src/tasks/CheckOutTask.cpp b/smart_bridge/src/tasks/CheckOutTask.cpp index af7074f..28138e0 100644 --- a/smart_bridge/src/tasks/CheckOutTask.cpp +++ b/smart_bridge/src/tasks/CheckOutTask.cpp @@ -2,7 +2,7 @@ CheckOutTask::CheckOutTask() : DependantTaskWithState() { - Serial.println("CheckOutTask created"); + Serial.println(F("CheckOutTask created")); this->sonar = new Sonar(SONAR_TRIG_PIN, SONAR_ECHO_PIN, SONAR_MAX_TIME); this->L3 = new Led(L3_PIN); this->gate = new ServoImpl(SERVO_PIN); @@ -34,13 +34,13 @@ void CheckOutTask::tick() void CheckOutTask::handleTurnOnL3() { this->L3->switchOn(); - Serial.println("CheckOutTask::L3 turned on"); + Serial.println(F("CheckOutTask::L3 turned on")); this->setState(OPENS_GATE); } void CheckOutTask::handleOpensGate() { this->gate->write(GATE_OPEN_POSITION); - Serial.println("CheckOutTask::Gate opened"); + Serial.println(F("CheckOutTask::Gate opened")); this->setCompleted(); } \ No newline at end of file diff --git a/smart_bridge/src/tasks/CountDown.cpp b/smart_bridge/src/tasks/CountDown.cpp index 1ffafef..528ac67 100644 --- a/smart_bridge/src/tasks/CountDown.cpp +++ b/smart_bridge/src/tasks/CountDown.cpp @@ -2,7 +2,7 @@ CountDown::CountDown(int countDown) : Task() { - Serial.println("CountDownTask created"); + Serial.println(F("CountDownTask created")); this->setStatus(false); this->lcd = new LCD(0x27, 16, 2); this->resetCountDown(N3); @@ -61,14 +61,14 @@ void CountDown::endsCountDown() this->isCompleted(); this->printsEndsCountdown(); this->resetCountDown(N3); - Serial.println("CountDown::Countdown resetted"); + Serial.println(F("CountDown::Countdown resetted")); this->setCompleted(); } } void CountDown::printsEndsCountdown() { - Serial.println("CountDown::Countdown ended!"); + Serial.println(F("CountDown::Countdown ended!")); } bool CountDown::isCountDownActive() diff --git a/smart_bridge/src/tasks/ExitTransitTask.cpp b/smart_bridge/src/tasks/ExitTransitTask.cpp index d068a46..6f38d0f 100644 --- a/smart_bridge/src/tasks/ExitTransitTask.cpp +++ b/smart_bridge/src/tasks/ExitTransitTask.cpp @@ -5,7 +5,7 @@ ExitTransitTask::ExitTransitTask() GATE_OPEN_POSITION(90), GATE_CLOSE_POSITION(0) { - Serial.println("ExitTransitTask created"); + Serial.println(F("ExitTransitTask created")); this->sonar = new Sonar(SONAR_TRIG_PIN, SONAR_ECHO_PIN, SONAR_MAX_TIME); this->L3 = new Led(L3_PIN); this->gate = new ServoImpl(SERVO_PIN); @@ -66,13 +66,13 @@ void ExitTransitTask::handleCheckingDistance() void ExitTransitTask::handleClosesGate() { this->gate->write(GATE_CLOSE_POSITION); - Serial.println("ExitTransitTask::Gate closed"); + Serial.println(F("ExitTransitTask::Gate closed")); this->setState(SWITCH_OFF_L3); } void ExitTransitTask::handleSwitchOffL3() { this->L3->switchOff(); - Serial.println("ExitTransitTask::L3 switched off"); + Serial.println(F("ExitTransitTask::L3 switched off")); this->setCompleted(); } \ No newline at end of file diff --git a/smart_bridge/src/tasks/ServoTestTask.cpp b/smart_bridge/src/tasks/ServoTestTask.cpp index bd90e26..0e31053 100644 --- a/smart_bridge/src/tasks/ServoTestTask.cpp +++ b/smart_bridge/src/tasks/ServoTestTask.cpp @@ -2,18 +2,18 @@ // void ServoTestTask::tick() // { -// Serial.println("ServoTestTask::tick()"); +// Serial.println(F("ServoTestTask::tick()")); // switch (this->getState()) // { // case OPEN: -// Serial.println("ServoTestTask::OPEN"); +// Serial.println(F("ServoTestTask::OPEN")); // this->servo.writeMicroseconds(1500); // this->setState(CLOSE); // break; // case CLOSE: // // if (this->elapsedTime() >= 1000) // { -// Serial.println("ServoTestTask::CLOSE"); +// Serial.println(F("ServoTestTask::CLOSE")); // this->servo.writeMicroseconds(0); // this->setState(OPEN); // } diff --git a/smart_bridge/src/tasks/ServoTestTask.h b/smart_bridge/src/tasks/ServoTestTask.h index ff5be23..06f7f4d 100644 --- a/smart_bridge/src/tasks/ServoTestTask.h +++ b/smart_bridge/src/tasks/ServoTestTask.h @@ -12,7 +12,7 @@ // { // // this->servo = new Servo(); // this->servo.detach(); -// Serial.println("Servo::attach" + String(this->servo.attach(SERVO_PIN))); +// Serial.println(F("Servo::attach" + String(this->servo.attach(SERVO_PIN))); // this->init(1000); // Periodic task, executed every 1000ms // this->setActive(true); // this->setState(OPEN); diff --git a/smart_bridge/src/tasks/SleepingTask.cpp b/smart_bridge/src/tasks/SleepingTask.cpp index d8e58c9..280a6c9 100644 --- a/smart_bridge/src/tasks/SleepingTask.cpp +++ b/smart_bridge/src/tasks/SleepingTask.cpp @@ -18,7 +18,7 @@ void SleepingTask::tick() case ALIVE: if (pir->checkDetectedStatus()) { - Serial.println("OBJECT revealed"); + Serial.println(F("OBJECT revealed")); this->setState(OBJECT_DETECTED); } break; diff --git a/smart_bridge/src/tasks/SleepingTask.h b/smart_bridge/src/tasks/SleepingTask.h index ab954ab..d7ac810 100644 --- a/smart_bridge/src/tasks/SleepingTask.h +++ b/smart_bridge/src/tasks/SleepingTask.h @@ -22,7 +22,7 @@ class SleepingTask : public TaskWithState public: SleepingTask() : TaskWithState() { - Serial.println("SleepingTask created"); + Serial.println(F("SleepingTask created")); this->pir = new Pir(PIR_PIN); this->lcd=new LCD(0x27, 16,2); this->init(); diff --git a/smart_bridge/src/tasks/TemperatureTask.cpp b/smart_bridge/src/tasks/TemperatureTask.cpp index 5b60edd..4dea837 100644 --- a/smart_bridge/src/tasks/TemperatureTask.cpp +++ b/smart_bridge/src/tasks/TemperatureTask.cpp @@ -5,7 +5,7 @@ TemperatureTask::TemperatureTask() voltageConversionFactor(30), voltageOffset(0.5) { - Serial.println("TemperatureTask created"); + Serial.println(F("TemperatureTask created")); this->lcd = new LCD(0x27, 16, 2); this->setTemperature(this->getTemperature()); this->init(1000); @@ -60,12 +60,12 @@ bool TemperatureTask::checkForCriticalTemperature() void TemperatureTask::criticalTemperatureReachedMessage() { - Serial.println("Critical temperature reached!"); + Serial.println(F("Critical temperature reached!")); } void TemperatureTask::temperatureMaintenanceMessage() { - // Serial.println("Detected a Problem - Please Wait"); + // Serial.println(F("Detected a Problem - Please Wait")); lcd->write("Detected a Problem - Please Wait: ", 0, 0); } diff --git a/smart_bridge/src/tasks/TransitTask.cpp b/smart_bridge/src/tasks/TransitTask.cpp index 104842b..49d92d8 100644 --- a/smart_bridge/src/tasks/TransitTask.cpp +++ b/smart_bridge/src/tasks/TransitTask.cpp @@ -14,14 +14,15 @@ void TransitTask::tick() this->L2->switchOn(); this->distance = sonar->detectDistance(); #ifdef __LOG - Serial.println("TransitTask::Distance: " + String(this->distance)); + Serial.println(F("TransitTask::Distance: ")); + Serial.print(String(this->distance)); #endif if (this->distance < MINDIST) { this->resetTime(); this->setState(CHECKING_DISTANCE); #ifdef __LOG - Serial.println("TransitTask::Checking distance"); + Serial.println(F("TransitTask::Checking distance")); #endif } break; @@ -33,19 +34,22 @@ void TransitTask::tick() } this->distance = sonar->detectDistance(); #ifdef __LOG - Serial.println("TransitTask::Distance: " + String(this->distance)); + Serial.print(F("TransitTask::Distance: ")); + Serial.println(String(this->distance)); #endif if (this->distance < MINDIST) { #ifdef __DEBUG - Serial.println("TransitTask::Elapsed: " + String(this->elapsedTime())); + Serial.print(F("TransitTask::Elapsed: ")); + Serial.println(String(this->elapsedTime())); #endif if (this->elapsedTime() >= (N2 * 1000)) { #ifdef __LOG - Serial.println("TransitTask::Distance: " + String(this->distance)); - Serial.println("TransitTask::Car entered"); - Serial.println("TransitTask::Closing gate"); + Serial.println(F("TransitTask::Distance: ")); + Serial.println(String(this->distance)); + Serial.println(F("TransitTask::Car entered")); + Serial.println(F("TransitTask::Closing gate")); #endif this->gate->write(0); if (this->blinkTask->isActive()) @@ -59,7 +63,7 @@ void TransitTask::tick() else { #ifdef __LOG - Serial.println("TransitTask::Reading distance"); + Serial.println(F("TransitTask::Reading distance")); #endif if (this->blinkTask->isActive()) { @@ -70,7 +74,7 @@ void TransitTask::tick() } break; default: - Serial.println("TransitTask::Invalid state"); + Serial.println(F("TransitTask::Invalid state")); break; } } diff --git a/smart_bridge/src/tasks/TransitTask.h b/smart_bridge/src/tasks/TransitTask.h index 3d1f111..cf210e0 100644 --- a/smart_bridge/src/tasks/TransitTask.h +++ b/smart_bridge/src/tasks/TransitTask.h @@ -24,7 +24,7 @@ class TransitTask : public DependantTaskWithState */ TransitTask(BlinkTask *blinkTask) : DependantTaskWithState() { - Serial.println("TransitTask created"); + Serial.println(F("TransitTask created")); this->sonar = new Sonar(SONAR_TRIG_PIN, SONAR_ECHO_PIN, SONAR_MAX_TIME); this->L2 = new Led(L2_PIN); this->lcd = new LCD(0x27, 16, 2); diff --git a/smart_bridge/src/tasks/WaitForClickTask.cpp b/smart_bridge/src/tasks/WaitForClickTask.cpp index b32c955..b0c0367 100644 --- a/smart_bridge/src/tasks/WaitForClickTask.cpp +++ b/smart_bridge/src/tasks/WaitForClickTask.cpp @@ -9,13 +9,13 @@ void WaitForClickTask::tick() this->lcd->write("Press START to", 0, 0); this->lcd->write("begin washing", 0, 1); #ifdef __LOG - Serial.println("WaitForClickTask::Waiting for START click"); + Serial.println(F("WaitForClickTask::Waiting for START click")); #endif this->start->sync(); if (this->start->isPressed()) { #ifdef __LOG - Serial.println("WaitForClickTask::START pressed"); + Serial.println(F("WaitForClickTask::START pressed")); #endif this->lcd->clear(); this->lcd->write("Starting to wash", 0, 0); diff --git a/smart_bridge/src/tasks/WaitForClickTask.h b/smart_bridge/src/tasks/WaitForClickTask.h index bbae0c9..8c472e9 100644 --- a/smart_bridge/src/tasks/WaitForClickTask.h +++ b/smart_bridge/src/tasks/WaitForClickTask.h @@ -22,7 +22,7 @@ class WaitForClickTask : public DependantTask this->start = new Button(BUTTON_PIN); this->lcd = new LCD(0x27, 16, 2); this->init(); - Serial.println("WaitForClickTask created"); + Serial.println(F("WaitForClickTask created")); }; void tick() override; diff --git a/smart_bridge/src/tasks/WaitingTask.cpp b/smart_bridge/src/tasks/WaitingTask.cpp index 757cc09..213d287 100644 --- a/smart_bridge/src/tasks/WaitingTask.cpp +++ b/smart_bridge/src/tasks/WaitingTask.cpp @@ -10,7 +10,8 @@ void WaitingTask::tick() switch (this->getState()) { case STARTED: - Serial.println("sono qui in waiting"); + break; + Serial.println(F("sono qui in waiting")); } } diff --git a/smart_bridge/src/tasks/WaitingTask.h b/smart_bridge/src/tasks/WaitingTask.h index a9ab900..1aa0cc6 100644 --- a/smart_bridge/src/tasks/WaitingTask.h +++ b/smart_bridge/src/tasks/WaitingTask.h @@ -18,7 +18,7 @@ class WaitingTask : public DependantTaskWithState this->pir=new Pir(PIR_PIN); //attached to the INTERRUPT_PIN 2 this->init(); this->setState(STARTED); - Serial.println("WaitingTask created"); + Serial.println(F("WaitingTask created")); }; void tick() override; diff --git a/smart_bridge/src/tasks/WashingTask.cpp b/smart_bridge/src/tasks/WashingTask.cpp index 6164790..f4f5fd0 100644 --- a/smart_bridge/src/tasks/WashingTask.cpp +++ b/smart_bridge/src/tasks/WashingTask.cpp @@ -5,7 +5,7 @@ WashingTask::WashingTask(BlinkTask *blinkTask, TemperatureTask *temperatureTask) : DependantTaskWithState() { - Serial.println("WashingTask created"); + Serial.println(F("WashingTask created")); this->L2 = new Led(L2_PIN); this->L3 = new Led(L3_PIN); this->tempSensor = new Temp(TMP_PIN); @@ -13,7 +13,7 @@ WashingTask::WashingTask(BlinkTask *blinkTask, this->gate = new ServoImpl(SERVO_PIN); this->blinkTask = blinkTask; this->blinkTask->init(500); // Blink every 500 ms the red led - this->blinkTask->setActive(false); // TODO: Check if this is necessary + this->blinkTask->setActive(false); this->countDownTask = countDownTask; this->temperatureTask = temperatureTask; this->init(1000); From 9c090c9a1ec1d4568a5ac1133f0b7e553aa1267d Mon Sep 17 00:00:00 2001 From: Alessandro Monticelli Date: Tue, 5 Dec 2023 16:41:24 +0100 Subject: [PATCH 3/7] Fix UI parenthesis error --- smart_bridge/src/UI/view.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/smart_bridge/src/UI/view.py b/smart_bridge/src/UI/view.py index 4f71fa2..a1cc707 100644 --- a/smart_bridge/src/UI/view.py +++ b/smart_bridge/src/UI/view.py @@ -17,8 +17,8 @@ def create_main_window(): root = tk.Tk() - root.title("Car Washing Dashboard")) - root.geometry("600x600")) + root.title("Car Washing Dashboard") + root.geometry("600x600") root.configure(bg='lightblue') root.resizable(True, True) return root @@ -26,7 +26,7 @@ def create_main_window(): #these elements are not modified by serialLine def configure_static_elements(root): - title = tk.Label(root, text="Car Washing Dashboard", font=('Arial', 20), bg='lightblue', fg="green")) + title = tk.Label(root, text="Car Washing Dashboard", font=('Arial', 20), bg='lightblue', fg="green") title.grid(row=0, column=0) static_elements = [ ("Current Washes Number: ", 1), @@ -37,7 +37,7 @@ def configure_static_elements(root): ] for text, row in static_elements: label = tk.Label(root, text=text, font=('Arial', 14), bg='lightblue') - label.grid(row=row, column=0, pady=20,padx=5, sticky="w")) + label.grid(row=row, column=0, pady=20,padx=5, sticky="w") #these elements are modified by serialLine def configure_dynamic_elements(root): @@ -52,10 +52,10 @@ def configure_dynamic_elements(root): ui_message=tk.StringVar() - wash_counter.set("counter")) - progress_status.set("washing state")) - current_temperature.set("20")) - ui_message.set("message")) + wash_counter.set("counter") + progress_status.set("washing state") + current_temperature.set("20") + ui_message.set("message") dynamic_elements = [ (tk.Label, wash_counter, 1), @@ -66,7 +66,7 @@ def configure_dynamic_elements(root): for element_type, text_var, row in dynamic_elements: element = element_type(root, textvariable=text_var, font=('Arial', 14), bg='lightblue') - element.grid(row=row, column=1, sticky="w")) + element.grid(row=row, column=1, sticky="w") def configure_button(root): @@ -79,7 +79,7 @@ def hide_button(): button.grid_remove() def show_button(): #show button when an error occured - button.grid(row=7, column=1, pady=10, columnspan=2, sticky="n")) + button.grid(row=7, column=1, pady=10, columnspan=2, sticky="n") def maintenance_done_click(): hide_button() @@ -105,13 +105,13 @@ def check_packet(decoded_packet): print(decoded_packet) if ":" in decoded_packet: - splitted_message=decoded_packet.split(":")) + splitted_message=decoded_packet.split(":") message_type=splitted_message[0] message=splitted_message[1] if message_type=="err": show_button() - ui_message.set("Errore nella macchina")) + ui_message.set("Errore nella macchina") elif message_type=="sts": #washing state progress_status.set(message) elif message_type=="cnt": #wash_counter @@ -129,9 +129,9 @@ def check_packet(decoded_packet): def send_packet(packet): try: serialInst.write(packet.encode('utf-8')) - print(f"GUI: Pacchetto inviato con successo: {packet}")) + print(f"GUI: Pacchetto inviato con successo: {packet}") except Exception as e: - print(f"Errore durante l'invio del pacchetto: {e}")) + print(f"Errore durante l'invio del pacchetto: {e}") def update_serial(): From 44860fbc9fad8477549ed648b6bd8542e2fd9b41 Mon Sep 17 00:00:00 2001 From: Alessandro Monticelli Date: Tue, 5 Dec 2023 16:42:29 +0100 Subject: [PATCH 4/7] Remove Serial prints --- smart_bridge/src/components/impl/LCD.cpp | 4 ++-- smart_bridge/src/kernel/DependantTask.h | 2 +- smart_bridge/src/kernel/Scheduler.cpp | 8 +++---- smart_bridge/src/kernel/SerialReceiver.cpp | 4 ++-- smart_bridge/src/main.cpp | 10 ++++---- smart_bridge/src/tasks/BlinkTask.h | 4 ++-- smart_bridge/src/tasks/CheckInTask.cpp | 6 ++--- smart_bridge/src/tasks/CheckInTask.h | 2 +- smart_bridge/src/tasks/CheckOutTask.cpp | 6 ++--- smart_bridge/src/tasks/CountDown.cpp | 6 ++--- smart_bridge/src/tasks/ExitTransitTask.cpp | 8 +++---- smart_bridge/src/tasks/ServoTestTask.cpp | 6 ++--- smart_bridge/src/tasks/ServoTestTask.h | 2 +- smart_bridge/src/tasks/SleepingTask.cpp | 2 +- smart_bridge/src/tasks/SleepingTask.h | 2 +- smart_bridge/src/tasks/TemperatureTask.cpp | 6 ++--- smart_bridge/src/tasks/TransitTask.cpp | 26 ++++++++++----------- smart_bridge/src/tasks/TransitTask.h | 2 +- smart_bridge/src/tasks/WaitForClickTask.cpp | 4 ++-- smart_bridge/src/tasks/WaitForClickTask.h | 2 +- smart_bridge/src/tasks/WaitingTask.cpp | 2 +- smart_bridge/src/tasks/WaitingTask.h | 2 +- smart_bridge/src/tasks/WashingTask.cpp | 2 +- 23 files changed, 59 insertions(+), 59 deletions(-) diff --git a/smart_bridge/src/components/impl/LCD.cpp b/smart_bridge/src/components/impl/LCD.cpp index e9d342d..c067b96 100644 --- a/smart_bridge/src/components/impl/LCD.cpp +++ b/smart_bridge/src/components/impl/LCD.cpp @@ -15,8 +15,8 @@ void LCD::clear() void LCD::write(const char *string, int start_col, int start_rows) { - Serial.print(F("LCD::Sto scrivendo sul display ")); - Serial.println(String(string)); + // Serial.print(F("LCD::Sto scrivendo sul display ")); + // Serial.println(String(string)); lcd.setCursor(start_col, start_rows); lcd.print(string); } \ No newline at end of file diff --git a/smart_bridge/src/kernel/DependantTask.h b/smart_bridge/src/kernel/DependantTask.h index c889d3b..15c3239 100644 --- a/smart_bridge/src/kernel/DependantTask.h +++ b/smart_bridge/src/kernel/DependantTask.h @@ -30,7 +30,7 @@ class DependantTask : virtual public Task { if (nDependencies <= MAX_DEPENDENCIES) { - Serial.println(F("DependantTask::addDependency()")); + // Serial.println(F("DependantTask::addDependency()")); this->dependencies[nDependencies++] = dependency; } } diff --git a/smart_bridge/src/kernel/Scheduler.cpp b/smart_bridge/src/kernel/Scheduler.cpp index 157a2fd..633c671 100644 --- a/smart_bridge/src/kernel/Scheduler.cpp +++ b/smart_bridge/src/kernel/Scheduler.cpp @@ -15,7 +15,7 @@ void Scheduler::addTask(Task *task) { tasks[numTasks++] = task; #ifdef __DEBUG - Serial.println(F("tasks[" + String(numTasks - 1) + "]: [" + String(reinterpret_cast(tasks[numTasks - 1])) + "]")); + // Serial.println(F("tasks[" + String(numTasks - 1) + "]: [" + String(reinterpret_cast(tasks[numTasks - 1])) + "]")); #endif } } @@ -35,16 +35,16 @@ void Scheduler::schedule() if (tasks[i]->updateAndCheckTime(schedulerPeriod)) // Check if it's time to execute { #ifdef __DEBUG - Serial.println(F("Scheduler::tasks[" + String(i) + "]: " + String(reinterpret_cast(tasks[i])) + " tick")); + // Serial.println(F("Scheduler::tasks[" + String(i) + "]: " + String(reinterpret_cast(tasks[i])) + " tick")); #endif tasks[i]->tick(); // Execute task - // Serial.println(F("Scheduler::numTasks: " + numTasks); + // // Serial.println(F("Scheduler::numTasks: " + numTasks); } } else // Task is aperiodic { #ifdef __DEBUG - Serial.println(F("Scheduler::tasks[" + String(i) + "]: " + String(reinterpret_cast(tasks[i])) + " tick")); + // Serial.println(F("Scheduler::tasks[" + String(i) + "]: " + String(reinterpret_cast(tasks[i])) + " tick")); #endif tasks[i]->tick(); // Execute task without checking time } diff --git a/smart_bridge/src/kernel/SerialReceiver.cpp b/smart_bridge/src/kernel/SerialReceiver.cpp index 323c42c..be8b3bd 100644 --- a/smart_bridge/src/kernel/SerialReceiver.cpp +++ b/smart_bridge/src/kernel/SerialReceiver.cpp @@ -11,7 +11,7 @@ bool SerialReceiver::readData() { // String data = // SerialreadString(); // data.trim(); // if (data=="mnt:done")) { - // Serial.println(F("Arduino received message: " + data); + // // Serial.println(F("Arduino received message: " + data); // return true; // } // } @@ -20,5 +20,5 @@ bool SerialReceiver::readData() { void SerialReceiver::simulateReadData() { this->simulateDataReceived = true; - Serial.println(F("Arduino received message: simulates mnt:done")); + // Serial.println(F("Arduino received message: simulates mnt:done")); } \ No newline at end of file diff --git a/smart_bridge/src/main.cpp b/smart_bridge/src/main.cpp index 84e5997..69fe58c 100644 --- a/smart_bridge/src/main.cpp +++ b/smart_bridge/src/main.cpp @@ -1,9 +1,10 @@ -#include "Arduino.h" +// #include "Arduino.h" #include "config/config.h" #include "kernel/Scheduler.h" -#include "kernel/SerialReceiver.h" + +#include "components/api/LCD.h" #include "tasks/BlinkTask.h" #include "tasks/CountDown.h" @@ -23,7 +24,7 @@ SerialReceiver *serialReceiver; void setup() { - Serial.begin(9600); + // Serial.begin(9600); scheduler.init(50); // NOTE: Might be set higher to use less power, needs testing. /**CREATE TASKS**/ @@ -34,10 +35,9 @@ void setup() CheckInTask checkInTask = CheckInTask(); TransitTask transitTask = TransitTask(&blinkTask); WaitForClickTask waitForClickTask = WaitForClickTask(); - WashingTask washingTask = WashingTask(&blinkTask, &countDownTask, &temperatureTask); + WashingTask washingTask = WashingTask(&blinkTask, nullptr, &temperatureTask); CheckOutTask checkOutTask = CheckOutTask(); ExitTransitTask exitTransitTask = ExitTransitTask(); - // /**DEPENDENCIES**/ checkInTask.addDependency(&sleepingTask); transitTask.addDependency(&checkInTask); diff --git a/smart_bridge/src/tasks/BlinkTask.h b/smart_bridge/src/tasks/BlinkTask.h index 9c2f825..8796484 100644 --- a/smart_bridge/src/tasks/BlinkTask.h +++ b/smart_bridge/src/tasks/BlinkTask.h @@ -20,7 +20,7 @@ class BlinkTask : public TaskWithState */ BlinkTask(int pin, int period) : TaskWithState() { - Serial.println(F("BlinkTask created")); + // Serial.println(F("BlinkTask created")); this->pin = pin; this->init(period); } @@ -31,7 +31,7 @@ class BlinkTask : public TaskWithState */ BlinkTask(int pin) : TaskWithState() { - Serial.println(F("BlinkTask created")); + // Serial.println(F("BlinkTask created")); this->pin = pin; if (this->isActive()) { diff --git a/smart_bridge/src/tasks/CheckInTask.cpp b/smart_bridge/src/tasks/CheckInTask.cpp index d7d8c17..dd46b7b 100644 --- a/smart_bridge/src/tasks/CheckInTask.cpp +++ b/smart_bridge/src/tasks/CheckInTask.cpp @@ -11,7 +11,7 @@ void CheckInTask::tick() lcd->write("SMART WASHING", 0, 1); L1->switchOn(); // Turn on L1 #ifdef __LOG - Serial.println(F("CheckInTask::Turned on L1")); + // Serial.println(F("CheckInTask::Turned on L1")); #endif this->resetTime(); // Reset the elapsed time this->setState(WAITING); // Set the state to WAITING @@ -21,11 +21,11 @@ void CheckInTask::tick() { L1->switchOff(); // Turn off L1 #ifdef __LOG - Serial.println(F("CheckInTask::Turned off L1")); + // Serial.println(F("CheckInTask::Turned off L1")); #endif gate->write(90); // Open the gate #ifdef __LOG - Serial.println(F("CheckInTask::Opened the gate")); + // Serial.println(F("CheckInTask::Opened the gate")); #endif this->setCompleted(); // Mark the task as completed } diff --git a/smart_bridge/src/tasks/CheckInTask.h b/smart_bridge/src/tasks/CheckInTask.h index 25f1551..44e456f 100644 --- a/smart_bridge/src/tasks/CheckInTask.h +++ b/smart_bridge/src/tasks/CheckInTask.h @@ -25,7 +25,7 @@ class CheckInTask : public DependantTaskWithState this->gate = new ServoImpl(SERVO_PIN); this->init(); this->setState(STARTED); - Serial.println(F("CheckInTask created")); + // Serial.println(F("CheckInTask created")); }; void tick() override; diff --git a/smart_bridge/src/tasks/CheckOutTask.cpp b/smart_bridge/src/tasks/CheckOutTask.cpp index 28138e0..2de38a9 100644 --- a/smart_bridge/src/tasks/CheckOutTask.cpp +++ b/smart_bridge/src/tasks/CheckOutTask.cpp @@ -2,7 +2,7 @@ CheckOutTask::CheckOutTask() : DependantTaskWithState() { - Serial.println(F("CheckOutTask created")); + // Serial.println(F("CheckOutTask created")); this->sonar = new Sonar(SONAR_TRIG_PIN, SONAR_ECHO_PIN, SONAR_MAX_TIME); this->L3 = new Led(L3_PIN); this->gate = new ServoImpl(SERVO_PIN); @@ -34,13 +34,13 @@ void CheckOutTask::tick() void CheckOutTask::handleTurnOnL3() { this->L3->switchOn(); - Serial.println(F("CheckOutTask::L3 turned on")); + // Serial.println(F("CheckOutTask::L3 turned on")); this->setState(OPENS_GATE); } void CheckOutTask::handleOpensGate() { this->gate->write(GATE_OPEN_POSITION); - Serial.println(F("CheckOutTask::Gate opened")); + // Serial.println(F("CheckOutTask::Gate opened")); this->setCompleted(); } \ No newline at end of file diff --git a/smart_bridge/src/tasks/CountDown.cpp b/smart_bridge/src/tasks/CountDown.cpp index 528ac67..d219306 100644 --- a/smart_bridge/src/tasks/CountDown.cpp +++ b/smart_bridge/src/tasks/CountDown.cpp @@ -2,7 +2,7 @@ CountDown::CountDown(int countDown) : Task() { - Serial.println(F("CountDownTask created")); + // Serial.println(F("CountDownTask created")); this->setStatus(false); this->lcd = new LCD(0x27, 16, 2); this->resetCountDown(N3); @@ -61,14 +61,14 @@ void CountDown::endsCountDown() this->isCompleted(); this->printsEndsCountdown(); this->resetCountDown(N3); - Serial.println(F("CountDown::Countdown resetted")); + // Serial.println(F("CountDown::Countdown resetted")); this->setCompleted(); } } void CountDown::printsEndsCountdown() { - Serial.println(F("CountDown::Countdown ended!")); + // Serial.println(F("CountDown::Countdown ended!")); } bool CountDown::isCountDownActive() diff --git a/smart_bridge/src/tasks/ExitTransitTask.cpp b/smart_bridge/src/tasks/ExitTransitTask.cpp index 6f38d0f..4c9eb50 100644 --- a/smart_bridge/src/tasks/ExitTransitTask.cpp +++ b/smart_bridge/src/tasks/ExitTransitTask.cpp @@ -5,7 +5,7 @@ ExitTransitTask::ExitTransitTask() GATE_OPEN_POSITION(90), GATE_CLOSE_POSITION(0) { - Serial.println(F("ExitTransitTask created")); + // Serial.println(F("ExitTransitTask created")); this->sonar = new Sonar(SONAR_TRIG_PIN, SONAR_ECHO_PIN, SONAR_MAX_TIME); this->L3 = new Led(L3_PIN); this->gate = new ServoImpl(SERVO_PIN); @@ -44,7 +44,7 @@ void ExitTransitTask::tick() void ExitTransitTask::handleReadingDistance() { this->distance = sonar->detectDistance(); - Serial.println("ExitTransitTask::Distance: " + String(this->distance)); + // Serial.println("ExitTransitTask::Distance: " + String(this->distance)); this->setState(CHECKING_DISTANCE); } @@ -66,13 +66,13 @@ void ExitTransitTask::handleCheckingDistance() void ExitTransitTask::handleClosesGate() { this->gate->write(GATE_CLOSE_POSITION); - Serial.println(F("ExitTransitTask::Gate closed")); + // Serial.println(F("ExitTransitTask::Gate closed")); this->setState(SWITCH_OFF_L3); } void ExitTransitTask::handleSwitchOffL3() { this->L3->switchOff(); - Serial.println(F("ExitTransitTask::L3 switched off")); + // Serial.println(F("ExitTransitTask::L3 switched off")); this->setCompleted(); } \ No newline at end of file diff --git a/smart_bridge/src/tasks/ServoTestTask.cpp b/smart_bridge/src/tasks/ServoTestTask.cpp index 0e31053..5ec124c 100644 --- a/smart_bridge/src/tasks/ServoTestTask.cpp +++ b/smart_bridge/src/tasks/ServoTestTask.cpp @@ -2,18 +2,18 @@ // void ServoTestTask::tick() // { -// Serial.println(F("ServoTestTask::tick()")); +// // Serial.println(F("ServoTestTask::tick()")); // switch (this->getState()) // { // case OPEN: -// Serial.println(F("ServoTestTask::OPEN")); +// // Serial.println(F("ServoTestTask::OPEN")); // this->servo.writeMicroseconds(1500); // this->setState(CLOSE); // break; // case CLOSE: // // if (this->elapsedTime() >= 1000) // { -// Serial.println(F("ServoTestTask::CLOSE")); +// // Serial.println(F("ServoTestTask::CLOSE")); // this->servo.writeMicroseconds(0); // this->setState(OPEN); // } diff --git a/smart_bridge/src/tasks/ServoTestTask.h b/smart_bridge/src/tasks/ServoTestTask.h index 06f7f4d..29c15a7 100644 --- a/smart_bridge/src/tasks/ServoTestTask.h +++ b/smart_bridge/src/tasks/ServoTestTask.h @@ -12,7 +12,7 @@ // { // // this->servo = new Servo(); // this->servo.detach(); -// Serial.println(F("Servo::attach" + String(this->servo.attach(SERVO_PIN))); +// // Serial.println(F("Servo::attach" + String(this->servo.attach(SERVO_PIN))); // this->init(1000); // Periodic task, executed every 1000ms // this->setActive(true); // this->setState(OPEN); diff --git a/smart_bridge/src/tasks/SleepingTask.cpp b/smart_bridge/src/tasks/SleepingTask.cpp index 280a6c9..66e7250 100644 --- a/smart_bridge/src/tasks/SleepingTask.cpp +++ b/smart_bridge/src/tasks/SleepingTask.cpp @@ -18,7 +18,7 @@ void SleepingTask::tick() case ALIVE: if (pir->checkDetectedStatus()) { - Serial.println(F("OBJECT revealed")); + // Serial.println(F("OBJECT revealed")); this->setState(OBJECT_DETECTED); } break; diff --git a/smart_bridge/src/tasks/SleepingTask.h b/smart_bridge/src/tasks/SleepingTask.h index d7ac810..5c341e1 100644 --- a/smart_bridge/src/tasks/SleepingTask.h +++ b/smart_bridge/src/tasks/SleepingTask.h @@ -22,7 +22,7 @@ class SleepingTask : public TaskWithState public: SleepingTask() : TaskWithState() { - Serial.println(F("SleepingTask created")); + // Serial.println(F("SleepingTask created")); this->pir = new Pir(PIR_PIN); this->lcd=new LCD(0x27, 16,2); this->init(); diff --git a/smart_bridge/src/tasks/TemperatureTask.cpp b/smart_bridge/src/tasks/TemperatureTask.cpp index 4dea837..db86fef 100644 --- a/smart_bridge/src/tasks/TemperatureTask.cpp +++ b/smart_bridge/src/tasks/TemperatureTask.cpp @@ -5,7 +5,7 @@ TemperatureTask::TemperatureTask() voltageConversionFactor(30), voltageOffset(0.5) { - Serial.println(F("TemperatureTask created")); + // Serial.println(F("TemperatureTask created")); this->lcd = new LCD(0x27, 16, 2); this->setTemperature(this->getTemperature()); this->init(1000); @@ -60,12 +60,12 @@ bool TemperatureTask::checkForCriticalTemperature() void TemperatureTask::criticalTemperatureReachedMessage() { - Serial.println(F("Critical temperature reached!")); + // Serial.println(F("Critical temperature reached!")); } void TemperatureTask::temperatureMaintenanceMessage() { - // Serial.println(F("Detected a Problem - Please Wait")); + // // Serial.println(F("Detected a Problem - Please Wait")); lcd->write("Detected a Problem - Please Wait: ", 0, 0); } diff --git a/smart_bridge/src/tasks/TransitTask.cpp b/smart_bridge/src/tasks/TransitTask.cpp index 49d92d8..1388398 100644 --- a/smart_bridge/src/tasks/TransitTask.cpp +++ b/smart_bridge/src/tasks/TransitTask.cpp @@ -14,15 +14,15 @@ void TransitTask::tick() this->L2->switchOn(); this->distance = sonar->detectDistance(); #ifdef __LOG - Serial.println(F("TransitTask::Distance: ")); - Serial.print(String(this->distance)); + // Serial.println(F("TransitTask::Distance: ")); + // Serial.print(String(this->distance)); #endif if (this->distance < MINDIST) { this->resetTime(); this->setState(CHECKING_DISTANCE); #ifdef __LOG - Serial.println(F("TransitTask::Checking distance")); + // Serial.println(F("TransitTask::Checking distance")); #endif } break; @@ -34,22 +34,22 @@ void TransitTask::tick() } this->distance = sonar->detectDistance(); #ifdef __LOG - Serial.print(F("TransitTask::Distance: ")); - Serial.println(String(this->distance)); + // Serial.print(F("TransitTask::Distance: ")); + // Serial.println(String(this->distance)); #endif if (this->distance < MINDIST) { #ifdef __DEBUG - Serial.print(F("TransitTask::Elapsed: ")); - Serial.println(String(this->elapsedTime())); + // Serial.print(F("TransitTask::Elapsed: ")); + // Serial.println(String(this->elapsedTime())); #endif if (this->elapsedTime() >= (N2 * 1000)) { #ifdef __LOG - Serial.println(F("TransitTask::Distance: ")); - Serial.println(String(this->distance)); - Serial.println(F("TransitTask::Car entered")); - Serial.println(F("TransitTask::Closing gate")); + // Serial.println(F("TransitTask::Distance: ")); + // Serial.println(String(this->distance)); + // Serial.println(F("TransitTask::Car entered")); + // Serial.println(F("TransitTask::Closing gate")); #endif this->gate->write(0); if (this->blinkTask->isActive()) @@ -63,7 +63,7 @@ void TransitTask::tick() else { #ifdef __LOG - Serial.println(F("TransitTask::Reading distance")); + // Serial.println(F("TransitTask::Reading distance")); #endif if (this->blinkTask->isActive()) { @@ -74,7 +74,7 @@ void TransitTask::tick() } break; default: - Serial.println(F("TransitTask::Invalid state")); + // Serial.println(F("TransitTask::Invalid state")); break; } } diff --git a/smart_bridge/src/tasks/TransitTask.h b/smart_bridge/src/tasks/TransitTask.h index cf210e0..f67c2da 100644 --- a/smart_bridge/src/tasks/TransitTask.h +++ b/smart_bridge/src/tasks/TransitTask.h @@ -24,7 +24,7 @@ class TransitTask : public DependantTaskWithState */ TransitTask(BlinkTask *blinkTask) : DependantTaskWithState() { - Serial.println(F("TransitTask created")); + // Serial.println(F("TransitTask created")); this->sonar = new Sonar(SONAR_TRIG_PIN, SONAR_ECHO_PIN, SONAR_MAX_TIME); this->L2 = new Led(L2_PIN); this->lcd = new LCD(0x27, 16, 2); diff --git a/smart_bridge/src/tasks/WaitForClickTask.cpp b/smart_bridge/src/tasks/WaitForClickTask.cpp index b0c0367..ece53c3 100644 --- a/smart_bridge/src/tasks/WaitForClickTask.cpp +++ b/smart_bridge/src/tasks/WaitForClickTask.cpp @@ -9,13 +9,13 @@ void WaitForClickTask::tick() this->lcd->write("Press START to", 0, 0); this->lcd->write("begin washing", 0, 1); #ifdef __LOG - Serial.println(F("WaitForClickTask::Waiting for START click")); + // Serial.println(F("WaitForClickTask::Waiting for START click")); #endif this->start->sync(); if (this->start->isPressed()) { #ifdef __LOG - Serial.println(F("WaitForClickTask::START pressed")); + // Serial.println(F("WaitForClickTask::START pressed")); #endif this->lcd->clear(); this->lcd->write("Starting to wash", 0, 0); diff --git a/smart_bridge/src/tasks/WaitForClickTask.h b/smart_bridge/src/tasks/WaitForClickTask.h index 8c472e9..3f110e6 100644 --- a/smart_bridge/src/tasks/WaitForClickTask.h +++ b/smart_bridge/src/tasks/WaitForClickTask.h @@ -22,7 +22,7 @@ class WaitForClickTask : public DependantTask this->start = new Button(BUTTON_PIN); this->lcd = new LCD(0x27, 16, 2); this->init(); - Serial.println(F("WaitForClickTask created")); + // Serial.println(F("WaitForClickTask created")); }; void tick() override; diff --git a/smart_bridge/src/tasks/WaitingTask.cpp b/smart_bridge/src/tasks/WaitingTask.cpp index 213d287..9226e75 100644 --- a/smart_bridge/src/tasks/WaitingTask.cpp +++ b/smart_bridge/src/tasks/WaitingTask.cpp @@ -11,7 +11,7 @@ void WaitingTask::tick() { case STARTED: break; - Serial.println(F("sono qui in waiting")); + // Serial.println(F("sono qui in waiting")); } } diff --git a/smart_bridge/src/tasks/WaitingTask.h b/smart_bridge/src/tasks/WaitingTask.h index 1aa0cc6..d97ecb4 100644 --- a/smart_bridge/src/tasks/WaitingTask.h +++ b/smart_bridge/src/tasks/WaitingTask.h @@ -18,7 +18,7 @@ class WaitingTask : public DependantTaskWithState this->pir=new Pir(PIR_PIN); //attached to the INTERRUPT_PIN 2 this->init(); this->setState(STARTED); - Serial.println(F("WaitingTask created")); + // Serial.println(F("WaitingTask created")); }; void tick() override; diff --git a/smart_bridge/src/tasks/WashingTask.cpp b/smart_bridge/src/tasks/WashingTask.cpp index f4f5fd0..bc53ed4 100644 --- a/smart_bridge/src/tasks/WashingTask.cpp +++ b/smart_bridge/src/tasks/WashingTask.cpp @@ -5,7 +5,7 @@ WashingTask::WashingTask(BlinkTask *blinkTask, TemperatureTask *temperatureTask) : DependantTaskWithState() { - Serial.println(F("WashingTask created")); + // Serial.println(F("WashingTask created")); this->L2 = new Led(L2_PIN); this->L3 = new Led(L3_PIN); this->tempSensor = new Temp(TMP_PIN); From f3d14d32aded06f2825f0c82c10597c95f175017 Mon Sep 17 00:00:00 2001 From: Alessandro Monticelli Date: Tue, 5 Dec 2023 21:53:47 +0100 Subject: [PATCH 5/7] Fix view parenthesis --- smart_bridge/src/UI/view.py | 4 ++-- smart_bridge/src/main.cpp | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/smart_bridge/src/UI/view.py b/smart_bridge/src/UI/view.py index a1cc707..d700535 100644 --- a/smart_bridge/src/UI/view.py +++ b/smart_bridge/src/UI/view.py @@ -143,9 +143,9 @@ def update_serial(): def start_serial(): global serialInst - serialInst = // SerialSerial() + serialInst = serial.Serial() serialInst.baudrate = 9600 - serialInst.port = 'COM3' #COM3 depends on the port where Arduino is connected + serialInst.port = '/dev/ttyACM0' #COM3 depends on the port where Arduino is connected serialInst.open() root.after(100, update_serial) diff --git a/smart_bridge/src/main.cpp b/smart_bridge/src/main.cpp index 69fe58c..3f2edad 100644 --- a/smart_bridge/src/main.cpp +++ b/smart_bridge/src/main.cpp @@ -23,8 +23,7 @@ SerialReceiver *serialReceiver; void setup() { - - // Serial.begin(9600); + Serial.begin(9600); scheduler.init(50); // NOTE: Might be set higher to use less power, needs testing. /**CREATE TASKS**/ @@ -38,7 +37,7 @@ void setup() WashingTask washingTask = WashingTask(&blinkTask, nullptr, &temperatureTask); CheckOutTask checkOutTask = CheckOutTask(); ExitTransitTask exitTransitTask = ExitTransitTask(); - // /**DEPENDENCIES**/ + /**DEPENDENCIES**/ checkInTask.addDependency(&sleepingTask); transitTask.addDependency(&checkInTask); waitForClickTask.addDependency(&transitTask); @@ -46,7 +45,7 @@ void setup() checkOutTask.addDependency(&washingTask); exitTransitTask.addDependency(&checkOutTask); - // /**ADD TASKS TO THE SCHEDULER**/ + /**ADD TASKS TO THE SCHEDULER**/ scheduler.addTask(&sleepingTask); scheduler.addTask(&checkInTask); scheduler.addTask(&transitTask); From b229788f135c1113f99ec4ed7ea9ac695cf5f685 Mon Sep 17 00:00:00 2001 From: Alessandro Monticelli Date: Tue, 5 Dec 2023 23:18:13 +0100 Subject: [PATCH 6/7] Update TaskWithState --- smart_bridge/src/kernel/TaskWithState.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/smart_bridge/src/kernel/TaskWithState.h b/smart_bridge/src/kernel/TaskWithState.h index 3acfe31..85857d8 100644 --- a/smart_bridge/src/kernel/TaskWithState.h +++ b/smart_bridge/src/kernel/TaskWithState.h @@ -14,11 +14,10 @@ class TaskWithState : public TaskWithTimer { public: - TaskWithState() : TaskWithTimer(), previousState(0){}; // Default constructor + TaskWithState() : TaskWithTimer(){}; // Default constructor void setState(const int state) { - this->previousState = this->state; this->state = state; this->stateTimestamp = millis(); } @@ -28,13 +27,7 @@ class TaskWithState : public TaskWithTimer return this->state; } - int getPreviousState() - { - return this->previousState; - } - private: - int previousState; int state; long stateTimestamp; }; From 004fbc634ce0090f9f1ad2139b3a0697957656ba Mon Sep 17 00:00:00 2001 From: Alessandro Monticelli Date: Wed, 6 Dec 2023 22:32:52 +0100 Subject: [PATCH 7/7] Merge and fix serial receiver --- smart_bridge/src/kernel/SerialReceiver.cpp | 26 +++++++++---------- smart_bridge/src/main.cpp | 30 ---------------------- smart_bridge/src/tasks/WashingTask.cpp | 5 ---- 3 files changed, 13 insertions(+), 48 deletions(-) diff --git a/smart_bridge/src/kernel/SerialReceiver.cpp b/smart_bridge/src/kernel/SerialReceiver.cpp index be8b3bd..e0ed99b 100644 --- a/smart_bridge/src/kernel/SerialReceiver.cpp +++ b/smart_bridge/src/kernel/SerialReceiver.cpp @@ -2,20 +2,20 @@ bool SerialReceiver::readData() { - if (this->simulateDataReceived) { - this->simulateDataReceived = false; - return true; - } - - // if (// Serialavailable() > 0) { //if some data has been received - // String data = // SerialreadString(); - // data.trim(); - // if (data=="mnt:done")) { - // // Serial.println(F("Arduino received message: " + data); - // return true; - // } + // if (this->simulateDataReceived) { + // this->simulateDataReceived = false; + // return true; // } - // return false; + + if (Serial.available() > 0) { //if some data has been received + String data = Serial.readString(); + data.trim(); + if (data=="mnt:done") { + // Serial.println(F("Arduino received message: " + data); + return true; + } + } + return false; } void SerialReceiver::simulateReadData() { diff --git a/smart_bridge/src/main.cpp b/smart_bridge/src/main.cpp index dc31d64..3f2edad 100644 --- a/smart_bridge/src/main.cpp +++ b/smart_bridge/src/main.cpp @@ -27,7 +27,6 @@ void setup() scheduler.init(50); // NOTE: Might be set higher to use less power, needs testing. /**CREATE TASKS**/ -<<<<<<< HEAD BlinkTask blinkTask = BlinkTask(L2_PIN); CountDown countDownTask = CountDown(N3); TemperatureTask temperatureTask = TemperatureTask(); @@ -57,35 +56,6 @@ void setup() scheduler.addTask(&washingTask); scheduler.addTask(&checkOutTask); scheduler.addTask(&exitTransitTask); -======= - CheckInTask *checkInTask = new CheckInTask(); - BlinkTask *blinkTask = new BlinkTask(L2_PIN); - TransitTask *transitTask = new TransitTask(blinkTask); - WaitForClickTask *waitForClickTask = new WaitForClickTask(); - CountDown *countDownTask = new CountDown(N3); - TemperatureTask *temperatureTask = new TemperatureTask(); - WashingTask *washingTask = new WashingTask(blinkTask, countDownTask, temperatureTask); - CheckOutTask *checkOutTask = new CheckOutTask(); - ExitTransitTask *exitTransitTask = new ExitTransitTask(); - - /**DEPENDENCIES**/ - transitTask->addDependency(checkInTask); - waitForClickTask->addDependency(transitTask); - washingTask->addDependency(waitForClickTask); - checkOutTask->addDependency(washingTask); - exitTransitTask->addDependency(checkOutTask); - - /**ADD TASKS TO THE SCHEDULER**/ - scheduler.addTask(checkInTask); - scheduler.addTask(transitTask); - scheduler.addTask(blinkTask); - scheduler.addTask(waitForClickTask); - scheduler.addTask(washingTask); - scheduler.addTask(countDownTask); - scheduler.addTask(temperatureTask); - scheduler.addTask(checkOutTask); - scheduler.addTask(exitTransitTask); ->>>>>>> ae7961de6fe356cd0044a8ce636b972a24eee768 } void loop() diff --git a/smart_bridge/src/tasks/WashingTask.cpp b/smart_bridge/src/tasks/WashingTask.cpp index e4040e8..2814bcd 100644 --- a/smart_bridge/src/tasks/WashingTask.cpp +++ b/smart_bridge/src/tasks/WashingTask.cpp @@ -12,11 +12,7 @@ WashingTask::WashingTask(BlinkTask *blinkTask, this->lcd = new LCD(0x27, 16, 2); this->gate = new ServoImpl(SERVO_PIN); this->blinkTask = blinkTask; -<<<<<<< HEAD - this->blinkTask->init(500); // Blink every 500 ms the red led -======= this->blinkTask->init(500); ->>>>>>> ae7961de6fe356cd0044a8ce636b972a24eee768 this->blinkTask->setActive(false); this->countDownTask = countDownTask; this->temperatureTask = temperatureTask; @@ -100,7 +96,6 @@ void WashingTask::handleError() this->countDownTask->pauseCountDown(); this->temperatureTask->criticalTemperatureReachedMessage(); this->temperatureTask->temperatureMaintenanceMessage(); - this->serialReceiver->simulateReadData(); // TODO: remove, but now simulate receiving "mnt:done" if (serialReceiver->readData() == true) { this->countDownTask->resumeCountDown();