FINAL VERSION

Dependencies:   BSP_DISCO_F746NG

Files at this revision

API Documentation at this revision

Comitter:
samdcr
Date:
Thu Jun 16 09:08:19 2022 +0000
Parent:
5:071136c3eefa
Commit message:
FINAL VERSION

Changed in this revision

lv_conf.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/lv_conf.h	Tue Jun 15 19:35:57 2021 +0000
+++ b/lv_conf.h	Thu Jun 16 09:08:19 2022 +0000
@@ -34,6 +34,9 @@
 /*Images pixels with this color will not be drawn if they are  chroma keyed)*/
 #define LV_COLOR_CHROMA_KEY    lv_color_hex(0x00ff00)         /*pure green*/
 
+#define LV_COLOR_RED 0xFF0000
+#define LV_COLOR_GREEN 0x00FF00
+
 /*=========================
    MEMORY SETTINGS
  *=========================*/
@@ -202,7 +205,7 @@
 #  define lv_snprintf     snprintf
 #  define lv_vsnprintf    vsnprintf
 #else   /*LV_SPRINTF_CUSTOM*/
-#  define LV_SPRINTF_USE_FLOAT 0
+#  define LV_SPRINTF_USE_FLOAT 1
 #endif  /*LV_SPRINTF_CUSTOM*/
 
 #define LV_USE_USER_DATA      1
--- a/main.cpp	Tue Jun 15 19:35:57 2021 +0000
+++ b/main.cpp	Thu Jun 16 09:08:19 2022 +0000
@@ -7,11 +7,23 @@
 #include "hal_stm_lvgl/tft/tft.h"
 #include "hal_stm_lvgl/touchpad/touchpad.h" 
 #include "lv_demo.h"    /*Comment/uncomment will switch between LVGL demo and Hello word example*/
+#include <iostream>
+#include <string>
 
 #define LVGL_TICK   10                               //Time tick value for lvgl in ms (1-10msa)
 #define TICKER_TIME 10ms                             //modified to miliseconds
 
 Ticker ticker;                                       //Ticker for lvgl                    
+float soilHumidity = 0.0;
+float soilPH = 0.0;
+float waterPH = 0.0;
+
+AnalogIn   ain(A0);
+AnalogIn   deux(A1);
+AnalogIn   trois(A2);
+
+lv_obj_t * scr1;
+lv_obj_t * scr2; 
  
 /*
  * Callback function for lvgl timing.
@@ -22,18 +34,27 @@
     lv_tick_inc(LVGL_TICK); 
 }
 
-#ifndef LV_DEMO_H
 static void event_handler(lv_event_t* event)
 {
     lv_event_code_t code = lv_event_get_code(event);
     if(code == LV_EVENT_CLICKED) {
+    //soilHumidity++;
+    soilPH++;
+    waterPH++;
         printf("Clicked\n");
+        lv_scr_load(scr2);
     }
     else if(code == LV_EVENT_VALUE_CHANGED) {
         printf("Toggled\n");
     }
 }
-#endif
+
+static void my_event_cb(lv_event_t * event)
+{
+    printf("Clicked\n");
+    lv_scr_load(scr1);
+}
+
 // main() runs in its own thread in the OS
 int main()
 {
@@ -42,43 +63,139 @@
     tft_init();                                             //Initialize diplay 
     touchpad_init();                                        //Initialize touchpad
     ticker.attach(callback(&lv_ticker_func),TICKER_TIME);   //Attach callback to ticker
-
-#ifdef LV_DEMO_H
-    printf("Demo\n"); 
-    lv_demo_widgets();
-#else
-    printf("Hello world\n");
-    lv_obj_t * label1 = lv_label_create(lv_scr_act());
-    lv_label_set_long_mode(label1, LV_LABEL_LONG_WRAP);     /*Break the long lines*/
-    lv_label_set_recolor(label1, true);                      /*Enable re-coloring by commands in the text*/
-    lv_label_set_text(label1, "#0000ff Hello# #ff00ff world# #ff0000 - the LVGL and MbedOS#");
-    lv_obj_set_width(label1, 150);
-    lv_obj_align(label1, LV_ALIGN_TOP_MID, 0, 20);
-
-    lv_obj_t * label2 = lv_label_create(lv_scr_act());
-    lv_label_set_long_mode(label2, LV_LABEL_LONG_SCROLL_CIRCULAR);     /*Circular scroll*/
-    lv_obj_set_width(label2, 150);
-    lv_label_set_text(label2, "It is a circularly scrolling text. ");
-    lv_obj_align(label2, LV_ALIGN_BOTTOM_MID, 0, 0);
+    
+    
+    scr1 = lv_obj_create(NULL);
+    scr2 = lv_obj_create(NULL);
+    
+    lv_scr_load(scr1);
+    
+    LV_IMG_DECLARE(myplant);
+    lv_obj_t * imgplant = lv_img_create(scr1);
+    lv_img_set_src(imgplant, &myplant);
+    lv_obj_align(imgplant, LV_ALIGN_TOP_LEFT, 0,0);
+    lv_obj_set_size(imgplant, 480, 85);
+    
+    LV_IMG_DECLARE(showdata);
+    lv_obj_t * mydata = lv_img_create(scr2);
+    lv_img_set_src(mydata, &showdata);
+    lv_obj_align(mydata, LV_ALIGN_TOP_LEFT, 0,0);
+    lv_obj_set_size(mydata, 480, 85);
     
     lv_obj_t * label;
-    lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
+    lv_obj_t * btn1 = lv_btn_create(scr1);
     lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL);
-    lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -25);
+    lv_obj_align(btn1, LV_ALIGN_TOP_LEFT, 20, 180);
+    lv_obj_set_size(btn1, 200, 80);
     label = lv_label_create(btn1);
-    lv_label_set_text(label, "Button");
-    lv_obj_t * btn2 = lv_btn_create(lv_scr_act());
-    lv_obj_add_event_cb(btn2, event_handler,LV_EVENT_ALL, NULL);
-    lv_obj_align(btn2, LV_ALIGN_CENTER, 0, 25);
-    lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
-    label = lv_label_create(btn2);
-    lv_label_set_text(label, "Toggled");
-#endif
+    lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
+    lv_label_set_text(label, "Vue detaillee");
+    
+    
+    
+    lv_obj_t * label1;
+    lv_obj_t * btn2 = lv_btn_create(scr2);
+    lv_obj_add_event_cb(btn2, my_event_cb, LV_EVENT_CLICKED, NULL);
+    lv_obj_align(btn2, LV_ALIGN_TOP_LEFT, 20, 90);
+    lv_obj_set_size(btn2, 120, 80);
+    label1 = lv_label_create(btn2);
+    lv_obj_align(label1, LV_ALIGN_CENTER, 0, 0);
+    lv_label_set_text(label1, "Retour");
+    
+    static lv_style_t style;
+    lv_style_init(&style);
+    lv_style_set_radius(&style, 5);
+
+    /*Make a gradient*/
+    lv_style_set_width(&style, 210);
+    lv_style_set_height(&style, 125);
+
+    lv_style_set_pad_ver(&style, 20);
+    lv_style_set_pad_left(&style, 5);
+
+    lv_style_set_x(&style, lv_pct(50));
+    lv_style_set_y(&style, 100);
+
+    /*Create an object with the new style*/
+    lv_obj_t * obj = lv_obj_create(lv_scr_act());
+    lv_obj_add_style(obj, &style, 0);
+
+    lv_obj_t * label22 = lv_label_create(obj);
+    
+    static lv_style_t style1;
+    lv_style_init(&style1);
+    lv_style_set_radius(&style1, 5);
+
+    /*Make a gradient*/
+    lv_style_set_width(&style1, 125);
+    lv_style_set_height(&style1, 80);
+
+    lv_style_set_pad_ver(&style1, 20);
+    lv_style_set_pad_left(&style1, 5);
+
+    lv_style_set_x(&style1, lv_pct(12));
+    lv_style_set_y(&style1, 92);
+
+    /*Create an object with the new style*/
+    lv_obj_t * obj2 = lv_obj_create(lv_scr_act());
+    lv_obj_add_style(obj2, &style1, 0);
+
+    lv_obj_t * label23 = lv_label_create(obj2);
+    
+    lv_obj_t * chart;
+    chart = lv_chart_create(scr2);
+    lv_obj_set_size(chart, 200, 150);
+    lv_obj_align(chart, LV_ALIGN_CENTER, 20, 40);
+    lv_chart_set_type(chart, LV_CHART_TYPE_LINE);
+    lv_chart_set_update_mode(chart, LV_CHART_UPDATE_MODE_SHIFT);
+    lv_chart_set_point_count(chart, 100);
+    lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, 0, 14);
+    
+    lv_chart_series_t * ser1 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_BLUE), LV_CHART_AXIS_PRIMARY_X);
+    lv_chart_series_t * ser2 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_GREEN), LV_CHART_AXIS_PRIMARY_X);
+    //lv_chart_series_t * ser3 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_BLUE), LV_CHART_AXIS_PRIMARY_X);
+    
+    lv_obj_t * label31 = lv_label_create(scr2);
+    lv_obj_set_width(label31, 300);
+    lv_label_set_recolor(label31, true);
+    lv_obj_align(label31, LV_ALIGN_CENTER, 285, 40);
+    
+    lv_obj_t * label32 = lv_label_create(scr2);
+    lv_obj_set_width(label32, 300);
+    lv_label_set_recolor(label32, true);
+    lv_obj_align(label32, LV_ALIGN_CENTER, 285, 60);
 
     while (true){
-        lv_task_handler(); 
+        lv_task_handler();
         //Call lv_task_handler() periodically every few milliseconds. 
         //It will redraw the screen if required, handle input devices etc.
+        waterPH = ain * 10;
+        soilPH = deux * 10;
+        soilHumidity = trois * 1000;
+        lv_label_set_text_fmt(label22, "pH de l'eau :              %0.1f \n\npH du sol :                 %0.1f\n\nHumidite du sol :     %0.1f", waterPH, soilPH, soilHumidity);
+        
+        if((soilHumidity > 500 && soilPH > 7)){
+                lv_label_set_text(label23, "Aroser : OUI \npH : ALCALIN");
+            }
+        else if((soilHumidity > 500 && soilPH < 7)){
+                lv_label_set_text(label23, "Aroser : OUI \npH : ACIDE OK");
+        }
+        else if((soilHumidity < 500 && soilPH < 7)){
+                lv_label_set_text(label23, "Aroser : NON \npH : ACIDE OK");
+        }
+        else if((soilHumidity < 500 && soilPH > 7)){
+                lv_label_set_text(label23, "Aroser : NON \npH : ALCALIN");
+        }
+    
+        //lv_chart_set_next_value(chart, ser1, soilHumidity);
+        lv_chart_set_next_value(chart, ser1, soilPH);
+        lv_chart_set_next_value(chart, ser2, waterPH);
+        
+        lv_label_set_text_fmt(label31, "#0000ff phEAU : %0.1f#", waterPH);
+        lv_label_set_text_fmt(label32, "#00ff00 phSOL : %0.1f#", soilPH);
+        
+        
+        
         thread_sleep_for(LVGL_TICK); 
     }
 }
\ No newline at end of file