@@ -271,25 +271,25 @@ static esp_err_t gpio_apply(gpio_control_t *control)
271271{
272272 gpio_config_t config = {
273273 .pin_bit_mask = 1ULL << control -> pin ,
274- .mode = control -> mode ? GPIO_MODE_OUTPUT : GPIO_MODE_INPUT ,
275- .pull_up_en = control -> mode ? GPIO_PULLUP_DISABLE : GPIO_PULLUP_ENABLE ,
274+ .mode = control -> mode == 1 ? GPIO_MODE_INPUT : GPIO_MODE_OUTPUT ,
275+ .pull_up_en = control -> mode == 1 ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE ,
276276 .pull_down_en = GPIO_PULLDOWN_DISABLE ,
277277 .intr_type = GPIO_INTR_DISABLE ,
278278 };
279279 esp_err_t error = gpio_config (& config );
280- if (error == ESP_OK && control -> mode ) error = gpio_set_level (control -> pin , control -> mode == 2 );
280+ if (error == ESP_OK && control -> mode > 1 ) error = gpio_set_level (control -> pin , control -> mode == 3 );
281281 return error ;
282282}
283283
284284static void gpio_mode_clicked (lv_event_t * event )
285285{
286286 gpio_control_t * control = lv_event_get_user_data (event );
287- control -> mode = ( control -> mode + 1 ) % 3 ;
287+ control -> mode = control -> mode == 3 ? 1 : control -> mode + 1 ;
288288 if (gpio_apply (control ) != ESP_OK ) {
289289 lv_label_set_text (control -> mode_label , "ERROR" );
290290 return ;
291291 }
292- lv_label_set_text (control -> mode_label , control -> mode == 0 ? "INPUT" : control -> mode == 1 ? "LOW" : "HIGH" );
292+ lv_label_set_text (control -> mode_label , control -> mode == 1 ? "INPUT" : control -> mode == 2 ? "LOW" : "HIGH" );
293293}
294294
295295static void gpio_tick (lv_timer_t * timer )
@@ -1463,7 +1463,7 @@ static void clear_content(void)
14631463 lv_timer_delete (gpio_timer );
14641464 gpio_timer = NULL ;
14651465 for (size_t i = 0 ; i < GPIO_CONTROL_COUNT ; i ++ ) {
1466- gpio_reset_pin (gpio_controls [i ].pin );
1466+ if ( gpio_controls [ i ]. mode ) gpio_reset_pin (gpio_controls [i ].pin );
14671467 gpio_controls [i ].mode_label = NULL ;
14681468 gpio_controls [i ].level_label = NULL ;
14691469 }
@@ -2396,7 +2396,6 @@ static void show_gpio(void)
23962396 for (size_t i = 0 ; i < GPIO_CONTROL_COUNT ; i ++ ) {
23972397 gpio_control_t * control = & gpio_controls [i ];
23982398 control -> mode = 0 ;
2399- gpio_apply (control );
24002399 lv_obj_t * row = lv_obj_create (list );
24012400 lv_obj_set_size (row , 600 , 66 );
24022401 lv_obj_set_flex_flow (row , LV_FLEX_FLOW_ROW );
@@ -2412,7 +2411,7 @@ static void show_gpio(void)
24122411 lv_obj_set_size (mode , 180 , 50 );
24132412 lv_obj_add_event_cb (mode , gpio_mode_clicked , LV_EVENT_CLICKED , control );
24142413 control -> mode_label = lv_label_create (mode );
2415- lv_label_set_text (control -> mode_label , "INPUT " );
2414+ lv_label_set_text (control -> mode_label , "SET " );
24162415 lv_obj_center (control -> mode_label );
24172416 }
24182417 gpio_timer = lv_timer_create (gpio_tick , 200 , NULL );
0 commit comments