Skip to content

Commit

Permalink
Retry IP connect on boot, fix network c string issue
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Nov 13, 2023
1 parent 5224e34 commit c5d0825
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
13 changes: 12 additions & 1 deletion CYD-Klipper/src/ui/ip_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ bool verify_ip(){
}
}

bool retry_ip_verify(){
for (int i = 0; i < 3; i++){
if (verify_ip()){
return true;
}
delay(500);
}

return false;
}

static void ta_event_cb(lv_event_t * e) {
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * ta = lv_event_get_target(e);
Expand Down Expand Up @@ -87,7 +98,7 @@ void ip_setup_inner(){
void ip_setup(){
connect_ok = false;

if (global_config.ipConfigured && verify_ip()){
if (global_config.ipConfigured && retry_ip_verify()){
return;
}

Expand Down
21 changes: 13 additions & 8 deletions CYD-Klipper/src/ui/wifi_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ void wifi_init_inner(){
lv_task_handler();
lv_refr_now(NULL);

int n = WiFi.scanNetworks();

lv_obj_clean(lv_scr_act());

lv_obj_t * refreshBtn = lv_btn_create(lv_scr_act());
Expand All @@ -128,15 +126,22 @@ void wifi_init_inner(){
lv_obj_align(list, LV_ALIGN_TOP_LEFT, 10, 40);
lv_obj_set_size(list, TFT_HEIGHT - 20, TFT_WIDTH - 40 - 5);

int n = WiFi.scanNetworks();

for (int i = 0; i < n; ++i) {
const char* ssid = WiFi.SSID(i).c_str();
int len = strlen(ssid);
String ssid = WiFi.SSID(i);
char* ssid_copy = (char*)malloc(ssid.length() + 1);
int j = 0;

for (; j < ssid.length(); ++j){
if (ssid[j] == '\0')
continue;

ssid_copy[j] = ssid[j];
}

if (len == 0)
continue;
ssid_copy[j] = '\0';

const char* ssid_copy = (const char*)malloc(len + 1);
strcpy((char*)ssid_copy, ssid);
lv_obj_t * btn = lv_list_add_btn(list, LV_SYMBOL_WIFI, ssid_copy);
lv_obj_add_event_cb(btn, wifi_btn_event_handler, LV_EVENT_ALL, (void*)ssid_copy);
}
Expand Down

0 comments on commit c5d0825

Please sign in to comment.