From 5b5b11284653312f694a10e002cc1d45d6e752d0 Mon Sep 17 00:00:00 2001 From: Malaurie Bernard <mbernard@kinouby> Date: Thu, 24 Aug 2023 11:01:58 +0200 Subject: [PATCH] Add a getter to update the limit switch right when it et pressed/released and do not clutter the web_loop --- pousseseringue-arduino.cpp | 13 +++++++++++ web.cpp | 44 +++++++++++++++++--------------------- web.h | 5 ++++- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/pousseseringue-arduino.cpp b/pousseseringue-arduino.cpp index 25f779a..3c2264c 100644 --- a/pousseseringue-arduino.cpp +++ b/pousseseringue-arduino.cpp @@ -59,6 +59,7 @@ SSD1306AsciiWire oled; #include "common.h" #include "fs.h" +#include <ESPUI.h> enum class Modes { TURN, TURNSetup, RPM, RPMSetup, INFO }; @@ -371,6 +372,18 @@ void loop() { syringe_filled.manage_emergency(bEmergency.pressed(), !!stepper.distanceToGo()); Serial.printf("%sEmergency=%u (remaining steps = %lu)\n", msgHeader, bEmergency.pressed(), stepper.distanceToGo()); + + if (bEmergency.pressed()) + { + ESPUI.print(web.get_id_status_limit_switch(), "On"); + web.style (web.get_id_status_limit_switch(), 2); + } + else + { + ESPUI.print(web.get_id_status_limit_switch(), "Off"); + web.style (web.get_id_status_limit_switch(), 1); + } + } diff --git a/web.cpp b/web.cpp index 7eb8419..18e3114 100644 --- a/web.cpp +++ b/web.cpp @@ -144,22 +144,31 @@ void Web :: web_setup() } +//getters +uint16_t Web :: get_id_status_limit_switch() +{ + return status_limit_switch; +} + /************CALLBACK_METHODS****************/ -//GENERAL CALLBACKS// -void Web :: number_callback(Control* sender, int type) +void Web :: lead_screw_pitch_mm_callback(Control* sender, int type) /*** -Argument : Pointer to the controller calling the function, integer according to the controller type. -Return : / -Action : Print the value of the number controller via the serial port. ***/ { - Serial.println("Type: number"); - Serial.println(String("Value: ") + String(sender->value)); - Serial.println(String("ID: ") + sender->id); + syringe_filled.set_lead_screw_pitch_mm(atof(sender->value.c_str())); + syringe_filled.save_json(); + + serial_print ("lead_screm_pitch_mm (sender->value)", sender); + + Serial.println("lead_screm_pitch_mm (json value)"); + Serial.println(String("Value: ") + String(syringe_filled.get_lead_screw_pitch_mm())); Serial.println(""); -} +} //SPECIFIC CALLBACKS// @@ -1069,18 +1078,12 @@ void Web :: serial_print (String name, Control* sender) } - //WEB_LOOP// void Web :: web_loop() { #if 0 - if(millis() > last_time + 4) { - last_time = millis(); - - //UPDATES - - //ESPUI.updateSlider(remaining_volume_mL, syringe_filled.step_to_mm(syringe_filled.where_step()*100/syringe_filled.get_syringe_pump_length_mm())); - + if(millis() > last_time + 4) { + last_time = millis(); if (syringe_filled.is_running()==false) { @@ -1092,17 +1095,10 @@ void Web :: web_loop() } - if (syringe_filled.get_emergency()) - { - ESPUI.print(status_limit_switch, "On"); - style (status_limit_switch, 2); - } + } - else - { - ESPUI.print(status_limit_switch, "Off"); - style (status_limit_switch, 1); - } +#endif +#if 0 if (syringe_filled.get_update_remaining_volume()) ESPUI.updateSlider(remaining_volume_mL, syringe_filled.get_remaining_volume_mL() + syringe_filled.mm_to_volume(syringe_filled.step_to_mm(syringe_filled.where_step()))); diff --git a/web.h b/web.h index 2f5ae77..ab8b914 100644 --- a/web.h +++ b/web.h @@ -74,11 +74,14 @@ public : void web_setup(); void web_loop(); +//getters +uint16_t get_id_status_limit_switch(); + /************CALLBACK_METHODS****************/ //GENERAL CALLBACKS// - void number_callback(Control* sender, int type); + void lead_screw_pitch_mm_callback(Control* sender, int type); //SPECIFIC CALLBACKS// -- GitLab