//#include #include #include #include #include // #define ESP32 0 // #define MEGA2560 1 // #define MCU 1 #define SPEED 4//16的因数 #define ICON_SPEED 12 #define ICON_SPACE 48//图标间隔,speed倍数 // #define READ A0 // #define BTN0 5 // #define BTN1 6 // #define BTN2 7 #define READ 2 #define BTN0 27 //上 #define BTN1 25 //下 #define BTN2 26 //确认 const char* ssid = "WFxue"; const char* password = "xue3344520"; char date[20]; char time_n[20]; const char *ntpServer = "ntp.aliyun.com"; const long gmtOffset_sec = 8*3600; const int daylightOffset_sec = 0; U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* clock=*/ 22, /* data=*/ 21); // ESP32 Thing, pure SW emulated I2C PROGMEM const uint8_t icon_pic[][200] { { 0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00, 0x00,0x02,0x04,0x00,0x00,0x00,0x03,0x0C, 0x00,0x00,0x80,0x03,0x1C,0x00,0x07,0xC0, 0x03,0x7C,0x80,0x1F,0xE0,0x03,0xFE,0xFF, 0xFF,0xFF,0x03,0xFE,0xFF,0xFF,0xFF,0x03, 0xFE,0xFF,0xFF,0xFF,0x03,0xFE,0xFF,0xFF, 0xFF,0x03,0xFE,0xFF,0xFF,0xFF,0x03,0xFE, 0xFF,0xFF,0xFF,0x03,0xFC,0xFF,0xFF,0xFF, 0x03,0xFC,0xFF,0xFF,0xFF,0x03,0xFC,0xFF, 0xFF,0xFF,0x03,0xFC,0xFF,0xFF,0xFF,0x03, 0xFC,0xFF,0xFF,0xFF,0x01,0xFC,0xFF,0xFF, 0xFF,0x01,0xF8,0xFF,0xFF,0xFF,0x01,0xF8, 0xFF,0xFF,0xFF,0x01,0xF8,0xFF,0xFF,0xFF, 0x00,0xF0,0xFF,0xFF,0xFF,0x00,0xF0,0xFF, 0xFF,0x7F,0x00,0xE0,0xFF,0xFF,0x7F,0x00, 0xE0,0xFF,0xFF,0x3F,0x00,0xC0,0xFF,0xFF, 0x3F,0x00,0x80,0xFF,0xFF,0x1F,0x00,0x80, 0xFF,0xFF,0x0F,0x00,0x00,0xFF,0xFF,0x07, 0x00,0x00,0xFE,0xFF,0x03,0x00,0x00,0xF8, 0xFF,0x01,0x00,0x00,0xF0,0x7F,0x00,0x00, 0x00,0xC0,0x1F,0x00,0x00,0x00,0x00,0x07, 0x00,0x00,0x00,0x00,0x00,0x00,0x00 /*"C:\Users\ROG\Desktop\三连\点赞.bmp",0*//* (36 X 35 )*/ }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x80, 0x1F, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0xC0, 0x3F, 0x00, 0x00, 0x00, 0xC0, 0x3F, 0x00, 0x00, 0x00, 0xC0, 0x7F, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x01, 0x00, 0x00, 0xFC, 0xFF, 0x03, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0x07, 0xFE, 0xFF, 0xFF, 0xFF, 0x07, 0xFC, 0xFF, 0xFF, 0xFF, 0x07, 0xFC, 0xFF, 0xFF, 0xFF, 0x03, 0xF8, 0xFF, 0xFF, 0xFF, 0x01, 0xF0, 0xFF, 0xFF, 0xFF, 0x00, 0xE0, 0xFF, 0xFF, 0x7F, 0x00, 0xC0, 0xFF, 0xFF, 0x3F, 0x00, 0x80, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0xFF, 0xFF, 0x1F, 0x00, 0x80, 0xFF, 0xF0, 0x1F, 0x00, 0x80, 0x3F, 0xC0, 0x1F, 0x00, 0x80, 0x1F, 0x00, 0x1F, 0x00, 0x00, 0x07, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00/*"C:\Users\ROG\Desktop\三连\收藏.bmp",0*/ /* (36 X 37 )*/ }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18, 0x00,0x00,0x00,0x00,0x1C,0x00,0x00,0x00, 0x04,0x3E,0x00,0x00,0x00,0x1E,0x3E,0x0E, 0x00,0x00,0x3E,0x3E,0x0F,0x00,0x00,0x7E, 0xBF,0x0F,0x00,0x00,0x7E,0xFF,0x0F,0x00, 0x00,0xFE,0xFF,0x0F,0x00,0xF0,0xFF,0xFF, 0x0F,0x00,0xF8,0xFF,0xFF,0xFF,0x01,0xF0, 0xFF,0xFF,0xFF,0x01,0xF0,0xFF,0xFF,0xFF, 0x01,0xE0,0xFF,0xFF,0xFF,0x00,0xC0,0xFF, 0xF0,0x7F,0x00,0xF0,0x7F,0xE0,0x3F,0x00, 0xFC,0x3F,0xC0,0xFF,0x00,0xFE,0x3F,0xC0, 0xFF,0x03,0xFC,0x3F,0xC0,0xFF,0x07,0xF8, 0x7F,0xE0,0xFF,0x07,0xE0,0x7F,0xE0,0xFF, 0x01,0xC0,0xFF,0xF9,0x7F,0x00,0xE0,0xFF, 0xFF,0x3F,0x00,0xF0,0xFF,0xFF,0x7F,0x00, 0xF0,0xFF,0xFF,0xFF,0x00,0xF8,0xFF,0xFF, 0xFF,0x00,0xF0,0xFE,0xFF,0xFF,0x00,0x00, 0xFE,0xFF,0x63,0x00,0x00,0xFE,0xFF,0x03, 0x00,0x00,0xBE,0xEF,0x07,0x00,0x00,0x9E, 0xCF,0x07,0x00,0x00,0x8E,0x8F,0x03,0x00, 0x00,0x80,0x0F,0x03,0x00,0x00,0x00,0x07, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00 /*"C:\Users\ROG\Desktop\三连\点赞.bmp",0*//* (36 X 35 )*/ }, { 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x80, 0x7F, 0x00, 0x00, 0x00, 0x80, 0x7F, 0x00, 0x00, 0x00, 0xC0, 0x7F, 0x00, 0x00, 0x00, 0xE0, 0x7F, 0x00, 0x00, 0x00, 0xF8, 0x7F, 0x00, 0x00, 0xF0, 0xF8, 0xFF, 0xFF, 0x01, 0xFC, 0xF8, 0xFF, 0xFF, 0x07, 0xFC, 0xF8, 0xFF, 0xFF, 0x07, 0xFE, 0xF8, 0xFF, 0xFF, 0x07, 0xFE, 0xF8, 0xFF, 0xFF, 0x07, 0xFE, 0xF8, 0xFF, 0xFF, 0x07, 0xFE, 0xF8, 0xFF, 0xFF, 0x07, 0xFE, 0xF8, 0xFF, 0xFF, 0x07, 0xFE, 0xF8, 0xFF, 0xFF, 0x03, 0xFE, 0xF8, 0xFF, 0xFF, 0x03, 0xFE, 0xF8, 0xFF, 0xFF, 0x03, 0xFE, 0xF8, 0xFF, 0xFF, 0x03, 0xFE, 0xF8, 0xFF, 0xFF, 0x01, 0xFE, 0xF8, 0xFF, 0xFF, 0x01, 0xFE, 0xF8, 0xFF, 0xFF, 0x01, 0xFE, 0xF8, 0xFF, 0xFF, 0x01, 0xFE, 0xF8, 0xFF, 0xFF, 0x00, 0xFE, 0xF8, 0xFF, 0xFF, 0x00, 0xFC, 0xF8, 0xFF, 0x7F, 0x00, 0xFC, 0xF8, 0xFF, 0x3F, 0x00, 0xF8, 0xF8, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /*"C:\Users\ROG\Desktop\三连\点赞.bmp",0*/ /* (36 X 35 )*/ }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x0C,0x00,0x00,0x00,0x00,0x1C,0x00, 0x00,0x00,0x00,0x3C,0x00,0x00,0x00,0x00, 0xFC,0x00,0x00,0x00,0x00,0xFC,0x01,0x00, 0x00,0x00,0xFC,0x03,0x00,0x00,0x00,0xFC, 0x07,0x00,0x00,0x00,0xFC,0x0F,0x00,0x00, 0x00,0xFE,0x1F,0x00,0x00,0xF8,0xFF,0x3F, 0x00,0x00,0xFF,0xFF,0xFF,0x00,0xC0,0xFF, 0xFF,0xFF,0x01,0xE0,0xFF,0xFF,0xFF,0x03, 0xF0,0xFF,0xFF,0xFF,0x07,0xF0,0xFF,0xFF, 0xFF,0x0F,0xF8,0xFF,0xFF,0xFF,0x0F,0xFC, 0xFF,0xFF,0xFF,0x07,0xFC,0xFF,0xFF,0xFF, 0x03,0xFE,0xFF,0xFF,0xFF,0x01,0xFE,0xFF, 0xFF,0xFF,0x00,0xFF,0x03,0xFE,0x3F,0x00, 0xFF,0x00,0xFC,0x1F,0x00,0x3F,0x00,0xFC, 0x0F,0x00,0x1F,0x00,0xFC,0x07,0x00,0x07, 0x00,0xFC,0x03,0x00,0x03,0x00,0xFC,0x01, 0x00,0x01,0x00,0xFC,0x00,0x00,0x00,0x00, 0x3C,0x00,0x00,0x00,0x00,0x1C,0x00,0x00, 0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,/*"C:\Users\13944\Desktop\fenxiang.bmp",0*/ } }; uint8_t icon_width[]={35,37,36,36,36}; //main界面图片 PROGMEM const uint8_t LOGO[]= { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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FF,0xFB,0xCF,0x3F,0xFF,0xF9,0x9F,0xEF, 0xFF,0x00,0xFC,0xFF,0xE1,0xFF,0x1F,0xFE,0xFF,0x07,0xF0,0xFF,0x00,0xFE,0x7F,0xF0, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F, 0xFC,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x78,0x00,0x00,0x00,0x00,0x08,0x08,0x00,0x40,0x00,0x02,0x10,0x00,0x00, 0x00,0x00,0x88,0x00,0x00,0x00,0x00,0x08,0x08,0x00,0x60,0x00,0x02,0x00,0x00,0x00, 0x00,0x00,0x88,0x9C,0x24,0xC7,0x1C,0x0F,0x68,0x22,0xA0,0xCC,0x23,0x91,0xC7,0x01, 0x00,0xFE,0x88,0xA2,0xAA,0x48,0xA2,0x08,0x98,0x14,0xB0,0x24,0x22,0x91,0x24,0x02, 0x00,0x00,0x78,0xA2,0xAB,0x4F,0xBE,0x08,0x88,0x14,0xF0,0x24,0x22,0x91,0x24,0x02, 0x00,0x00,0x08,0x22,0x9B,0x40,0x82,0x08,0x88,0x0C,0x08,0x25,0x22,0x91,0x24,0x02, 0x00,0x00,0x08,0x1C,0x11,0x4F,0x3C,0x0F,0x78,0x08,0x08,0xC5,0xE3,0x91,0xC4,0x01, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; const float PID_MAX=10.00;//PID最大允许值 //PID变量 float Kpid[3]={9.97,0.2,0.01};//Kp,Ki,Kd // float Kp=8.96; // float Ki=0.2; // float Kd=0.01; uint8_t disappear_step=1; float angle,angle_last; //实时坐标 uint8_t chart_x; bool frame_is_drawed=false; //指向buf首地址的指针 uint8_t* buf_ptr; uint16_t buf_len; //选择界面变量 uint8_t x; int16_t y,y_trg;//目标和当前 uint8_t line_y,line_y_trg;//线的位置 uint8_t box_width,box_width_trg;//框的宽度 int16_t box_y,box_y_trg;//框的当前值和目标值 int8_t ui_select;//当前选中那一栏 //pid界面变量 //int8_t pid_y,pid_y_trg; uint8_t pid_line_y,pid_line_y_trg;//线的位置 uint8_t pid_box_width,pid_box_width_trg;//框的宽度 int16_t pid_box_y,pid_box_y_trg;//框的当前值和目标值 int8_t pid_select;//当前选中那一栏 //icon界面变量 int16_t icon_x,icon_x_trg; int16_t app_y,app_y_trg; int8_t icon_select; uint8_t ui_index,ui_state; enum//ui_index { M_LOGO,//开始界面 M_SELECT,//选择界面 M_PID,//PID界面 M_PID_EDIT,//pid编辑 M_ICON,//icon界面 M_CHART,//图表 M_TEXT_EDIT,//文字编辑 M_VIDEO,//视频显示 M_ABOUT,//关于本机 }; enum//ui_state { S_NONE, S_DISAPPEAR, S_SWITCH, S_MENU_TO_MENU, S_MENU_TO_PIC, S_PIC_TO_MENU, }; //const char* text="This is a text Hello world ! follow up one two three four may jun july"; //菜单结构体 typedef struct { char * select; }SELECT_LIST; SELECT_LIST pid[] { {"-Proportion"}, {"-Integral"}, {"-Derivative"}, {"Return"}, }; uint8_t pid_num=sizeof(pid)/sizeof(SELECT_LIST);//PID选项数量 SELECT_LIST list[] { {"MainUI"}, {"+PID Editor"}, {"-Icon Test"}, {"-Chart Test"}, {"-Text Edit"}, {"-Play Video"}, {"{ About }"}, }; uint8_t list_num=sizeof(list)/sizeof(SELECT_LIST);//选择界面数量 uint8_t single_line_length=63/list_num; uint8_t total_line_length=single_line_length*list_num+1; SELECT_LIST icon[] { {"Likes"}, {"Collection"}, {"Setp"}, {"Slot"}, {"Share"}, }; //设备名称 char name[]="MunoUI"; //允许名字的最大长度 const uint8_t name_len=6;//0-11for name 12 for return uint8_t edit_index=0; bool edit_flag=false;//默认不在编辑 uint8_t blink_flag;//默认高亮 const uint8_t BLINK_SPEED=16;//2的倍数 uint8_t icon_num=sizeof(icon)/sizeof(SELECT_LIST); //按键变量 typedef struct { bool val; bool last_val; }KEY; KEY key[3]={false}; //按键信息 typedef struct { uint8_t id; bool pressed; }KEY_MSG; KEY_MSG key_msg={0}; bool get_key_val(uint8_t ch) { switch (ch) { case 0: return digitalRead(BTN0); break; case 1: return digitalRead(BTN1); break; case 2: return digitalRead(BTN2); break; default: break; } } void key_init() { for(uint8_t i=0;i<(sizeof(key)/sizeof(KEY));++i) { key[i].val=key[i].last_val=get_key_val(i); } } void key_scan() { for(uint8_t i=0;i<(sizeof(key)/sizeof(KEY));++i) { key[i].val=get_key_val(i);//获取键值 if(key[i].last_val!=key[i].val)//发生改变 { key[i].last_val=key[i].val;//更新状态 if(key[i].val==LOW) { key_msg.id=i; key_msg.pressed=true; } } } } //移动函数 bool move(int16_t* a,int16_t* a_trg) { if (*a < *a_trg) { *a+=SPEED; if (*a>*a_trg) *a=*a_trg;//加完超过 } else if(*a>*a_trg) { *a-=SPEED; if (*a<*a_trg) *a=*a_trg;//减完不足 } else { return true;//到达目标 } return false;//未到达 } //移动函数 bool move_icon(int16_t* a,int16_t* a_trg) { if (*a < *a_trg) { *a+=ICON_SPEED; if (*a>*a_trg) *a=*a_trg;//加完超过 } else if(*a>*a_trg) { *a-=ICON_SPEED; if (*a<*a_trg) *a=*a_trg;//减完不足 } else { return true;//到达目标 } return false;//未到达 } //宽度移动函数 bool move_width(uint8_t* a,uint8_t* a_trg,uint8_t select,uint8_t id) { if (*a < *a_trg) { uint8_t step=16/SPEED;//判断步数 uint8_t len; if(ui_index==M_SELECT) { len=abs(u8g2.getStrWidth(list[select].select)-u8g2.getStrWidth(list[id==0?select+1:select-1].select)); } else if(ui_index==M_PID) { len=abs(u8g2.getStrWidth(pid[select].select)-u8g2.getStrWidth(pid[id==0?select+1:select-1].select)); } uint8_t width_speed=((len%step)==0?(len/step):(len/step+1)); //计算步长 *a+=width_speed; if (*a>*a_trg) *a=*a_trg;// } else if(*a>*a_trg) { uint8_t step=16/SPEED;//判断步数 uint8_t len; if(ui_index==M_SELECT) { len=abs(u8g2.getStrWidth(list[select].select)-u8g2.getStrWidth(list[id==0?select+1:select-1].select)); } else if(ui_index==M_PID) { len=abs(u8g2.getStrWidth(pid[select].select)-u8g2.getStrWidth(pid[id==0?select+1:select-1].select)); } uint8_t width_speed=((len%step)==0?(len/step):(len/step+1)); //计算步长 *a-=width_speed; if (*a<*a_trg) *a=*a_trg; } else { return true;//到达目标 } return false;//未到达 } //进度条移动函数 bool move_bar(uint8_t* a,uint8_t* a_trg) { if (*a < *a_trg) { uint8_t step=16/SPEED;//判断步数 uint8_t width_speed=((single_line_length%step)==0?(single_line_length/step):(single_line_length/step+1)); //计算步长 *a+=width_speed; if (*a>*a_trg) *a=*a_trg;// } else if(*a>*a_trg) { uint8_t step=16/SPEED;//判断步数 uint8_t width_speed=((single_line_length%step)==0?(single_line_length/step):(single_line_length/step+1)); //计算步长 *a-=width_speed; if (*a<*a_trg) *a=*a_trg; } else { return true;//到达目标 } return false;//未到达 } //文字编辑函数 void text_edit(bool dir,uint8_t index) { if(!dir) { if(name[index]>='A' && name[index]<='Z')//大写字母 { if(name[index]=='A') { name[index]='z'; } else { name[index]-=1; } } else if(name[index]>='a' && name[index]<='z')//小写字母 { if(name[index]=='a') { name[index]=' '; } else { name[index]-=1; } } else { name[index]='Z'; } } else { if(name[index]>='A' && name[index]<='Z')//大写字母 { if(name[index]=='Z') { name[index]=' '; } else { name[index]+=1; } } else if(name[index]>='a' && name[index]<='z')//小写字母 { if(name[index]=='z') { name[index]='A'; } else { name[index]+=1; } } else { name[index]='a'; } } } //消失函数 void disappear() { switch(disappear_step) { case 1: for(uint16_t i=0;i0) Kpid[pid_select]-=0.01; break; case 1: if(Kpid[pid_select]< PID_MAX ) Kpid[pid_select]+=0.01; break; case 2: ui_index=M_PID; break; default: break; } } pid_ui_show(); for(uint16_t i=0;i(sizeof(list)/sizeof(SELECT_LIST))) break; ui_select+=1; line_y_trg+=single_line_length; if((ui_select+1)>(4-y/16)) { y_trg-=16; } else { box_y_trg+=16; } break; case 2: switch(ui_select) { case 0: //return ui_state=S_DISAPPEAR; ui_index=M_LOGO; break; case 1: //pid ui_state=S_DISAPPEAR; ui_index=M_PID; break; case 2: //icon ui_state=S_DISAPPEAR; ui_index=M_ICON; break; case 3: //chart ui_state=S_DISAPPEAR; ui_index=M_CHART; break; case 4: //textedit ui_state=S_DISAPPEAR; ui_index=M_TEXT_EDIT; break; case 6: //about ui_state=S_DISAPPEAR; ui_index=M_ABOUT; break; default: break; } //Serial.println("Btn2"); default: break; } //Serial.println(ui_select); box_width_trg=u8g2.getStrWidth(list[ui_select].select)+x*2; } select_ui_show(); } void icon_proc(void)//icon界面处理 { icon_ui_show(); if(key_msg.pressed) { key_msg.pressed=false; switch(key_msg.id) { case 1: if(icon_select!=(icon_num-1)) { icon_select+=1; app_y_trg+=16; icon_x_trg-=ICON_SPACE; } break; case 0: if(icon_select!=0) { icon_select-=1; app_y_trg-=16; icon_x_trg+=ICON_SPACE; } break; case 2: ui_state=S_DISAPPEAR; ui_index=M_SELECT; icon_select=0; icon_x=icon_x_trg=0; app_y=app_y_trg=0; break; default: break; } } } void chart_proc()//chart界面处理函数 { chart_ui_show(); if(key_msg.pressed) { key_msg.pressed=false; ui_state=S_DISAPPEAR; ui_index=M_SELECT; frame_is_drawed=false;//退出后框架为未画状态 chart_x=0; } } void text_edit_proc() { text_edit_ui_show(); if(key_msg.pressed) { key_msg.pressed=false; switch(key_msg.id) { case 0: if(edit_flag) { //编辑 text_edit(false,edit_index); } else { if(edit_index==0) { edit_index=name_len; } else { edit_index-=1; } } break; case 1: if(edit_flag) { //编辑 text_edit(true,edit_index); } else { if(edit_index==name_len) { edit_index=0; } else { edit_index+=1; } } break; case 2: if (edit_index==name_len) { ui_state=S_DISAPPEAR; ui_index=M_SELECT; edit_index=0; } else { edit_flag=!edit_flag; } break; default: break; } } } void about_proc()//about界面处理函数 { if(key_msg.pressed) { key_msg.pressed=false; ui_state=S_DISAPPEAR; ui_index=M_SELECT; } about_ui_show(); } /********************************总的UI显示************************************/ void ui_proc()//总的UI进程 { switch(ui_state) { case S_NONE: if(ui_index!=M_CHART) u8g2.clearBuffer(); switch(ui_index) { case M_LOGO: logo_proc(); break; case M_SELECT: select_proc(); break; case M_PID: pid_proc(); break; case M_ICON: icon_proc(); break; case M_CHART: chart_proc(); break; case M_TEXT_EDIT: text_edit_proc(); break; case M_PID_EDIT: pid_edit_proc(); break; case M_ABOUT: about_proc(); break; default: break; } break; case S_DISAPPEAR: disappear(); break; default: break; } u8g2.sendBuffer(); } void conn() { WiFi.disconnect(true); // 断开当前WIFI连接 WiFi.mode(WIFI_STA); // 设置WIFI模式为STA模式 WiFi.begin(ssid, password); /* while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting..."); } */ } void ntc_now() { static uint32_t nowTime = millis(); if (millis() - nowTime > 1000) { nowTime = millis(); time_t now = time(nullptr); struct tm* timeinfo = localtime(&now); strftime(date, sizeof(date), "%Y-%m-%d", timeinfo); strftime(time_n, sizeof(time_n), "%H:%M:%S", timeinfo); // u8g2.drawStr(2,12,"2023-06-25"); // u8g2.drawStr(83,12,"17:10:20"); // u8g2.sendBuffer(); } } void wifi_ac() { static uint32_t wifi_nowTime = millis(); if (millis() - wifi_nowTime > 20000) { wifi_nowTime = millis(); if (WiFi.status() != WL_CONNECTED) { conn(); Serial.println("Connecting..."); } else { Serial.println("Connected to Wi-Fi"); } } } void setup() { Serial.begin(115200); //Wire.begin(21,22,400000); pinMode(BTN0, INPUT_PULLUP); pinMode(BTN1, INPUT_PULLUP); pinMode(BTN2, INPUT_PULLUP); pinMode(32, OUTPUT); pinMode(18, OUTPUT); digitalWrite(18,HIGH); digitalWrite(32,LOW); key_init(); u8g2.setBusClock(800000); u8g2.begin(); u8g2.setFont(u8g2_font_wqy12_t_chinese1); conn(); configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); // configTime(0, 0, "pool.ntp.org"); while (!time(nullptr)) { delay(1000); Serial.println("Waiting..."); } Serial.println("Time synchronized"); //u8g2.setContrast(10); buf_ptr=u8g2.getBufferPtr();//拿到buffer首地址 buf_len=8*u8g2.getBufferTileHeight()*u8g2.getBufferTileWidth(); x=4; y=y_trg=0; line_y=line_y_trg=1; pid_line_y=pid_line_y_trg=1; ui_select=pid_select=icon_select=0; icon_x=icon_x_trg=0; app_y=app_y_trg=0; box_width=box_width_trg=u8g2.getStrWidth(list[ui_select].select)+x*2;//两边各多2 pid_box_width=pid_box_width_trg=u8g2.getStrWidth(pid[pid_select].select)+x*2;//两边各多2 ui_index=M_LOGO; //ui_index=M_TEXT_EDIT; ui_state=S_NONE; } void loop() { ntc_now(); //NTP同步时间 key_scan(); //按键检测 ui_proc(); //UI进程 wifi_ac(); //wifi检测 }