Julien VILLEMEJANE / Mbed 2 deprecated PIMS_VisionIndus_IHM

Dependencies:   F746_GUI_vV mbed Vision_Indus_IHM

Revision:
26:9f98a43d4098
Parent:
25:586781d009dd
Child:
27:3ac3f6c77c88
--- a/main.cpp	Mon Mar 19 04:21:00 2018 +0000
+++ b/main.cpp	Sat Oct 30 09:22:12 2021 +0000
@@ -1,137 +1,213 @@
 //-----------------------------------------------------------------------
-//  GuiBase とその派生クラスのデモプログラム
-//  Demo program for GuiBase class and its derivertive classes
-//
-//      GuiBase, Button, ButtonGroup, Label, NumericLabel, BlinkLabel,
-//      SeekBar, SeekbarGroup, NumericUpDown
-//
-//      <インポートしたライブラリのリビジョン>
-//          F746_GUI     33
-//          mbed        161
-//
+//  
+//  GUI library from :
 //  2018/03/12, Copyright (c) 2018 MIKAMI, Naoki
 //-----------------------------------------------------------------------
 
 #include "F746_GUI.hpp"
 
+// Color ARGB (8-8-8-8)
+#define     COLOR_OFF       0xFF666666
+
+/* Graphical objects */
+Label       title(240, 2, "Vision Industrielle", Label::CENTER, Font24);
+Label       subtitle(240, 25, "LEnsE / 2021", Label::CENTER, Font16);
+// All On-Off
+Button      light_on(250, 65, 80, 40, "ALL ON");
+Button      light_off(340, 65, 80, 40, "ALL OFF");
+uint8_t     all_on_active;
+// EFFI-Ring
+Label       roundRGB(10, 50, "EFFI-Ring RGB", Label::LEFT);
+Button      roundRGB_R(10, 65, 50, 40, "RED");
+Button      roundRGB_G(70, 65, 50, 40, "GREEN");
+Button      roundRGB_B(130, 65, 50, 40, "BLUE");
+uint8_t     roundRGB_R_active;
+uint8_t     roundRGB_G_active;
+uint8_t     roundRGB_B_active;
+// EFFI-Dome
+Label       dome(10, 115, "EFFI-Dome W", Label::LEFT);
+Button      dome_W(10, 130, 80, 40, "Dome");
+uint8_t     dome_active;
+// EFFI-Dome
+Label       rasant(100, 115, "EFFI-Rlla R", Label::LEFT);
+Button      rasant_R(100, 130, 80, 40, "Rasant");
+uint8_t     rasant_active;
+// EFFI-Flex
+Label       flex1(10, 180, "EFFI-Flex W", Label::LEFT);
+Button      flex1_W(10, 195, 80, 40, "Flex1");
+uint8_t     flex1_active;
+Button      flex2_W(100, 195, 80, 40, "Flex2");
+uint8_t     flex2_active;
+// Conveyor
+Label               conveyor(250, 200, "Convoyeur / Vitesse", Label::LEFT);
+NumericLabel<int>   conv_speed_lab(400, 200, "V = ", Label::LEFT);
+SeekBar             conv_speed(250, 250, 150, 0, 100, 0, "0", "", "100%");
+
+/* initIHM */
+void initIHM(void){
+    all_on_active = 0;            
+    light_off.Draw(0xFFFFFFFF, 0xFF000000);
+    light_on.Draw(COLOR_OFF, 0xFFFFFFFF);
+    /* EFFI-Ring */
+    roundRGB_R_active = 0;
+    roundRGB_R.Draw(COLOR_OFF);
+    roundRGB_G_active = 0;
+    roundRGB_G.Draw(COLOR_OFF);
+    roundRGB_B_active = 0;
+    roundRGB_B.Draw(COLOR_OFF);
+    /* EFFI-Dome */
+    dome_active = 0;
+    dome_W.Draw(COLOR_OFF);
+    /* EFFI-Rlla */
+    rasant_active = 0;
+    rasant_R.Draw(COLOR_OFF);
+    /* EFFI-Flex */
+    flex1_active = 0;
+    flex1_W.Draw(COLOR_OFF);
+    flex2_active = 0;
+    flex2_W.Draw(COLOR_OFF);
+    /* Conveyor */
+    int8_t x = (int8_t)conv_speed.GetValue();
+    conv_speed_lab.Draw("%3d m/s", x);   
+}    
+
+/* updateIHM */
+void updateIHM(void){
+    if (light_on.Touched()){
+        all_on_active = 1;
+    }
+    if(all_on_active == 1){
+        light_off.Draw(COLOR_OFF, 0xFFFFFFFF);
+        light_on.Draw(0xFFFFFFFF, 0xFF000000);
+
+        roundRGB_R_active = 1;
+        roundRGB_R.Draw(0xFFFF0000);
+        roundRGB_G_active = 1;
+        roundRGB_G.Draw(0xFF33DD33, 0xFF000000);
+        roundRGB_B_active = 1;
+        roundRGB_B.Draw(0xFF0000FF);
+        
+        dome_active = 1;
+        dome_W.Draw(0xFFFFFFFF, 0xFF000000);
+        
+        rasant_active = 1;
+        rasant_R.Draw(0xFFFF0000);
+
+        flex1_active = 1;
+        flex1_W.Draw(0xFFEEEEEE, 0xFF000000);
+        flex2_active = 1;
+        flex2_W.Draw(0xFFEEEEEE, 0xFF000000);
+                              
+        all_on_active = 0;
+    }
+    else{
+        light_off.Draw(0xFFFFFFFF, 0xFF000000);
+        light_on.Draw(COLOR_OFF, 0xFFFFFFFF);
+        if (light_off.Touched()){
+            all_on_active = 0;
+            light_off.Draw(0xFFFFFFFF, 0xFF000000);
+            light_on.Draw(COLOR_OFF, 0xFFFFFFFF);
+        }  
+        if (roundRGB_R.Touched()){
+            if(roundRGB_R_active){
+                roundRGB_R_active = 0;
+                all_on_active = 0;
+                roundRGB_R.Draw(COLOR_OFF);
+            }
+            else{
+                roundRGB_R_active = 1;
+                roundRGB_R.Draw(0xFFFF0000);
+            }
+            
+        }
+        if (roundRGB_G.Touched()){
+            if(roundRGB_G_active){
+                roundRGB_G_active = 0;
+                all_on_active = 0;
+                roundRGB_G.Draw(COLOR_OFF, 0xFFFFFFFF);
+            }
+            else{
+                roundRGB_G_active = 1;
+                roundRGB_G.Draw(0xFF33DD33, 0xFF000000);
+            }
+            
+        }
+        if (roundRGB_B.Touched()){
+            if(roundRGB_B_active){
+                roundRGB_B_active = 0;
+                all_on_active = 0;
+                roundRGB_B.Draw(COLOR_OFF);
+            }
+            else{
+                roundRGB_B_active = 1;
+                roundRGB_B.Draw(0xFF0000FF);
+            }
+            
+        }
+        if (dome_W.Touched()){
+            if(dome_active){
+                dome_active = 0;
+                all_on_active = 0;
+                dome_W.Draw(COLOR_OFF, 0xFFFFFFFF);
+            }
+            else{
+                dome_active = 1;
+                dome_W.Draw(0xFFFFFFFF, 0xFF000000);
+            }
+        }  
+        if (rasant_R.Touched()){
+            if(rasant_active){
+                rasant_active = 0;
+                all_on_active = 0;
+                rasant_R.Draw(COLOR_OFF);
+            }
+            else{
+                rasant_active = 1;
+                rasant_R.Draw(0xFFFF0000);
+            }
+        }     
+        if (flex1_W.Touched()){
+            if(flex1_active){
+                flex1_active = 0;
+                all_on_active = 0;
+                flex1_W.Draw(COLOR_OFF, 0xFFFFFFFF);
+            }
+            else{
+                flex1_active = 1;
+                flex1_W.Draw(0xFFEEEEEE, 0xFF000000);
+            }
+        }   
+        
+        if (flex2_W.Touched()){
+            if(flex2_active){
+                flex2_active = 0;
+                all_on_active = 0;
+                flex2_W.Draw(COLOR_OFF, 0xFFFFFFFF);
+            }
+            else{
+                flex2_active = 1;
+                flex2_W.Draw(0xFFEEEEEE, 0xFF000000);
+            }
+        } 
+    }  
+    if (conv_speed.Slide())
+    {
+        int8_t x = (int8_t)conv_speed.GetValue();
+        conv_speed_lab.Draw("%3d", x);          
+    }
+
+} 
+
+/* Main Program */
 int main()
 {
-    Label obj10(240, 2, "Demo: GUI parts, 2018/03/12", Label::CENTER, Font16);
-    Label obj11(240, 20, "Button, ButtonGroup, Label, NumericLabel, BlinkLabel,",
-                Label::CENTER);
-    Label obj12(240, 32, "SeekBar, SeekbarGroup, NumericUpDown",
-                Label::CENTER);
-
-    Button button1(10, 54, 30, 35, "1");
-    Button button2(42, 54, 30, 35, "2");
-
-    const int NUMBER_BUTTONS = 4;
-    const string STR1[NUMBER_BUTTONS] = {"Button1", "Button2", "Button3", "Activate"};
-    ButtonGroup bGroup1(168, 54, 66, 35,  NUMBER_BUTTONS, STR1, 2, 2, 3, 1,
-                        Font12, LCD_COLOR_WHITE, 0xFF003538, 0xFFB70068, 0xFFFF7FFF);
-    NumericLabel<int> bTouch(240, 112, "", Label::LEFT, Font12, LCD_COLOR_MAGENTA);
-
-    // Control status of bGroup2
-    ButtonGroup bGroup2(168, 150, 66, 40,  3, (string[]){"0", "1", "2"}, 5, 5, 3);
-    bGroup2.InactivateAll();
-    
-    // Switching buttons to control barH active or inactive
-    ButtonGroup bGroup3(78, 54, 40, 35,  2, (string[]){"ON", "OFF"}, 0, 0, 2);
-    bGroup3.TouchedColor(0);
-
-    Button doNotTouch(250, 220, 120, 40, "Don't Touch", Font12,
-                      GuiBase::ENUM_TEXT, GuiBase::ENUM_BACK,
-                      LCD_COLOR_DARKGREEN, LCD_COLOR_RED);
-
-    // Using default value for argument (Horizontal)
-    SeekBar barH(20, 250, 200, -5, 5, 0, "-5", "", "5");
-    NumericLabel<float> numLabel1(80, 205, "%5.1f", barH.GetValue());
-    NumericLabel<int> numLabel2(130, 205, "%3d", (int)barH.GetValue());
-    NumericLabel<int> numLabel3(160, 205, "%3d");
-    
-    // SeekbarGroup (vertical)
-    SeekbarGroup barV(410, 130, 121, 2, 45, -6, 6, 2,
-                      SeekBar::Vertical, 0xFFA0FFC0);
-
-    Array<NumericLabel<float> *> numLabel4(2);
-    for (int n=0; n<2; n++) numLabel4[n] =
-        new NumericLabel<float>(410+n*45, 104, "%4.1f", barV.GetValue(n), Label::CENTER);
-
-    NumericLabel<int> numLabel5(455, 92, "%1d", barV.GetIntValue(0), Label::CENTER);
-
-    // Test of left-, cenrer-, and right-justified
-    Label leftJustified(420, 54, "ABC", Label::LEFT);
-    Label centerJustified(420, 64, "ABC", Label::CENTER);
-    Label rightJustified1(420, 74, "ABC", Label::RIGHT);
-    
-    // NumericalUpDown
-    NumericUpDown nUd(3, 10, 190, 100, 999, 10);
+    initIHM();
 
     while (true)
     {
-        if (button1.Touched()) button2.Draw();
-        if (button2.Touched()) button1.Draw();
-
-        int num;
-        if (bGroup1.GetTouchedNumber(num))
-            bTouch.Draw("Button%d touched", num+1);
-        if (num == 3)
-            bGroup2.ActivateAll();
-
-        if (bGroup2.GetTouchedNumber(num))
-        switch (num)
-        {
-            case 0: button1.Activate();
-                    bGroup1.Activate(1);
-                    bGroup1.DrawAll();
-                    break;
-            case 1: button1.Inactivate();
-                    bGroup1.Inactivate(1);
-                    break;
-            case 2: bGroup1.EraseAll();//for (int n=0; n<4; n++) bGroup1.Erase(n);
-                    for (int n=0; n<2; n++)
-                    {
-                        barV.Draw(n, 0);    // reset seekbar
-                        numLabel4[n]->Draw("%4.1f", barV.GetValue(n));
-                    }
-                    break;
-        }
+        updateIHM();
 
-        if (barH.Slide())
-        {
-            numLabel1.Draw("%5.1f", barH.GetValue());
-            int8_t x = (int8_t)barH.GetValue();
-            numLabel2.Draw("%3d", x);
-
-            numLabel3.Draw(barH.GetIntValue());            
-        }        
-
-        int sbNum;
-        if (barV.GetSlidedNumber(sbNum))
-        {
-            if (sbNum == 0) numLabel4[sbNum]->Draw("%4.1f", barV.GetValue(sbNum));
-            else            numLabel4[sbNum]->Draw("%4.1f", barV.GetValue(sbNum));
-            if (sbNum == 1) numLabel5.Draw("%1d", barV.GetIntValue(sbNum));
-        }
-        // If "doNotTouch" button touched, trapped into endless loop
-        if (doNotTouch.Touched())
-            BlinkLabel warning(250, 200, "You must reset", Label::LEFT, Font16);
-            
-        // SeekBar active inactive switching
-        if (bGroup3.Touched(0))
-        {
-            barH.Activate();
-            barV.ActivateAll();
-        }
-        if (bGroup3.Touched(1))
-        {
-            barH.Inactivate();
-            barV.InactivateAll();
-        }
-        
-        if (nUd.Touched()) {}   // Example of NumericalUpDown
-
-        wait(0.02f);
+        wait(0.05f);
     }
 }