Skip to content

Commit

Permalink
1.WIFI刷新
Browse files Browse the repository at this point in the history
2.页面修改
  • Loading branch information
Rainboooom committed Jul 13, 2023
1 parent a614018 commit d4e3285
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 75 deletions.
6 changes: 3 additions & 3 deletions include/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,10 @@

//3.1.3 CLL 打印前判断耗材种类并弹窗
#define TJC_PAGE_PREVIEW_POP_1 114
#define TJC_PAGE_PREVIEW_POP_1_YES 0x00

#define TJC_PAGE_PREVIEW_POP_2 115
#define TJC_PAGE_PREVIEW_POP_2_YES 0x00
#define TJC_PAGE_PREVIEW_POP_YES 0x00
//4.3.4 CLL 耗材确认弹窗新增不再提示按钮
#define TJC_PAGE_PREVIEW_POP_NO_POP 0x01

#endif

Expand Down
31 changes: 23 additions & 8 deletions src/MakerbaseWiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ void set_page_wifi_ssid_list(int pages) {
}
}

//4.3.4 CLL 修复WiFi刷新bug
void get_ssid_list_pages() {
if (result_list.size() % 5 == 0) {
if (ssid_list.size() % 5 == 0) {
// page_wifi_ssid_list_pages = result_list.size() / 5 - 1;
page_wifi_ssid_list_pages = ssid_list.size() / 5 - 1;
page_wifi_ssid_list_pages = ssid_list.size() / 5;
} else {
// page_wifi_ssid_list_pages = result_list.size() / 5;
page_wifi_ssid_list_pages = ssid_list.size() / 5;
page_wifi_ssid_list_pages = ssid_list.size() / 5 + 1;
}
// std::cout << "页面数 = " << page_wifi_ssid_list_pages << std::endl;

Expand Down Expand Up @@ -734,9 +735,14 @@ int parse_scan_results(char* scan_results) {
level_list.clear();
ssid_list.clear();

char* lines[1024] = {0};
//4.3.4 CLL 修复WiFi刷新bug
//char* lines[1024] = {0};
char buffer[4096];
strcpy(buffer, scan_results);
char* lines[128] = {0};
int num_lines = 0;
char* line = strtok(scan_results, "\n");
//char* line = strtok(scan_results, "\n");
char* line = strtok(buffer, "\n");
while (line != NULL) {
lines[num_lines++] = line;
line = strtok(NULL, "\n");
Expand All @@ -746,7 +752,9 @@ int parse_scan_results(char* scan_results) {
char* fields[5] = {0};
int num_fields = 0;

char ssid_line[128] = {0};
//4.3.4 CLL 修复WiFi刷新bug
//char ssid_line[128] = {0};
char ssid_line[256] = {0};
memset(ssid_line, 0x00, sizeof(ssid_line));
strcpy(ssid_line, lines[i]);
int ssid_line_index = 0;
Expand All @@ -760,14 +768,21 @@ int parse_scan_results(char* scan_results) {

fields[num_fields++] = field;
field = strtok(NULL, " \t");
//4.3.4 CLL 修复WiFi刷新bug
if (5 == num_fields) {
break;
}
}

if (num_fields < 5) {
printf("Invalid scan result: %s\n", lines[i]);
continue;
} else {
unsigned char ssid_name[64];
printf_decode(ssid_name, 64, ssid_line + ssid_line_index);
//4.3.4 CLL 修复WiFi刷新bug
//unsigned char ssid_name[64];
//printf_decode(ssid_name, 64, ssid_line + ssid_line_index);
unsigned char ssid_name[192];
printf_decode(ssid_name, 192, ssid_line + ssid_line_index);
if (ssid_name[0] == '\x00') {

} else {
Expand Down
74 changes: 47 additions & 27 deletions src/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ extern std::string output_console;
//3.1.0 CLL 新增热床调平
extern bool printer_bed_leveling;

//4.3.4 CLL 耗材确认弹窗新增不再提示按钮
extern bool preview_pop_1_on;
extern bool preview_pop_2_on;

/* 更新页面处理 */
void refresh_page_show() {
if (current_page_id != TJC_PAGE_PRINTING) {
Expand Down Expand Up @@ -2210,7 +2214,10 @@ void refresh_page_main() {
send_cmd_val(tty_fd, "n2", std::to_string(printer_hot_temperature));

// MKSLOG_RED("LED灯的状态: %f", printer_caselight_value);
if (printer_caselight_value == 0) { // LED灯的logo
//4.3.4 CLL 修复开机读取不到状态
if (printer_caselight_value == -1) {
get_object_status();
} else if (printer_caselight_value == 0) { // LED灯的logo
send_cmd_picc(tty_fd, "b0", "1");
} else {
send_cmd_picc(tty_fd, "b0", "2");
Expand Down Expand Up @@ -3121,8 +3128,11 @@ void go_to_network() {
page_wifi_ssid_list_pages = 0;
page_wifi_current_pages = 0;
page_to(TJC_PAGE_WIFI_LIST_2);
send_cmd_txt(tty_fd, "t0", get_wlan0_ip().data());
get_wlan0_status();
//4.3.4 CLL 修复WiFi刷新bug
//send_cmd_txt(tty_fd, "t0", get_wlan0_ip().data());

//get_wlan0_status();
scan_ssid_and_show();
if (strcmp(status_result.wpa_state, "COMPLETED") == 0) {
current_connected_ssid_name = status_result.ssid; // 如果已经连接wifi,获取wifi的名字
} else if (strcmp(status_result.wpa_state, "INACTIVE")) {
Expand All @@ -3135,17 +3145,26 @@ void go_to_network() {
}
}

//4.3.4 CLL 修复WiFi刷新bug
void scan_ssid_and_show() {
if (access("/var/run/wpa_supplicant/wlan0", F_OK) == 0){
get_wlan0_status();
mks_wpa_scan_scanresults();
// mks_wpa_scan();
get_ssid_list_pages();
page_wifi_current_pages = 0;
set_page_wifi_ssid_list(page_wifi_current_pages);
refresh_page_wifi_list();
} else{
mks_page_internet_ip = get_eth0_ip();
page_to(TJC_PAGE_INTERNET);
send_cmd_txt(tty_fd, "t0", mks_page_internet_ip);
}
}

void refresh_page_wifi_list() {
//4.3.4 CLL 修复WiFi刷新bug
if (access("/var/run/wpa_supplicant/wlan0", F_OK) == 0){
for (int i = 0; i < 5; i++) {
std::cout << "刷新的wifi: " << page_wifi_ssid_list[i] << std::endl;
// send_cmd_txt(tty_fd, "t" + std::to_string(i+1), page_wifi_ssid_list[i]);
Expand Down Expand Up @@ -3178,33 +3197,34 @@ void refresh_page_wifi_list() {
} else {
send_cmd_picc(tty_fd, "wifi1", "102");
page_wifi_list_ssid_button_enabled[0] = true;
}
}

if (page_wifi_ssid_list[i] == "") {
std::cout << "刷新为没有锁的图片" << std::endl;
send_cmd_picc(tty_fd, "wifi" + std::to_string(i + 1), "358");
send_cmd_picc2(tty_fd, "wifi" + std::to_string(i + 1), "359");
page_wifi_list_ssid_button_enabled[i] = false;
} else {
std::cout << "刷新为有锁的图片" << std::endl;
send_cmd_picc(tty_fd, "wifi" + std::to_string(i + 1), "102");
send_cmd_picc2(tty_fd, "wifi" + std::to_string(i + 1), "323");
page_wifi_list_ssid_button_enabled[i] = true;
}

if (page_wifi_ssid_list_pages == 0) {
send_cmd_picc(tty_fd, "b0", "104");
send_cmd_picc(tty_fd, "b1", "106");
} else {
if (page_wifi_current_pages == 0) {
send_cmd_picc(tty_fd, "b0", "104");
std::cout << "刷新为没有锁的图片" << std::endl;
send_cmd_picc(tty_fd, "wifi" + std::to_string(i + 1), "358");
send_cmd_picc2(tty_fd, "wifi" + std::to_string(i + 1), "359");
page_wifi_list_ssid_button_enabled[i] = false;
} else {
send_cmd_picc(tty_fd, "b0", "103");
std::cout << "刷新为有锁的图片" << std::endl;
send_cmd_picc(tty_fd, "wifi" + std::to_string(i + 1), "102");
send_cmd_picc2(tty_fd, "wifi" + std::to_string(i + 1), "323");
page_wifi_list_ssid_button_enabled[i] = true;
}
if (page_wifi_current_pages == page_wifi_ssid_list_pages - 1) {

if (page_wifi_ssid_list_pages == 0) {
send_cmd_picc(tty_fd, "b0", "104");
send_cmd_picc(tty_fd, "b1", "106");
} else {
send_cmd_picc(tty_fd, "b1", "105");
if (page_wifi_current_pages == 0) {
send_cmd_picc(tty_fd, "b0", "104");
} else {
send_cmd_picc(tty_fd, "b0", "103");
}
if (page_wifi_current_pages == page_wifi_ssid_list_pages - 1) {
send_cmd_picc(tty_fd, "b1", "106");
} else {
send_cmd_picc(tty_fd, "b1", "105");
}
}
}
}
Expand Down Expand Up @@ -3790,10 +3810,10 @@ void check_filament_type() {
filament_type = file_metadata_filament_name;
}
std::transform(filament_type.begin(), filament_type.end(), filament_type.begin(), tolower);
MKSLOG_YELLOW("filament_type : %s",filament_type.c_str());
if (filament_type.find("pla") != -1 || filament_type.find("petg") != -1) {
//4.3.4 CLL 耗材确认弹窗新增不再提示按钮
if ((filament_type.find("pla") != -1 || filament_type.find("petg") != -1) && preview_pop_1_on == true) {
page_to(TJC_PAGE_PREVIEW_POP_1);
}else if (filament_type.find("abs") != -1) {
}else if (filament_type.find("abs") != -1 && preview_pop_2_on == true) {
page_to(TJC_PAGE_PREVIEW_POP_2);
}else {
page_to(TJC_PAGE_PRINTING);
Expand Down
3 changes: 2 additions & 1 deletion src/mks_printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ bool filament_switch_sensor_fila_filament_detected = false;
bool filament_switch_sensor_fila_enabled = false;

// output_pin caselight
float printer_caselight_value = 0;
//4.3.4 CLL 修复开机读取不到状态
float printer_caselight_value = -1;

// probe
float printer_probe_x_zoffset = 0.0;
Expand Down
54 changes: 34 additions & 20 deletions src/mks_wpa_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ int mks_wifi_run_cmd(char const *cmd, char *result, size_t *len) {

int ret = wpa_ctrl_request(wpa_ctrl, cmd, strlen(cmd), result, len, 0);
result[*len] = 0;

wpa_ctrl_close(wpa_ctrl);
//4.3.4 CLL 修复WiFi刷新bug
//wpa_ctrl_close(wpa_ctrl);

return ret;
}
Expand Down Expand Up @@ -423,8 +423,12 @@ void *mks_wifi_hdlevent_thread(void *arg) {
mks_enable_network();
} else if (strstr(buf, "CTRL-EVENT-CONNECTED") != NULL) {
MKSLOG_BLUE("已经成功连接上wifi");
//4.3.4 CLL 修复WiFi刷新bug
mks_enable_network();
usleep(10000);
wlan_state_str = "connected";
system("dhcpcd wlan0");
//4.3.4 CLL 修复WiFi刷新bug
//system("dhcpcd wlan0");
if (current_page_id == TJC_PAGE_WIFI_CONNECT) {
page_to(TJC_PAGE_WIFI_SUCCESS);
}
Expand All @@ -434,7 +438,7 @@ void *mks_wifi_hdlevent_thread(void *arg) {
if (current_page_id == TJC_PAGE_WIFI_CONNECT) {
page_to(TJC_PAGE_WIFI_FAILED);
}
} else if (strstr(buf, "CONN_FAILED") != NULL) {
} else if (strstr(buf, "CONN_FAILED") || strstr(buf, "timed out") != NULL) {
if (current_page_id == TJC_PAGE_WIFI_CONNECT) {
page_to(TJC_PAGE_WIFI_FAILED);
}
Expand All @@ -451,10 +455,11 @@ void *mks_wifi_hdlevent_thread(void *arg) {
}

int mks_wpa_scan_scanresults() {
// char path[64] = {"\0"};
//4.3.4 CLL 修复WiFi刷新bug
char path[64] = {"\0"};

// sprintf(path, "/var/run/wpa_supplicant/wlan0");
// ctrl_conn = wpa_ctrl_open(path);
sprintf(path, "/var/run/wpa_supplicant/wlan0");
ctrl_conn = wpa_ctrl_open(path);

if (!ctrl_conn) {
printf("Open wpa control interfaces failed!\n");
Expand All @@ -468,7 +473,8 @@ int mks_wpa_scan_scanresults() {

int ret;
reply_len = sizeof(replyBuff) - 1;
ret = wpa_ctrl_request(ctrl_conn, "SCAN", strlen("SCAN"), replyBuff, &reply_len, wpa_cli_msg_cb);
//4.3.4 CLL 修复WiFi刷新bug
ret = wpa_ctrl_request(ctrl_conn, "SCAN", strlen("SCAN"), replyBuff, &reply_len, NULL);
if (ret == -2) {
printf("Command timed out.\n");
// wpa_ctrl_close(ctrl_conn);
Expand All @@ -488,7 +494,8 @@ int mks_wpa_scan_scanresults() {

memset(replyBuff, 0x00, sizeof(replyBuff));
reply_len = sizeof(replyBuff) - 1;
ret = wpa_ctrl_request(ctrl_conn, "SCAN_RESULTS", strlen("SCAN_RESULTS"), replyBuff, &reply_len, wpa_cli_msg_cb);
//4.2.3 CLL 修复WiFi刷新bug
ret = wpa_ctrl_request(ctrl_conn, "SCAN_RESULTS", strlen("SCAN_RESULTS"), replyBuff, &reply_len, NULL);


if (ret == -2) {
Expand Down Expand Up @@ -614,8 +621,8 @@ int mks_wifi_connect(char *ssid, char *psk) {
*/

int mks_set_ssid(char *ssid) {

// char path[64] = {"\0"};
//4.3.4 CLL 修复WiFi刷新bug
char path[64] = {"\0"};
char cmd[64];
char replyBuff[2048] = {"\0"};
size_t reply_len;
Expand All @@ -637,7 +644,8 @@ int mks_set_ssid(char *ssid) {
MKSLOG_RED("发送cmd命令为: %s", cmd);
memset(replyBuff, 0x00, sizeof(replyBuff));
reply_len = sizeof(replyBuff) - 1;
ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), replyBuff, &reply_len, wpa_cli_msg_cb);
//4.3.4 CLL 修复WiFi刷新bug
ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), replyBuff, &reply_len, NULL);
if (ret == -2) {
MKSLOG_RED("Command timed out.");
// wpa_ctrl_close(ctrl_conn);
Expand Down Expand Up @@ -718,7 +726,8 @@ int mks_add_set_network(char *ssid) {
}

int mks_set_psk(char *psk) {
// char path[64] = {"\0"};
//4.3.4 CLL 修复WiFi刷新bug
char path[64] = {"\0"};
char cmd[64];
char replyBuff[2048] = {"\0"};
size_t reply_len;
Expand All @@ -743,7 +752,8 @@ int mks_set_psk(char *psk) {
// memset(replyBuff, 0x00, sizeof(replyBuff));
reply_len = sizeof(replyBuff) - 1;
// ret = wpa_ctrl_request(ctrl_conn, "SET_NETWORK 0 psk \"makerbase318\"", strlen("SET_NETWORK 0 psk \"makerbase318\""), replyBuff, &reply_len, wpa_cli_msg_cb);
ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), replyBuff, &reply_len, wpa_cli_msg_cb);
//4.3.4 CLL 修复WiFi刷新bug
ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), replyBuff, &reply_len, NULL );
if (ret == 0) {
replyBuff[reply_len] = '\0';
MKSLOG_YELLOW("返回的消息: %s", replyBuff);
Expand Down Expand Up @@ -819,7 +829,8 @@ int mks_disable_network() {
}

int mks_enable_network() {
// char path[64] = {"\0"};
//4.3.4 CLL 修复WiFi刷新bug
char path[64] = {"\0"};
char cmd[64];

char replyBuff[4096] = {"\0"};
Expand All @@ -841,7 +852,8 @@ int mks_enable_network() {
snprintf(cmd, sizeof(cmd) - 1, "ENABLE_NETWORK 0");
memset(replyBuff, 0x00, sizeof(replyBuff));
reply_len = sizeof(replyBuff) - 1;
ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), replyBuff, &reply_len, wpa_cli_msg_cb);
//4.3.4 CLL 修复WiFi刷新bug
ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), replyBuff, &reply_len, NULL);
if (ret == -2) {
MKSLOG_RED("Command timed out.");
// wpa_ctrl_close(ctrl_conn);
Expand Down Expand Up @@ -876,7 +888,8 @@ int mks_save_config() {
sprintf(cmd, "SAVE_CONFIG");
memset(replyBuff, 0x00, sizeof(replyBuff));
reply_len = sizeof(replyBuff) - 1;
ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), replyBuff, &reply_len, wpa_cli_msg_cb);
//4.3.4 CLL 修复WiFi刷新bug
ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), replyBuff, &reply_len, NULL);
if (ret == -2) {
MKSLOG_RED("Command timed out.");
// wpa_ctrl_close(ctrl_conn);
Expand Down Expand Up @@ -908,8 +921,8 @@ int mks_wpa_cli_open_connection() {
sprintf(path, "/var/run/wpa_supplicant/wlan0");

ctrl_conn = wpa_ctrl_open(path);

if (!ctrl_conn) {
//4.3.4 CLL 修复WiFi刷新bug
if (ctrl_conn) {
mks_wpa_cli_connected = true;
MKSLOG_RED("成功连接wpa connection");
return 0;
Expand Down Expand Up @@ -999,7 +1012,8 @@ int mks_wpa_get_status() {

int ret;
reply_len = sizeof(replyBuff) - 1;
ret = wpa_ctrl_request(ctrl_conn, "STATUS", strlen("STATUS"), replyBuff, &reply_len, wpa_cli_msg_cb);
//4.3.4 CLL 修复WiFi刷新bug
ret = wpa_ctrl_request(ctrl_conn, "STATUS", strlen("STATUS"), replyBuff, &reply_len, NULL);

if (ret == -2) {
printf("Command timed out.\n");
Expand Down
Loading

0 comments on commit d4e3285

Please sign in to comment.