Bladeren bron

add:lcd 添加设置方向接口,避免重新初始化

Dozingfiretruck 2 jaren geleden
bovenliggende
commit
041184367d
3 gewijzigde bestanden met toevoegingen van 23 en 7 verwijderingen
  1. 11 5
      components/lcd/luat_lcd.c
  2. 1 1
      components/lcd/luat_lcd.h
  3. 11 1
      components/lcd/luat_lib_lcd.c

+ 11 - 5
components/lcd/luat_lcd.c

@@ -161,11 +161,7 @@ int luat_lcd_init(luat_lcd_conf_t* conf) {
         if(strcmp(conf->opts->name,"custom") == 0){
             luat_heap_free(conf->opts->init_cmds);
         }
-        if(conf->direction==0) direction_date = conf->opts->direction0;
-        else if(conf->direction==1) direction_date = conf->opts->direction90;
-        else if(conf->direction==2) direction_date = conf->opts->direction180;
-        else direction_date = conf->opts->direction270;
-        lcd_write_cmd_data(conf,0x36, &direction_date, 1);
+        luat_lcd_set_direction(conf,conf->direction);
     }
 
     luat_lcd_wakeup(conf);
@@ -246,6 +242,16 @@ int luat_lcd_set_color(luat_color_t back, luat_color_t fore){
     return 0;
 }
 
+int luat_lcd_set_direction(luat_lcd_conf_t* conf, uint8_t direction){
+    uint8_t direction_date = 0;
+    if(direction==0) direction_date = conf->opts->direction0;
+    else if(direction==1) direction_date = conf->opts->direction90;
+    else if(direction==2) direction_date = conf->opts->direction180;
+    else direction_date = conf->opts->direction270;
+    lcd_write_cmd_data(conf,0x36, &direction_date, 1);
+    return 0;
+}
+
 #ifndef LUAT_USE_LCD_CUSTOM_DRAW
 int luat_lcd_flush(luat_lcd_conf_t* conf) {
     if (conf->buff == NULL) {

+ 1 - 1
components/lcd/luat_lcd.h

@@ -135,7 +135,7 @@ int luat_lcd_draw_vline(luat_lcd_conf_t* conf, int16_t x, int16_t y,int16_t h, l
 int luat_lcd_draw_hline(luat_lcd_conf_t* conf, int16_t x, int16_t y,int16_t h, luat_color_t color);
 int luat_lcd_draw_rectangle(luat_lcd_conf_t* conf, int16_t x1, int16_t y1, int16_t x2, int16_t y2, luat_color_t color);
 int luat_lcd_draw_circle(luat_lcd_conf_t* conf, int16_t x0, int16_t y0, uint8_t r, luat_color_t color);
-
+int luat_lcd_set_direction(luat_lcd_conf_t* conf, uint8_t direction);
 /*
  * csdk适配用
  */

+ 11 - 1
components/lcd/luat_lib_lcd.c

@@ -429,6 +429,12 @@ static int l_lcd_set_color(lua_State* L) {
     return 1;
 }
 
+static int l_lcd_set_direction(lua_State* L) {
+    int ret = luat_lcd_set_direction(default_conf, (uint8_t)luaL_checkinteger(L, 1));
+    lua_pushboolean(L, ret == 0 ? 1 : 0);
+    return 1;
+}
+
 /*
 lcd颜色填充
 @api lcd.draw(x1, y1, x2, y2,color)
@@ -1825,7 +1831,11 @@ static const rotable_Reg_t reg_lcd[] =
 #ifdef USE_U8G2_SARASA_M28_CHINESE
     { "font_sarasa_m28_chinese", ROREG_PTR((void*)u8g2_font_sarasa_m28_chinese)},
 #endif
-
+    { "set_direction",  ROREG_FUNC(l_lcd_set_direction)},
+    { "direction_0",    ROREG_INT(0)},
+    { "direction_90",   ROREG_INT(1)},
+    { "direction_180",  ROREG_INT(2)},
+    { "direction_270",  ROREG_INT(3)},
 	  {NULL, ROREG_INT(0)}
 };