#include <Arduino.h>
#include <WiFi.h>
#include <U8g2lib.h>
#include <MUIU8g2.h>
#include <Wire.h>
#include "fonts.h"
#include "graphics.h"
#define BTN1 17
#define BTN2 18
#define BTN3 19
#include "GyverButton.h"
GButton butt1(BTN1);
GButton butt2(BTN2);
GButton butt3(BTN3);
// Адрес 0x3C
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
MUIU8G2 mui;
uint8_t num_value = 0;
uint8_t bar_value = 0;
uint16_t sensor_idx = 0;
const char *sensors[] = { "DHT11", "DHT21", "DHT22", };
//const uint8_t *adress[] = {0x78, 0x2c, 0x3c };
uint16_t sensor_name_list_get_cnt(void *data) {
return sizeof(sensors)/sizeof(*sensors); /* number of sensors */
}
const char *sensor_name_list_get_str(void *data, uint16_t index) {
return sensors[index];
}
uint8_t mui_hrule(mui_t *ui, uint8_t msg) {
if ( msg == MUIF_MSG_DRAW ) {
u8g2.drawHLine(0, mui_get_y(ui), u8g2.getDisplayWidth());
}
return 0;
}
uint8_t show_my_data(mui_t *ui, uint8_t msg) {
if ( msg == MUIF_MSG_DRAW ) {
u8g2_uint_t x = mui_get_x(ui);
u8g2_uint_t y = mui_get_y(ui);
u8g2.setCursor(x+5, y);
u8g2.print("Num:");
u8g2.setCursor(x+50, y);
u8g2.print(num_value);
u8g2.setCursor(x+5, y+12);
u8g2.print("Bar:");
u8g2.setCursor(x+50, y+12);
u8g2.print(bar_value);
u8g2.setCursor(x+5, y+24);
u8g2.print("Sensor:");
u8g2.setCursor(x+50, y+24);
u8g2.print(sensor_idx);
u8g2.print("=");
u8g2.print(sensors[sensor_idx]);
}
return 0;
}
muif_t muif_list[] = {
MUIF_U8G2_FONT_STYLE(0, max_font), /* regular font */
MUIF_U8G2_FONT_STYLE(1, max_font), /* bold font */
MUIF_RO("HR", mui_hrule),
MUIF_U8G2_LABEL(),
MUIF_RO("GP",mui_u8g2_goto_data),
MUIF_BUTTON("GC", mui_u8g2_goto_form_w1_pi),
MUIF_U8G2_U8_MIN_MAX("NV", &num_value, 0, 99, mui_u8g2_u8_min_max_wm_mud_pf),
MUIF_U8G2_U8_MIN_MAX_STEP("NB", &bar_value, 0, 16, 1, MUI_MMS_2X_BAR, mui_u8g2_u8_bar_wm_mud_pf),
MUIF_U8G2_U16_LIST("NA", &sensor_idx, NULL, sensor_name_list_get_str, sensor_name_list_get_cnt, mui_u8g2_u16_list_line_wa_mud_pi),
/* register custom function to show the data */
MUIF_RO("SH", show_my_data),
/* a button for the menu... */
//MUIF_BUTTON("GO", mui_u8g2_btn_goto_wm_fi)
MUIF_EXECUTE_ON_SELECT_BUTTON("GO", mui_u8g2_btn_goto_wm_fi)
};
fds_t fds_data[] =
MUI_FORM(1)
MUI_STYLE(1)
MUI_LABEL(5, 8, "Настройки")
MUI_STYLE(0)
MUI_XY("HR", 0,11)
MUI_DATA("GP",
MUI_100 "Насторить|"
MUI_90 "Смотреть настройки|"
MUI_80 "Еще пункт")
MUI_XYA("GC", 5, 24, 0)
MUI_XYA("GC", 5, 36, 1)
MUI_XYA("GC", 5, 48, 2)
MUI_FORM(2)
MUI_STYLE(1)
MUI_LABEL(5, 8, "Ввод параметров")
MUI_XY("HR", 0,11)
MUI_STYLE(0)
MUI_LABEL(5,23, "Номер:")
MUI_LABEL(5,36, "Шкала:")
MUI_LABEL(5,49, "Сенсор:")
MUI_XY("NV", 50, 23)
MUI_XY("NB", 50, 36)
MUI_XYA("NA", 50, 49, 44)
MUI_XYAT("GO", 114, 60, 1, " Ok ")
MUI_FORM(3)
MUI_STYLE(1)
MUI_LABEL(5, 8, "Значения параметров")
MUI_XY("HR", 0,11)
MUI_STYLE(0)
MUI_XY("SH", 0, 23)
MUI_XYAT("GO", 114, 60, 1, " Ok ")
MUI_FORM(4)
MUI_STYLE(1)
MUI_LABEL(5, 8, "Пример вложения")
MUI_XY("HR", 0,11)
MUI_STYLE(0)
MUI_XYAT("GO", 114, 60, 1, " Ok ")
;
// global variables for menu redraw and input event handling
uint8_t is_redraw = 1;
uint8_t up_event = 0; // 0 = not click, 1 = 1btn UP, 2 = 3btn DOWN
uint8_t down_event = 0;
uint8_t press_event = 0; // 0 = not pushed OK, 1 = pushed OK
uint8_t long_press_event = 0; // 0 = not pushed OK, 1 = pushed OK
void handle_events(void) {
// 0 = not pushed, 1 = pushed
if ( press_event == 1 ) {
mui.sendSelect();
is_redraw = 1;
press_event = 0;
}
// 0 = not pushed, 1 = pushed
if ( long_press_event == 1 ) {
mui.sendSelectWithExecuteOnSelectFieldSearch();
is_redraw = 1;
long_press_event = 0;
}
// 0 = not turning, 1 = CW, 2 = CCW
if ( up_event == 1 ) {
mui.nextField();
is_redraw = 1;
up_event = 0;
}
if ( down_event == 1 ) {
mui.prevField();
is_redraw = 1;
down_event = 0;
}
}
void setup(void) {
butt1.setTickMode(AUTO);
butt2.setTickMode(AUTO);
butt3.setTickMode(AUTO);
u8g2.begin();
u8g2.enableUTF8Print(); // enable UTF8 support for the Arduino print() function
u8g2.setFontDirection(0);
mui.begin(u8g2, fds_data, muif_list, sizeof(muif_list)/sizeof(muif_t));
mui.gotoForm(/* form_id= */ 1, /* initial_cursor_position= */ 0);
}
void loop(void) {
if (butt1.isClick()) up_event = 1;
if (butt2.isClick()) press_event = 1;
if (butt3.isClick()) down_event = 1;
if (butt2.isHolded()) long_press_event = 1;
if ( mui.isFormActive() ) {
if ( is_redraw ) {
u8g2.firstPage();
do {
//draw_main_scr();
mui.draw();
} while ( u8g2.nextPage() );
is_redraw = 0;
}
handle_events();
} else {
mui.gotoForm(/* form_id= */ 1, /* initial_cursor_position= */ 0);
}
delay(10);
}
void draw_main_scr(void)
{
u8g2.setCursor(2, 16);
u8g2.setFont(u8g2_font_profont22_tr);
//u8g2.setFont(u8g_font_helvR18n);
u8g2.print("15:37:54");
u8g2.setFont(max_font);
u8g2.setCursor( 2, 26);
u8g2.print("07 Окт 2024 Пн");
u8g2.drawXBMP(5, 29, term_width, term_height, term);
u8g2.drawXBMP(5, 47, hum_width, hum_height, hum);
u8g2.drawXBMP(53, 29, wind_width, wind_height, wind);
u8g2.drawXBMP(53, 47, windsock_width, windsock_height, windsock);
u8g2.drawXBMP(105, 29, weather_width, weather_height, weather_semisun);
u8g2.drawXBMP(111, 1, net_width, net_height, net_x);
}