Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <lvgl.h>
- #include <Ticker.h>
- #include <TFT_eSPI.h>
- //#include "lv_test_theme_1.h"
- #define LVGL_TICK_PERIOD 60
- //const int relaisPin = 13;
- Ticker tick; /* timer for interrupt handler */
- TFT_eSPI tft = TFT_eSPI(); /* TFT instance */
- static lv_disp_buf_t disp_buf;
- static lv_color_t buf[LV_HOR_RES_MAX * 10];
- static void create_tab1(lv_obj_t * parent);
- static void create_tab2(lv_obj_t * parent);
- static void create_tab3(lv_obj_t * parent);
- lv_obj_t * slider_label;
- int screenWidth = 480;
- int screenHeight = 320;
- const int relaisPin = 13; //relais 3.3v dispaly + touch, bme,hx711
- const int relaisPin1 = 02; //relais gsm 4.1v
- const int relaisPin2 = 15; //relais 5v hx711
- #if USE_LV_LOG != 1
- /* Serial debugging */
- void my_print(lv_log_level_t level, const char * file, uint32_t line, const char * dsc)
- {
- Serial.printf("%s@%d->%s\r\n", file, line, dsc);
- delay(100);
- }
- #endif
- /* Display flushing */
- void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
- {
- uint16_t c;
- tft.startWrite(); /* Start new TFT transaction */
- tft.setAddrWindow(area->x1, area->y1, (area->x2 - area->x1 + 1), (area->y2 - area->y1 + 1)); /* set the working window */
- for (int y = area->y1; y <= area->y2; y++) {
- for (int x = area->x1; x <= area->x2; x++) {
- c = color_p->full;
- tft.writeColor(c, 1);
- color_p++;
- }
- }
- tft.endWrite(); /* terminate TFT transaction */
- lv_disp_flush_ready(disp); /* tell lvgl that flushing is done */
- }
- bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
- {
- uint16_t touchX, touchY;
- bool touched = tft.getTouch(&touchX, &touchY, 600);
- if(!touched)
- {
- return false;
- }
- if(touchX>screenWidth || touchY > screenHeight)
- {
- Serial.println("Y or y outside of expected parameters..");
- Serial.print("y:");
- Serial.print(touchX);
- Serial.print(" x:");
- Serial.print(touchY);
- }
- else
- {
- data->state = touched ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
- /*Save the state and save the pressed coordinate*/
- //if(data->state == LV_INDEV_STATE_PR) touchpad_get_xy(&last_x, &last_y);
- /*Set the coordinates (if released use the last pressed coordinates)*/
- data->point.x = touchX;
- data->point.y = touchY;
- Serial.print("Data x");
- Serial.println(touchX);
- Serial.print("Data y");
- Serial.println(touchY);
- }
- return false; /*Return `false` because we are not buffering and no more data to read*/
- }
- /* Interrupt driven periodic handler */
- static void lv_tick_handler(void)
- {
- lv_tick_inc(LVGL_TICK_PERIOD);
- }
- void setup() {
- pinMode (relaisPin, OUTPUT);
- digitalWrite (relaisPin, HIGH);
- delay(1000);
- pinMode (relaisPin2, OUTPUT);
- digitalWrite (relaisPin2, HIGH);
- delay(1000);
- pinMode (relaisPin1, OUTPUT);
- digitalWrite (relaisPin1, HIGH);
- delay(1000);
- pinMode (4, OUTPUT);
- digitalWrite (4, HIGH);
- ledcSetup(10, 5000/*freq*/, 10 /*resolution*/);
- ledcAttachPin(32, 10);
- analogReadResolution(10);
- ledcWrite(10,768);
- //const char test = '9' ;
- #define MAX_STRING_SIZE 5
- float test = 52.4;
- char test2[MAX_STRING_SIZE];
- snprintf(test2, MAX_STRING_SIZE, "%f", test);
- Serial.begin(115200); /* prepare for possible serial debug */
- lv_init();
- #if USE_LV_LOG != 0
- lv_log_register_print(my_print); /* register print function for debugging */
- #endif
- tft.begin(); /* TFT init */
- tft.setRotation(1);
- uint16_t calData[5] = { 275, 3620, 264, 3532, 1 };
- tft.setTouch(calData);
- lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10);
- /*Initialize the display*/
- lv_disp_drv_t disp_drv;
- lv_disp_drv_init(&disp_drv);
- disp_drv.hor_res = 320;
- disp_drv.ver_res = 240;
- disp_drv.flush_cb = my_disp_flush;
- disp_drv.buffer = &disp_buf;
- lv_disp_drv_register(&disp_drv);
- lv_indev_drv_t indev_drv;
- lv_indev_drv_init(&indev_drv); /*Descriptor of a input device driver*/
- indev_drv.type = LV_INDEV_TYPE_POINTER; /*Touch pad is a pointer-like device*/
- indev_drv.read_cb = my_touchpad_read; /*Set your driver function*/
- lv_indev_drv_register(&indev_drv); /*Finally register the driver*/
- /*Initialize the touch pad*/
- //lv_indev_drv_t indev_drv;
- //lv_indev_drv_init(&indev_drv);
- //indev_drv.type = LV_INDEV_TYPE_ENCODER;
- //indev_drv.read_cb = read_encoder;
- //lv_indev_drv_register(&indev_drv);
- /*Initialize the graphics library's tick*/
- tick.attach_ms(LVGL_TICK_PERIOD, lv_tick_handler);
- //Set the theme..
- lv_theme_t * th = lv_theme_material_init(210, NULL); //Set a HUE value and a Font for the Night Theme
- lv_theme_set_current(th);
- lv_obj_t * scr = lv_cont_create(NULL, NULL);
- lv_disp_load_scr(scr);
- /*Create a Tab view object*/
- lv_obj_t *tabview;
- tabview = lv_tabview_create(lv_scr_act(), NULL);
- /*Add 3 tabs (the tabs are page (lv_page) and can be scrolled*/
- lv_obj_t *tab1 = lv_tabview_add_tab(tabview, "Uebersicht");
- lv_obj_t *tab2 = lv_tabview_add_tab(tabview, "Visualisierung");
- lv_obj_t *tab3 = lv_tabview_add_tab(tabview, "Einstellungen");
- /*Create a normal cell style*/
- static lv_style_t style_cell1;
- lv_style_copy(&style_cell1, &lv_style_plain);
- style_cell1.body.border.width = 2;
- style_cell1.body.border.color = LV_COLOR_BLACK;
- /*Crealte a header cell style*/
- static lv_style_t style_cell2;
- lv_style_copy(&style_cell2, &lv_style_plain);
- style_cell2.body.border.width = 2;
- style_cell2.body.border.color = LV_COLOR_BLACK;
- style_cell2.body.main_color = LV_COLOR_SILVER;
- style_cell2.body.grad_color = LV_COLOR_SILVER;
- lv_obj_t * table = lv_table_create(tab1, NULL);
- lv_table_set_style(table, LV_TABLE_STYLE_CELL1, &style_cell1);
- lv_table_set_style(table, LV_TABLE_STYLE_CELL2, &style_cell2);
- lv_table_set_style(table, LV_TABLE_STYLE_BG, &lv_style_transp_tight);
- lv_table_set_col_cnt(table, 2);
- lv_table_set_row_cnt(table, 5);
- lv_obj_align(table, NULL, LV_ALIGN_CENTER, -18, 0);
- /*Make the cells of the first row center aligned */
- lv_table_set_cell_align(table, 0, 0, LV_LABEL_ALIGN_CENTER);
- lv_table_set_cell_align(table, 0, 1, LV_LABEL_ALIGN_CENTER);
- /*Make the cells of the first row TYPE = 2 (use `style_cell2`) */
- lv_table_set_cell_type(table, 0, 0, 2);
- lv_table_set_cell_type(table, 0, 1, 2);
- /*Fill the first column*/
- lv_table_set_cell_value(table, 0, 0, "Sensor");
- lv_table_set_cell_value(table, 1, 0, "Gewicht" );
- lv_table_set_cell_value(table, 2, 0, "Temperatur");
- lv_table_set_cell_value(table, 3, 0, "Luftfeuchtigkeit");
- lv_table_set_cell_value(table, 4, 0, "Luftdruck");
- /*Fill the second column*/
- lv_table_set_cell_value(table, 0, 1, "Wert");
- lv_table_set_cell_value(table, 1, 1, test2 );
- lv_table_set_cell_value(table, 2, 1, "0");
- lv_table_set_cell_value(table, 3, 1, "0");
- lv_table_set_cell_value(table, 4, 1, "0");
- //Width of cell
- lv_table_set_col_width(table, 0, 130);
- // Cell grows not with words
- lv_table_set_cell_crop(table, 3, 0, true);
- /*Add content to the tabs*/
- lv_obj_t * label = lv_label_create(tab1, NULL);
- lv_label_set_text(label, "");
- label = lv_label_create(tab2, NULL);
- lv_label_set_text(label, "");
- label = lv_label_create(tab3, NULL);
- lv_label_set_text(label, "");
- // lv_obj_t * label;
- lv_obj_t * btn1 = lv_btn_create(tab3, NULL);
- lv_obj_set_event_cb(btn1, event_handler);
- lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -40);
- label = lv_label_create(btn1, NULL);
- lv_label_set_text(label, "Deepsleep");
- lv_obj_t * btn2 = lv_btn_create(tab3, NULL);
- lv_obj_set_event_cb(btn2, event_handler);
- lv_obj_align(btn2, NULL, LV_ALIGN_CENTER, 0, 40);
- lv_btn_set_toggle(btn2, true);
- lv_btn_toggle(btn2);
- lv_btn_set_fit2(btn2, LV_FIT_NONE, LV_FIT_TIGHT);
- label = lv_label_create(btn2, NULL);
- lv_label_set_text(label, "Handy Nr.");
- lv_coord_t w = lv_page_get_scrl_width(tab2);
- lv_obj_t * chart = lv_chart_create(tab2, NULL);
- lv_chart_set_type(chart, LV_CHART_TYPE_AREA);
- lv_obj_set_size(chart, w / 1.5, lv_disp_get_ver_res(NULL) / 1.5);
- lv_obj_set_pos(chart, LV_DPI / 10, LV_DPI / 10);
- lv_chart_series_t * s1 = lv_chart_add_series(chart, LV_COLOR_RED);
- lv_chart_set_next(chart, s1, 30);
- lv_chart_set_next(chart, s1, 20);
- lv_chart_set_next(chart, s1, 10);
- lv_chart_set_next(chart, s1, 12);
- lv_chart_set_next(chart, s1, 20);
- lv_chart_set_next(chart, s1, 27);
- lv_chart_set_next(chart, s1, 35);
- lv_chart_set_next(chart, s1, 55);
- lv_chart_set_next(chart, s1, 70);
- lv_chart_set_next(chart, s1, test);
- }
- void loop() {
- lv_task_handler(); /* let the GUI do its work */
- delay(5);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement