Skip to content
Snippets Groups Projects
web.cpp 10.7 KiB
Newer Older
David Gauchard's avatar
David Gauchard committed

{
   
    //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);


    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);





    uint16_t tab1 = ESPUI.addControl(ControlType::Tab, "Configurations", "Configurations");
    uint16_t tab3 = ESPUI.addControl(ControlType::Tab, "Nouvelle Seringue", "Nouvelle seringue");
    uint16_t tab4 = ESPUI.addControl(ControlType::Tab, "Caracteristiques du pousse-seringue", "Caracteristiques du pousse-seringue");
    //***Syringe-pump***//
    status_syringe_pump = ESPUI.label("Etat du pousse-seringue :", ControlColor::None, "A l'arrêt");

Malaurie Bernard's avatar
Malaurie Bernard committed
    activation_syringe_pump = ESPUI.addControl(ControlType::Switcher, "Mise en marche", "Arrêt", ControlColor::None, status_syringe_pump, syringe_pump_callback, (void*)19);
    style (status_syringe_pump, 2);
    style (activation_syringe_pump, 2);

    //***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);

    
    //Style
    style (status_syringe_filled, 2);
    style (syringe_filled_placement, 2);


    //***Initialisation***//
    initialisation = ESPUI.button("Initialisation", initialisation_callback, ControlColor::None, "");
    //ESPUI.updateVisibility(initialisation, false);


    //Deplacement demandé du pousse-seringue
    position_choice = ESPUI.number("Choix du volume à echanger", position_choice_callback, ControlColor::None, 0, 0, 50, (void*)19);

    label_position_choice = ESPUI.addControl(ControlType::Label, "Distance", "0", ControlColor::None, position_choice, status_position_choice_callback);
    ESPUI.addControl(ControlType::Slider, "Distance", "0", ControlColor::None, position_choice, progress_move_callback, (void*)19);

    ESPUI.sliderContinuous = true;
    style (position_choice, 3);
    style (label_position_choice, 3);






    //TAB1  = Configurations

    //Choix de la seringue 1
    ESPUI.addControl(ControlType::Separator, "Seringue 1", "", ControlColor::None, tab1);

    select_syringe_maj(tab1);

    uint16_t syringe_ref = ESPUI.addControl( ControlType::Label, "Caractéristiques de la seringue 1 : ", "Reférence : ? " , ControlColor::None, tab1);
    uint16_t syringe_brand =ESPUI.addControl( ControlType::Label, "Caractéristiques de la seringue 1 : ", "Marque : ? " , ControlColor::None, syringe_ref);
    uint16_t syringe_volume =ESPUI.addControl( ControlType::Label, "Caractéristiques de la seringue 1 : ", "Volume total = ? mL" , ControlColor::None, syringe_ref);
    uint16_t syringe_diameter =ESPUI.addControl( ControlType::Label, "Caractéristiques de la seringue 1 : ", "Diamètre interne = ? mm" , ControlColor::None, syringe_ref);
    style (syringe_ref, 3);
    style (syringe_brand, 3);
    style (syringe_volume, 3);
    style (syringe_diameter, 3);
    choose_syringe = ESPUI.addControl(ControlType::Button, "Choisir cette seringue", "Valider", ControlColor::None, syringe_selection, choose_syringe_callback, (void*)19);
  
    new_syringe =ESPUI.addControl(ControlType::Text, "Nouvelle seringue", "Nom de la seringue :", ControlColor::None, tab3, syringe_name_callback);
    ESPUI.addControl(ControlType::Number, "Diamètre interne de la seringue en mm", "5", ControlColor::None, new_syringe, number_callback);
    ESPUI.addControl(ControlType::Number, "Volume total de la seringue en µL", "5", ControlColor::None, new_syringe, number_callback);
    add_syringe = ESPUI.addControl(ControlType::Button, "Ajouter la seringue", "Valider", ControlColor::None, new_syringe, add_syringe_callback, (void*)19);
    
    style (new_syringe, 3);

    //TAB4 : Configurations avancées
    //Diamètre de la vis
    ESPUI.addControl(ControlType::Number, "Diamètre de la vis sans fin", "5", ControlColor::None, tab4, number_callback);
    //Sens de rotation du moteur
    ESPUI.addControl(ControlType::Switcher, "Sens de rotation du moteur", "Horaire", ControlColor::None, tab4, switch_callback);
