Newer
Older
void web_setup ()
Malaurie Bernard
committed
set_theme(1);
//Create tabs
configurations = ESPUI.addControl(ControlType::Tab, "Configurations", "Configurations");
new_syringe = ESPUI.addControl(ControlType::Tab, "Nouvelle Seringue", "Nouvelle seringue");
features = ESPUI.addControl(ControlType::Tab, "Caracteristiques du pousse-seringue", "Caracteristiques du pousse-seringue");
//***ABOVE***//
//***Syringe-pump***//
status_syringe_pump = ESPUI.label("Etat du pousse-seringue :", ControlColor::None, "A l'arrêt");
activation_syringe_pump = ESPUI.addControl(ControlType::Switcher, "Mise en marche", "Arrêt", ControlColor::None, status_syringe_pump, activation_syringe_pump_callback, (void*)19);
//***Syringe-filled***//
status_syringe_filled = ESPUI.label("Etat de la seringue :", ControlColor::None, "Pas en place");
syringe_filled_placement = ESPUI.addControl(ControlType::Switcher, "Mise en marche", "Arrêt", ControlColor::None, status_syringe_filled, syringe_filled_placement_callback, (void*)19);
ESPUI.addControl(ControlType::Separator, "", "", ControlColor::None);
//***Initialisation***//
initialisation = ESPUI.button("Initialisation", initialisation_callback, ControlColor::None, "Lancer");
Malaurie Bernard
committed
label_remaining_volume_mL = ESPUI.label("Volume restant en mL", ControlColor::None, "Volume restant en mL");
Malaurie Bernard
committed
remaining_volume_mL = ESPUI.addControl(ControlType::Slider, "Distance", "0", ControlColor::None, label_remaining_volume_mL, remaining_volume_mL_callback, (void*)19);
ESPUI.sliderContinuous = true;
//Volume_exchange_wanted
volume_exchange_mL_label = ESPUI.addControl(ControlType::Label, "Caractéristiques de l'échange", "Volume à échanger en mL", ControlColor::None);
volume_exchange_mL = ESPUI.addControl(ControlType::Number,"Caractéristiques de l'échange", "", ControlColor::None, volume_exchange_mL_label, volume_exchange_mL_callback, (void*)19);
exchange_throughtput_uL_per_sec_label = ESPUI.addControl(ControlType::Label, "Caractéristiques de l'échange", "Débit de l'échange en uL/sec", ControlColor::None, volume_exchange_mL_label);
exchange_throughtput_uL_per_sec = ESPUI.addControl(ControlType::Number,"Caractéristiques de l'échange", "", ControlColor::None, volume_exchange_mL_label, exchange_throughtput_uL_per_sec_callback, (void*)19);
label_push_pull_choice = ESPUI.addControl(ControlType::Label, "Delivrer ou recupérer", "Délivrer", ControlColor::None, volume_exchange_mL_label);
switch_push_pull_choice = ESPUI.addControl(ControlType::Switcher, "Delivrer ou recupérer", "Délivrer", ControlColor::None, volume_exchange_mL_label, switch_push_pull_choice_callback, (void*)19);
ESPUI.updateSwitcher(switch_push_pull_choice, true); //pour mettre a "Delivrer" par défaut au début
Malaurie Bernard
committed
syringe_selection = ESPUI.addControl(ControlType::Select, "Choix de la seringue :", "", ControlColor::None, configurations, syringe_selection_callback);
select_syringe_maj(configurations);
syringe_volume_mL_value = 5;
syringe_volume_mL_string = "Volume total: " + std::to_string(syringe_volume_mL_value) + "mL";
syringe_volume_mL =ESPUI.addControl( ControlType::Label, "Caractéristiques de la seringue : ", syringe_volume_mL_string.c_str() , ControlColor::None, configurations);
syringe_diameter_mm_value = 5;
syringe_diameter_mm_string = "internal diameter : " + std::to_string(syringe_volume_mL_value) + "mm";
syringe_diameter_mm =ESPUI.addControl( ControlType::Label, "Caractéristiques de la seringue : ", syringe_diameter_mm_string.c_str(), ControlColor::None, syringe_volume_mL);
choose_syringe = ESPUI.addControl(ControlType::Button, "Choisir cette seringue", "Utiliser cette seringue", ControlColor::None, syringe_selection, choose_syringe_callback, (void*)19);
ESPUI.addControl(ControlType::Separator, "", "", ControlColor::None, configurations);
name_new_syringe_label = ESPUI.addControl(ControlType::Label, "Nouvelle seringue", "Nom de la seringue :", ControlColor::None, new_syringe);
name_new_syringe = ESPUI.addControl(ControlType::Text, "Nouvelle seringue", "", ControlColor::None, name_new_syringe_label, name_new_syringe_callback);
internal_diameter_mm_new_syringe_label =ESPUI.addControl(ControlType::Label, "Nouvelle seringue", "Diamètre interne de la seringue en mm :", ControlColor::None, name_new_syringe_label);
Malaurie Bernard
committed
internal_diameter_mm_new_syringe = ESPUI.addControl(ControlType::Number, "Diamètre interne de la seringue en mm", "5", ControlColor::None, name_new_syringe_label, internal_diameter_mm_new_syringe_callback);
Malaurie Bernard
committed
internal_diameter_mm_new_syringe_value = 5;
total_volume_mL_new_syringe_label =ESPUI.addControl(ControlType::Label, "Nouvelle seringue", "Volume total de la seringue en µL :", ControlColor::None, name_new_syringe_label);
Malaurie Bernard
committed
total_volume_mL_new_syringe = ESPUI.addControl(ControlType::Number, "Volume total de la seringue en µL", "5", ControlColor::None, name_new_syringe_label, total_volume_mL_new_syringe_callback);
Malaurie Bernard
committed
total_volume_mL_new_syringe_value = 5;
add_syringe_label =ESPUI.addControl(ControlType::Label, "Nouvelle seringue", "Ajouter la seringue", ControlColor::None, name_new_syringe_label);
add_syringe = ESPUI.addControl(ControlType::Button, "Ajouter la seringue", "Valider", ControlColor::None, name_new_syringe_label, add_syringe_callback, (void*)19);
worm_diameter_mm = ESPUI.addControl(ControlType::Number, "Diamètre de la vis sans fin", "5", ControlColor::None, features, number_callback);
clockwise_equals_push_label = ESPUI.addControl(ControlType::Label, "Sens de rotation du moteur", "Horaire = Delivrer", ControlColor::None, features);
Malaurie Bernard
committed
clockwise_equals_push = ESPUI.addControl(ControlType::Switcher, "Sens de rotation du moteur", "Horaire =", ControlColor::None, clockwise_equals_push_label, clockwise_equals_push_callback);
ESPUI.updateSwitcher(clockwise_equals_push, true); //set "Horaire = Delivrer" at the beginning
set_init_style();
ESPUI.begin("ESPUI Control");
void number_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(sender->value);
//SPECIFIC CALLBACKS//
//***ABOVE***//
void activation_syringe_pump_callback (Control* sender, int value, void* param)
/***
-Argument : Pointer to the controller calling the function, integer according to the controller type.
-Return : /
-Action : Linking the switch of the syringe pump status and the actions.
***/
Serial.println(String("param: ") + String(long(param)));
switch (value)
{
case S_ACTIVE:
syringe_pump_on();
break;
case S_INACTIVE:
syringe_pump_off();
break;
}
Serial.print(" ");
Serial.println(sender->id);
void syringe_filled_placement_callback (Control* sender, int value, void* param)
/***
-Argument : Pointer to the controller calling the function, integer according to the controller type.
-Return : /
-Action : Linking the switch of the syringe filled status(placed or not) and the actions.
***/
{
Serial.println(String("param: ") + String(long(param)));
switch (value)
syringe_filled_placement_on();
break;
case S_INACTIVE:
syringe_filled_placement_off();
Serial.print(" ");
Serial.println(sender->id);
}
void initialisation_callback (Control *sender, int type)
/***
-Argument : Pointer to the controller calling the function, integer according to the controller type.
-Return : /
-Action : Enable the syringe-pump initialisation and change the style appropriately.
***/
{
if((type == B_UP)) {
Serial.printf("Go to zero");
syringe_filled.go_to_zero();
Serial.print("Active:");
ESPUI.print(status_syringe_pump, "En marche");
ESPUI.updateSwitcher(activation_syringe_pump, true);
style (status_syringe_pump, 1);
style (activation_syringe_pump, 1);
}
}
void volume_exchange_mL_callback (Control* sender, int value, void* param)
/***
-Argument : Pointer to the controller calling the function, integer according to the controller type.
-Return : /
-Action : Enable to choose the volume that woud be exchanged.
***/
{
Serial.printf("val=%s\n", sender->value.c_str());
syringe_filled.set_exchange_volume_mL(atof(sender->value.c_str()));
void exchange_throughtput_uL_per_sec_callback (Control* sender, int value, void* param)
/***
-Argument : Pointer to the controller calling the function, integer according to the controller type.
-Return : /
-Action : Enable to choose the volume that woud be exchanged.
***/
{
Serial.printf("val=%s\n", sender->value.c_str());
syringe_filled.set_exchange_throughput_uL_per_sec(atof(sender->value.c_str()));
syringe_filled.write_Json ();
}
void switch_push_pull_choice_callback (Control* sender, int value, void* param)
/***
-Argument : Pointer to the controller calling the function, integer according to the controller type.
-Return : /
-Action : Change the label_push_pull_choice to display the choice.
Change the style of the controller involved.
***/
{
Serial.println(String("param: ") + String(long(param)));
switch (value)
{
case S_ACTIVE:
syringe_filled.set_push(true);
ESPUI.print(label_push_pull_choice, "Délivrer");
style (volume_exchange_mL_label, 1);
style (volume_exchange_mL, 1);
style (exchange_throughtput_uL_per_sec_label, 1);
style (exchange_throughtput_uL_per_sec, 1);
style (label_push_pull_choice, 1);
style (switch_push_pull_choice, 1);
break;
case S_INACTIVE:
syringe_filled.set_push(false);
ESPUI.print(label_push_pull_choice, "Recupérer");
style (volume_exchange_mL_label, 2);
style (volume_exchange_mL, 2);
style (exchange_throughtput_uL_per_sec_label, 2);
style (exchange_throughtput_uL_per_sec, 2);
style (label_push_pull_choice, 2);
style (switch_push_pull_choice, 2);
syringe_filled.write_Json();
Serial.print(" ");
Serial.println(sender->id);
}
void remaining_volume_mL_callback (Control* sender, int value, void* param)
/***
-Argument : Pointer to the controller calling the function, integer according to the controller type.
-Return : /
-Action : Linking the display with the current volume remaining.
***/
{
ESPUI.updateSlider(remaining_volume_mL, syringe_filled.get_remaining_volume_mL());
}
//configurations = Configurations
void choose_syringe_callback (Control* sender, int value, void* param)
/***
-Argument : Pointer to the controller calling the function, integer according to the controller type.
-Return : /
-Action : Print the value of the button state via the serial port.
***/
switch (value)
{
case B_DOWN:
Serial.println("Button DOWN");
//syringe_volume_mL_value = 2; //Mettre la valeur associé au nom choisit du select
syringe_volume_mL_value = syringe.get_syringe_database()[select_value]["total_volume_mL"];
syringe_volume_mL_string = "Volume total: " + std::to_string(syringe_volume_mL_value) + "mL";
ESPUI.print(syringe_volume_mL, syringe_volume_mL_string.c_str());
//syringe_diameter_mm_value = 1; //Mettre la valeur associé au nom choisit du select
syringe_diameter_mm_value = syringe.get_syringe_database()[select_value]["internal_diameter_mm"];
syringe_diameter_mm_string = "internal diameter : " + std::to_string(syringe_volume_mL_value) + "mm";
ESPUI.print(syringe_diameter_mm, syringe_diameter_mm_string.c_str());
case B_UP:
Serial.println("Button UP");
break;
}
}
void name_new_syringe_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 new syringe name chosen via the serial port.
***/
{
Malaurie Bernard
committed
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
name_new_syringe_value = sender->value;
Serial.print("Text: ID: ");
Serial.print(sender->id);
Serial.print(", Value: ");
Serial.println(sender->value);
}
void total_volume_mL_new_syringe_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 new syringe name chosen via the serial port.
***/
{
total_volume_mL_new_syringe_value = sender->value;
Serial.print("Text: ID: ");
Serial.print(sender->id);
Serial.print(", Value: ");
Serial.println(sender->value);
}
void internal_diameter_mm_new_syringe_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 new syringe name chosen via the serial port.
***/
{
internal_diameter_mm_new_syringe_value = sender->value,
Serial.print("Text: ID: ");
Serial.print(sender->id);
Serial.print(", Value: ");
Serial.println(sender->value);
}
void add_syringe_callback (Control* sender, int value, void* param)
/***
-Argument : Pointer to the controller calling the function, integer according to the controller type.
-Return : /
-Action : Print the value of the button state via the serial port.
Enable to save data in the syringe_json file.
***/
switch (value)
{
case B_DOWN:
Serial.println("Button DOWN");
Malaurie Bernard
committed
syringe.set_syringe(name_new_syringe_value, total_volume_mL_new_syringe_value.toFloat(), internal_diameter_mm_new_syringe_value.toFloat());
syringe.write_Json();
select_syringe_maj(configurations);
case B_UP:
Serial.println("Button UP");
break;
}
}
//features : Configurations avancées
void clockwise_equals_push_callback(Control* sender, int value)
/***
-Argument : Pointer to the controller calling the function, integer according to the controller type.
-Return : /
-Action : Print the value of the convention chosen via the serial port.
Change the clockwise_equals_push_label to display the information.
***/
{
switch (value)
{
case S_ACTIVE:
Serial.print("Clockwise equals push");
ESPUI.print(clockwise_equals_push_label, "Horaire = Delivrer");
break;
case S_INACTIVE:
Serial.print("Clockwise equals pull");
ESPUI.print(clockwise_equals_push_label, "Horaire = Récupérer");
break;
}
Serial.print(" ");
Serial.println(sender->id);
}
void syringe_selection_callback(Control* sender, int value)
/***
-Argument : Pointer to the controller calling the function, integer according to the controller type.
-Return : /
-Action : Print the value of the syringe name chosen via the serial port.
***/
{
Serial.print("Select: ID: ");
Serial.print(sender->id);
Serial.print(", Value: ");
Serial.println(sender->value);
select_value = sender->value;
}
Malaurie Bernard
committed
//ON_OFF METHODS
Malaurie Bernard
committed
void syringe_pump_on_off()
/***
-Argument : /
-Return : /
-Action : Update the display of the syringe-pump status to match when the motor runs or not (so when we initialize, it stop by itself)
***/
{
if (syringe_filled.is_running())
{
ESPUI.updateControlValue(activation_syringe_pump, "1");
}
ESPUI.updateControlValue(activation_syringe_pump, "0");
}
void syringe_pump_on()
/***
-Argument : /
-Return : /
-Action : Change the status_syringe_pump label to display the information.
Change the style of the controller involved.
Causes the movement of the syringe pump.
***/
{
ESPUI.print(status_syringe_pump, "En marche");
ESPUI.updateSwitcher(activation_syringe_pump, true);
style (status_syringe_pump, 1);
style (activation_syringe_pump, 1);
syringe_filled.move();
}
void syringe_pump_off()
/***
-Argument : /
-Return : /
-Action : Change the status_syringe_pump label to display the information.
Change the style of the controller involved.
Causes the stop of the syringe pump.
***/
{
ESPUI.print(status_syringe_pump, "A l'arrêt");
ESPUI.updateSwitcher(activation_syringe_pump, false);
style (status_syringe_pump, 2);
style (activation_syringe_pump, 2);
syringe_filled.stop();
}
void syringe_filled_placement_on()
/***
-Argument : /
-Return : /
-Action : Change the status_syringe_filled label to display the information.
Change the style of the controller involved.
Disable the initialisation.
***/
ESPUI.print(status_syringe_filled, "En place");
style (status_syringe_filled, 1);
style (syringe_filled_placement, 1);
Malaurie Bernard
committed
ESPUI.setEnabled(initialisation, false);
style (initialisation, 2);
void syringe_filled_placement_off()
/***
-Argument : /
-Return : /
-Action : Change the status_syringe_filled label to display the information.
Change the style of the controller involved.
Enable the initialisation.
***/
{
ESPUI.print(status_syringe_filled, "Enlevée");
style (status_syringe_filled, 2);
style (syringe_filled_placement, 2);
Malaurie Bernard
committed
ESPUI.setEnabled(initialisation, true);
style (initialisation, 1);
}
/*************OTHER_METHODS****************/
void style (uint16_t id, int style)
/***
-Argument : The controller id and the style wanted.
-Return : /
-Action : Change style (1 is active, green; 2 is inactive, red; 3 is neutral, brown)
***/
{
switch (style)
{
case 1:
ESPUI.setPanelStyle(id, couleurs[0]);
ESPUI.setElementStyle(id, couleurs[1]);
break;
case 2:
ESPUI.setPanelStyle(id, couleurs[2]);
ESPUI.setElementStyle(id, couleurs[3]);
break;
case 3:
ESPUI.setPanelStyle(id, couleurs[4]);
ESPUI.setElementStyle(id, couleurs[5]);
break;
}
}
void set_init_style()
/***
-Argument : /
-Return : /
-Action : Set up the initial style of every controller.
Malaurie Bernard
committed
{
//***ABOVE***//
style (status_syringe_pump, 2);
style (activation_syringe_pump, 2);
style (status_syringe_filled, 2);
style (syringe_filled_placement, 2);
style (initialisation, 2);
style (volume_exchange_mL_label, 1);
style (volume_exchange_mL, 1);
style (exchange_throughtput_uL_per_sec_label, 1);
style (exchange_throughtput_uL_per_sec, 1);
style (label_push_pull_choice, 1);
style (switch_push_pull_choice, 1);
style (label_remaining_volume_mL, 3);
//configurations = Configurations
style (syringe_volume_mL, 3);
style (syringe_diameter_mm, 3);
style (choose_syringe, 3);
style (name_new_syringe, 3);
style (internal_diameter_mm_new_syringe, 3);
style (total_volume_mL_new_syringe, 3);
style (add_syringe, 3);
style (name_new_syringe_label, 3);
style (internal_diameter_mm_new_syringe_label, 3);
style (total_volume_mL_new_syringe_label, 3);
style (add_syringe_label, 3);
//features : Configurations avancées
style (clockwise_equals_push_label, 3);
style (clockwise_equals_push, 3);
Malaurie Bernard
committed
}
void set_theme(int theme)
/***
-Argument : Integer defining the theme wanted.
-Return : /
-Action : Change the interface theme for dark, light of colorful theme.
***/
Malaurie Bernard
committed
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
{
if (theme ==1)
{
//Creation des différents styles
//Les verts pour la mise en mrche de la seringue
sprintf(couleur1, "background-color: #%06X;", (unsigned int) 0xb2dbbf);
sprintf(couleur2, "background-color: #%06X;", (unsigned int) 0x5a8668);
//Le rouge pour la seringue a l'arrêt
sprintf(couleur3, "background-color: #%06X;", (unsigned int) 0xc97064);
sprintf(couleur4, "background-color: #%06X;", (unsigned int) 0x762419);
//Les marrons pour la config des seringues
sprintf(couleur5, "background-color: #%06X;", (unsigned int) 0xce9f6f);
sprintf(couleur6, "background-color: #%06X;", (unsigned int) 0x926448);
//Pas utilisé pour le moment
sprintf(couleur7, "background-color: #%06X;", (unsigned int) 0x0a7477);
sprintf(couleur8, "background-color: #%06X;", (unsigned int) 0x052a38);
sprintf(couleur9, "background-color: #%06X;", (unsigned int) 0x044365);
sprintf(couleur10, "background-color: #%06X;", (unsigned int) 0x58b8c3);
}
}
void select_syringe_maj(uint16_t tab)
/***
-Argument : The page on which the info must display.
-Return : /
-Action : Read the syringe_json file so it get/recover all the syringe models registered.
***/
{
JsonObject root = syringe.get_syringe_database_object();
for (JsonPair kv : root)
{
ESPUI.addControl(ControlType::Option, kv.key().c_str(), kv.key().c_str(), ControlColor::None, syringe_selection);
}
style (syringe_selection, 3);
}
//bool switchi = syringe.isRunning();
//bool a = syringe.isRunning();
if(millis() > last_time + 500) {
last_time = millis();
//UPDATES
syringe_filled.update_remaining_volume();
if (syringe_filled.is_running())
syringe_pump_on();
else
syringe_pump_off();
}