diff --git a/syringefilled.cpp b/syringefilled.cpp index 17d7a65a142501d04aaf706c0433d309dbc3e2ec..86ce21e99cec247ba90ed784d6edd4dd483103a2 100644 --- a/syringefilled.cpp +++ b/syringefilled.cpp @@ -21,6 +21,7 @@ SyringeFilled :: SyringeFilled (MotorHardware_t& stepper): Motor(stepper) set_syringe_pump_length_mm(50); set_microstep_configuration(16); set_motor_steps(200); + set_motor_release(false); set_emergency(false); } @@ -77,6 +78,11 @@ void SyringeFilled :: set_motor_steps(int motor_steps) syringe_filled_json["motor_steps"] = motor_steps; } +void SyringeFilled :: set_motor_release(int motor_release) +{ + syringe_filled_json["motor_release"] = motor_release; +} + void SyringeFilled :: set_emergency(bool emergency) { syringe_filled_json["emergency"] = emergency; @@ -134,6 +140,11 @@ int SyringeFilled :: get_motor_steps() return syringe_filled_json["motor_steps"].as<int>(); } +bool SyringeFilled :: get_motor_release() +{ + return syringe_filled_json["motor_release"].as<bool>(); +} + bool SyringeFilled :: get_emergency() { return syringe_filled_json["emergency"].as<bool>(); @@ -210,6 +221,7 @@ void SyringeFilled :: start_exchange() float radius = syringe.get_syringe_database()[syringe_filled_json["name_syringe"]]["internal_diameter_mm"]; float section_mm2 = M_PI*radius*radius; + digitalWrite(SLEEP, LOW); set_speed_mm_per_sec(get_exchange_throughput_uL_per_sec()/section_mm2); @@ -235,6 +247,7 @@ void SyringeFilled :: go_to_zero() ***/ { + digitalWrite(SLEEP, LOW); if (get_emergency()) { return; diff --git a/syringefilled.h b/syringefilled.h index 7c3df12817a11a83d0cd116051c92c4d2e6052b9..5aa206b1452733bf73d3b143716447e117971c41 100644 --- a/syringefilled.h +++ b/syringefilled.h @@ -63,6 +63,7 @@ class SyringeFilled : public Motor void set_syringe_pump_length_mm(float syringe_pump_length_mm); void set_microstep_configuration(int microstep_configuration); void set_motor_steps(int motor_steps); + void set_motor_release(int motor_release); void set_emergency(bool emergency); @@ -77,6 +78,7 @@ class SyringeFilled : public Motor float get_lead_screw_pitch_mm(); int get_microstep_configuration(); int get_motor_steps(); + bool get_motor_release(); bool get_emergency(); const StaticJsonDocument<200>& get_syringe_filled_data(); diff --git a/web.cpp b/web.cpp index 376be8ff9c51923d01d2b88ac311969a6ed5c81a..89dc2cbfb12174039e5373ed281f7c7c1352cc8e 100644 --- a/web.cpp +++ b/web.cpp @@ -153,8 +153,9 @@ void Web :: web_setup() motor_steps = ESPUI.addControl(ControlType::Number, "Caractéristique du moteur (nombre de pas possibles ?)", "2000", ControlColor::None, features,[&](Control* sender, int value){motor_steps_callback(sender, value);}); - - + motor_release_label = ESPUI.addControl(ControlType::Label, "Relachement du moteur", "Off", ControlColor::None, features); + motor_release = ESPUI.addControl(ControlType::Switcher, "Relachement du moteur", "", ControlColor::None, motor_release_label, [&](Control* sender, int value){motor_release_callback(sender, value);}); + //Begin set_initial_style(); @@ -254,6 +255,8 @@ void Web :: fast_backward_callback (Control *sender, int type) { case B_DOWN: + digitalWrite(SLEEP, LOW); + syringe_filled.move_to_mm(syringe_filled.get_clockwise_equals_push()? -50:50); syringe_filled.set_speed_mm_per_sec(50); @@ -263,6 +266,8 @@ void Web :: fast_backward_callback (Control *sender, int type) style_syringe_pump_off(); + motor_release_action(); + break; } @@ -282,6 +287,8 @@ void Web :: fast_forward_callback (Control *sender, int type) { case B_DOWN: + digitalWrite(SLEEP, LOW); + syringe_filled.move_to_mm(syringe_filled.get_clockwise_equals_push()? 50:-50); syringe_filled.set_speed_mm_per_sec(50); @@ -290,6 +297,9 @@ void Web :: fast_forward_callback (Control *sender, int type) case B_UP: style_syringe_pump_off(); + + motor_release_action(); + break; } @@ -308,6 +318,8 @@ void Web :: slow_backward_callback (Control *sender, int type) { case B_DOWN: + digitalWrite(SLEEP, LOW); + syringe_filled.move_to_mm(syringe_filled.get_clockwise_equals_push()? -50:50); syringe_filled.set_speed_mm_per_sec(0.5); @@ -316,6 +328,9 @@ void Web :: slow_backward_callback (Control *sender, int type) case B_UP: style_syringe_pump_off(); + + motor_release_action(); + break; } @@ -334,7 +349,9 @@ void Web :: slow_forward_callback (Control *sender, int type) switch (type) { case B_DOWN: - + + digitalWrite(SLEEP, LOW); + syringe_filled.move_to_mm(syringe_filled.get_clockwise_equals_push()? 50:-50); syringe_filled.set_speed_mm_per_sec(0.5); @@ -343,6 +360,8 @@ void Web :: slow_forward_callback (Control *sender, int type) case B_UP: style_syringe_pump_off(); + + motor_release_action(); break; } @@ -691,6 +710,35 @@ void Web :: motor_steps_callback(Control* sender, int type) Serial.println(""); } +void Web :: motor_release_callback(Control* sender, int value) + { + switch (value) + { + case S_ACTIVE: + syringe_filled.set_motor_release(true); + ESPUI.print(motor_release_label, "On"); + syringe_filled.write_Json(); + + break; + + case S_INACTIVE: + syringe_filled.set_motor_release(false); + + if (!syringe_filled.is_running()) + digitalWrite(SLEEP, HIGH); + + ESPUI.print(motor_release_label, "Off"); + syringe_filled.write_Json(); + break; + } + + serial_print ("motor_release (sender->value)", sender); + + Serial.println("motor_release (json value)"); + Serial.println(String("Value: ") + String(syringe_filled.get_motor_release())); + Serial.println(""); + } + // @@ -822,6 +870,8 @@ void Web :: set_initial_style() style (clockwise_equals_push, 3); style (microstep_configuration, 3); style (motor_steps, 3); + style (motor_release_label, 3); + style (motor_release, 3); // @@ -955,7 +1005,6 @@ void Web :: style_exchange_configuration(int style_choice) //OTHER METHODS - void Web :: select_syringe_maj(uint16_t tab) /*** -Argument : The page on which the info must display. @@ -981,6 +1030,16 @@ void Web :: number_max_min(int min, int max, uint16_t control) ESPUI.addControl(Max, "", String(max), ControlColor :: None, control); } +void Web :: motor_release_action() +{ + if (syringe_filled.get_motor_release()) + { + digitalWrite(SLEEP, LOW); + } + else + digitalWrite(SLEEP, HIGH); +} + void Web :: serial_print (String name, Control* sender) { Serial.println(name); @@ -1003,7 +1062,12 @@ void Web :: web_loop() ESPUI.updateSlider(remaining_volume_mL, syringe_filled.step_to_mm(syringe_filled.where_step()*100/syringe_filled.get_syringe_pump_length_mm())); if (syringe_filled.is_running()==false) + { style_syringe_pump_off(); + if (syringe_filled.get_motor_release()) + digitalWrite(SLEEP, LOW); + + } if (syringe_filled.get_emergency()) { diff --git a/web.h b/web.h index cc6bb206278c249eb50234eee356aa270ea30ea8..90528e0b9e328398233be2b483a8047f9146efe1 100644 --- a/web.h +++ b/web.h @@ -51,7 +51,7 @@ private : //Features uint16_t syringe_pump_length_mm_value; - uint16_t lead_screw_pitch_mm, clockwise_equals_push_label, clockwise_equals_push, microstep_configuration, motor_steps; + uint16_t lead_screw_pitch_mm, clockwise_equals_push_label, clockwise_equals_push, microstep_configuration, motor_steps, motor_release, motor_release_label; //Other @@ -86,7 +86,7 @@ public : void fast_backward_callback (Control *sender, int type); void fast_forward_callback (Control *sender, int type); void slow_backward_callback (Control *sender, int type); - void slow_forward_callback (Control *sender, int type); + void slow_forward_callback (Control *senmotor_release_labelder, int type); void confirm_initialisation_callback (Control *sender, int type); void volume_exchange_mL_callback (Control* sender, int value); void exchange_throughtput_uL_per_sec_callback (Control* sender, int value); @@ -109,6 +109,7 @@ public : void clockwise_equals_push_callback(Control* sender, int value); void microstep_configuration_callback(Control* sender, int type); void motor_steps_callback(Control* sender, int type); + void motor_release_callback(Control* sender, int type); // void syringe_selection_callback(Control* sender, int value); @@ -135,6 +136,7 @@ public : //OTHER_METHODS void select_syringe_maj(uint16_t tab); void number_max_min(int min, int max, uint16_t control); + void motor_release_action(); void serial_print (String name, Control* sender); };