Malaurie Bernard's avatar
Malaurie Bernard committed
/************CALLBACK_METHODS****************/
void number_callback(Control* sender, int type)
{
    Serial.println(sender->value);
void syringe_name_callback(Control* sender, int type)
{
    Serial.print("Text: ID: ");
    Serial.print(sender->id);
    Serial.print(", Value: ");
    Serial.println(sender->value);
David Gauchard's avatar
David Gauchard committed

void syringe_selection_callback(Control* sender, int value)
David Gauchard's avatar
David Gauchard committed
{
    Serial.print("Select: ID: ");
    Serial.print(sender->id);
    Serial.print(", Value: ");
    Serial.println(sender->value);
David Gauchard's avatar
David Gauchard committed

void switch_callback(Control* sender, int value)
{
    switch (value)
    {
    case S_ACTIVE:
        Serial.print("Active:");
        break;

    case S_INACTIVE:
        Serial.print("Inactive");
        break;
    }

    Serial.print(" ");
    Serial.println(sender->id);
void button_seringue(Control* sender, int type)
David Gauchard's avatar
David Gauchard committed
{
    switch (type)
    {
    case B_DOWN:
        Serial.println("Button DOWN");
        break;

    case B_UP:
        Serial.println("Button UP");
        break;
    }
}


void syringe_pump_callback (Control* sender, int value, void* param)
{

    Serial.println(String("param: ") + String(long(param)));
    switch (value)
David Gauchard's avatar
David Gauchard committed
    {
    Serial.print(" ");
    Serial.println(sender->id);
}

Malaurie Bernard's avatar
Malaurie Bernard committed
void syringe_pump_on_off()
      ESPUI.updateControlValue(activation_syringe_pump, "1");
    ESPUI.updateControlValue(activation_syringe_pump, "0");
void initialisation_callback (Control *sender, int type) {
        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 progress_move_callback (Control* sender, int value, void* param)
{
void position_choice_callback (Control* sender, int value, void* param)
    Serial.printf("val=%s\n", sender->value.c_str()); 
    syringe_filled.set_exchange_volume_mL(atof(sender->value.c_str()));
}
void status_position_choice_callback (Control* sender, int value)
{

}

void add_syringe_callback (Control* sender, int value,  void* param)
{
    case B_DOWN:
        Serial.println("Button DOWN");
        syringe.write_Json();
        break;
    case B_UP:
        Serial.println("Button UP");
        break;
    }
    

}
void syringe_filled_placement_callback (Control* sender, int value, void* param)
{
    Serial.println(String("param: ") + String(long(param)));
    switch (value)
    {
    case S_ACTIVE:
        syringe_filled_placement_on();
        syringe_filled_placement_off();
    Serial.print(" ");
    Serial.println(sender->id);

void choose_syringe_callback (Control* sender, int value, void* param)
{
        switch (value)
    {
    case B_DOWN:
        Serial.println("Button DOWN");
        break;

    case B_UP:
        Serial.println("Button UP");
        break;
    }
    
}

/*************ON/OFF_METHODS****************/

void syringe_pump_on()
    ESPUI.print(status_syringe_pump, "En marche");
    ESPUI.updateSwitcher(activation_syringe_pump, true);
    style (status_syringe_pump, 1);
    style (activation_syringe_pump, 1);
void syringe_pump_off()
    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);
void syringe_filled_placement_on()
    ESPUI.print(status_syringe_filled, "En place");
    style (status_syringe_filled, 1);
    style (syringe_filled_placement, 1);
    
    ESPUI.setEnabled(initialisation, false);
void syringe_filled_placement_off()
    ESPUI.print(status_syringe_filled, "Enlevée");
    style (status_syringe_filled, 2);
    style (syringe_filled_placement, 2);

/*************OTHER_METHODS****************/

void select_syringe_maj(uint16_t tab)
{

    syringe_selection = ESPUI.addControl(ControlType::Select, "Choix de la seringue :", "", ControlColor::None, tab, syringe_selection_callback);

    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);


void style (uint16_t id, int style)
//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;

    }

}

Malaurie Bernard's avatar
Malaurie Bernard committed
void web_loop ()
  //bool switchi = syringe.isRunning();
  //bool a = syringe.isRunning();
    //ESPUI.updateSlider(slider, syringe_filled.current_position());
        if (syringe_filled.is_running())
        syringe_pump_on();
        else
        syringe_pump_off();
David Gauchard's avatar
David Gauchard committed
}