Skip to content

Commit

Permalink
#7 disconnect wifi feature added
Browse files Browse the repository at this point in the history
  • Loading branch information
sainsaji committed Feb 16, 2024
1 parent fdfadb0 commit 9d025c9
Show file tree
Hide file tree
Showing 20 changed files with 39 additions and 95 deletions.
Binary file modified SquareLine_Files/autosave/knobOS_autosave00.zip
Binary file not shown.
Binary file modified SquareLine_Files/autosave/knobOS_autosave01.zip
Binary file not shown.
Binary file modified SquareLine_Files/autosave/knobOS_autosave02.zip
Binary file not shown.
Binary file modified SquareLine_Files/autosave/knobOS_autosave03.zip
Binary file not shown.
Binary file modified SquareLine_Files/autosave/knobOS_autosave04.zip
Binary file not shown.
Binary file modified SquareLine_Files/autosave/knobOS_autosave05.zip
Binary file not shown.
Binary file modified SquareLine_Files/autosave/knobOS_autosave06.zip
Binary file not shown.
Binary file modified SquareLine_Files/autosave/knobOS_autosave08.zip
Binary file not shown.
Binary file modified SquareLine_Files/autosave/knobOS_autosave09.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion SquareLine_Files/knobOS.sll

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions SquareLine_Files/knobOS.spj
Original file line number Diff line number Diff line change
Expand Up @@ -21981,7 +21981,7 @@
{
"nid": 1245589631,
"strtype": "OBJECT/Name",
"strval": "Label1",
"strval": "WiFiConnectBtnLabel",
"InheritedType": 10
},
{
Expand Down Expand Up @@ -27654,7 +27654,7 @@
"theme_color2": 0,
"uiExportFolderPath": "C:\\Users\\sains\\OneDrive\\Documents\\Arduino\\knobOS\\./libraries/ui/src",
"projectExportFolderPath": "C:\\Users\\sains\\OneDrive\\Documents\\Arduino\\knobOS",
"backup_cnt": 354,
"backup_cnt": 366,
"autosave_cnt": 0,
"lvgl_version": "8.3.6",
"callfuncsexport": "C_FILE",
Expand Down
2 changes: 2 additions & 0 deletions libraries/lv_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,8 @@








1 change: 0 additions & 1 deletion libraries/ui/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ SET(SOURCES components/ui_comp_appcomponent.c
components/ui_comp_roundbutton.c
components/ui_comp.c
screens/ui_FlashScreen.c
screens/ui_Changelog.c
screens/ui_HomeScreen.c
screens/ui_AppScreenDisplay.c
screens/ui_LightControl.c
Expand Down
1 change: 0 additions & 1 deletion libraries/ui/src/filelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ components/ui_comp_apptitlecomp.c
components/ui_comp_roundbutton.c
components/ui_comp.c
screens/ui_FlashScreen.c
screens/ui_Changelog.c
screens/ui_HomeScreen.c
screens/ui_AppScreenDisplay.c
screens/ui_LightControl.c
Expand Down
39 changes: 0 additions & 39 deletions libraries/ui/src/screens/ui_Changelog.c

This file was deleted.

2 changes: 2 additions & 0 deletions libraries/ui/src/screens/ui_FlashScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ void ui_FlashScreen_screen_init(void)


lv_obj_add_event_cb(ui_roundButton, ui_event_roundButton_roundButton, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_FlashScreen, ui_event_FlashScreen, LV_EVENT_ALL, NULL);

}
10 changes: 5 additions & 5 deletions libraries/ui/src/screens/ui_SettingsScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ void ui_SettingsScreen_screen_init(void)
lv_obj_add_flag(ui_ConnectToWifiBtn, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags
lv_obj_clear_flag(ui_ConnectToWifiBtn, LV_OBJ_FLAG_SCROLLABLE); /// Flags

ui_Label1 = lv_label_create(ui_ConnectToWifiBtn);
lv_obj_set_width(ui_Label1, LV_SIZE_CONTENT); /// 1
lv_obj_set_height(ui_Label1, LV_SIZE_CONTENT); /// 1
lv_obj_set_align(ui_Label1, LV_ALIGN_CENTER);
lv_label_set_text(ui_Label1, "Connect WiFi");
ui_WiFiConnectBtnLabel = lv_label_create(ui_ConnectToWifiBtn);
lv_obj_set_width(ui_WiFiConnectBtnLabel, LV_SIZE_CONTENT); /// 1
lv_obj_set_height(ui_WiFiConnectBtnLabel, LV_SIZE_CONTENT); /// 1
lv_obj_set_align(ui_WiFiConnectBtnLabel, LV_ALIGN_CENTER);
lv_label_set_text(ui_WiFiConnectBtnLabel, "Connect WiFi");

ui_Image1 = lv_img_create(ui_ConnectToWifiBtn);
lv_img_set_src(ui_Image1, &ui_img_wifi_connected_png);
Expand Down
24 changes: 1 addition & 23 deletions libraries/ui/src/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ void ui_event_roundButton_roundButton(lv_event_t * e);
lv_obj_t * ui_roundButton;


// SCREEN: ui_Changelog
void ui_Changelog_screen_init(void);
void ui_event_Changelog(lv_event_t * e);
lv_obj_t * ui_Changelog;
lv_obj_t * ui_Label4;
lv_obj_t * ui_Label5;


// SCREEN: ui_HomeScreen
void ui_HomeScreen_screen_init(void);
void ui_event_HomeScreen(lv_event_t * e);
Expand Down Expand Up @@ -127,7 +119,7 @@ lv_obj_t * ui_AppTitleComp3;
lv_obj_t * ui_AppControls2;
void ui_event_ConnectToWifiBtn(lv_event_t * e);
lv_obj_t * ui_ConnectToWifiBtn;
lv_obj_t * ui_Label1;
lv_obj_t * ui_WiFiConnectBtnLabel;
lv_obj_t * ui_Image1;
lv_obj_t * ui_AutoConnectPanel;
lv_obj_t * ui_AutoConnectLabel;
Expand Down Expand Up @@ -174,15 +166,6 @@ void ui_event_roundButton_roundButton(lv_event_t * e)
_ui_screen_change(&ui_HomeScreen, LV_SCR_LOAD_ANIM_MOVE_LEFT, 500, 0, &ui_HomeScreen_screen_init);
}
}
void ui_event_Changelog(lv_event_t * e)
{
lv_event_code_t event_code = lv_event_get_code(e);
lv_obj_t * target = lv_event_get_target(e);
if(event_code == LV_EVENT_GESTURE && lv_indev_get_gesture_dir(lv_indev_get_act()) == LV_DIR_LEFT) {
lv_indev_wait_release(lv_indev_get_act());
_ui_screen_change(&ui_HomeScreen, LV_SCR_LOAD_ANIM_MOVE_LEFT, 500, 0, &ui_HomeScreen_screen_init);
}
}
void ui_event_HomeScreen(lv_event_t * e)
{
lv_event_code_t event_code = lv_event_get_code(e);
Expand All @@ -204,10 +187,6 @@ void ui_event_AppScreenDisplay(lv_event_t * e)
{
lv_event_code_t event_code = lv_event_get_code(e);
lv_obj_t * target = lv_event_get_target(e);
if(event_code == LV_EVENT_GESTURE && lv_indev_get_gesture_dir(lv_indev_get_act()) == LV_DIR_RIGHT) {
lv_indev_wait_release(lv_indev_get_act());
_ui_screen_change(&ui_Changelog, LV_SCR_LOAD_ANIM_MOVE_RIGHT, 500, 0, &ui_Changelog_screen_init);
}
if(event_code == LV_EVENT_GESTURE && lv_indev_get_gesture_dir(lv_indev_get_act()) == LV_DIR_BOTTOM) {
lv_indev_wait_release(lv_indev_get_act());
_ui_screen_change(&ui_SettingsScreen, LV_SCR_LOAD_ANIM_MOVE_BOTTOM, 500, 0, &ui_SettingsScreen_screen_init);
Expand Down Expand Up @@ -368,7 +347,6 @@ void ui_init(void)
false, LV_FONT_DEFAULT);
lv_disp_set_theme(dispp, theme);
ui_FlashScreen_screen_init();
ui_Changelog_screen_init();
ui_HomeScreen_screen_init();
ui_AppScreenDisplay_screen_init();
ui_LightControl_screen_init();
Expand Down
8 changes: 1 addition & 7 deletions libraries/ui/src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ extern lv_obj_t * ui_knobosLabel;
extern lv_obj_t * ui_firmwareLabel;
void ui_event_roundButton_roundButton(lv_event_t * e);
extern lv_obj_t * ui_roundButton;
// SCREEN: ui_Changelog
void ui_Changelog_screen_init(void);
void ui_event_Changelog(lv_event_t * e);
extern lv_obj_t * ui_Changelog;
extern lv_obj_t * ui_Label4;
extern lv_obj_t * ui_Label5;
// SCREEN: ui_HomeScreen
void ui_HomeScreen_screen_init(void);
void ui_event_HomeScreen(lv_event_t * e);
Expand Down Expand Up @@ -128,7 +122,7 @@ extern lv_obj_t * ui_AppTitleComp3;
extern lv_obj_t * ui_AppControls2;
void ui_event_ConnectToWifiBtn(lv_event_t * e);
extern lv_obj_t * ui_ConnectToWifiBtn;
extern lv_obj_t * ui_Label1;
extern lv_obj_t * ui_WiFiConnectBtnLabel;
extern lv_obj_t * ui_Image1;
extern lv_obj_t * ui_AutoConnectPanel;
extern lv_obj_t * ui_AutoConnectLabel;
Expand Down
41 changes: 25 additions & 16 deletions ui/ui.ino
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ void socketSend(String dataToSocket)

static void connectWiFi(void *pvParameters) {
lv_obj_t *statusLabel = (lv_obj_t *)pvParameters;
lv_obj_t *WiFiConnectBtnLabel = ui_WiFiConnectBtnLabel;
if(!isConnected)
{
WiFi.mode(WIFI_STA); //Optional
Expand All @@ -157,26 +158,29 @@ static void connectWiFi(void *pvParameters) {
delay(100);
}

if (WiFi.status() == WL_CONNECTED) {
if (WiFi.status() == WL_CONNECTED)
{
DEBUG_PRINTLN("\nConnected to the WiFi network");
DEBUG_PRINT("Local ESP32 IP: ");
DEBUG_PRINTLN(WiFi.localIP());
lv_label_set_text_fmt(statusLabel, "%s", WiFi.localIP().toString());

lv_label_set_text_fmt(statusLabel, "%s", WiFi.localIP().toString());
DEBUG_PRINTLN("\nChange WiFi Action and Label");
lv_label_set_text_fmt(WiFiConnectBtnLabel, "%s", "Disconnect WiFi");
isConnected = true;
} else {
}
else
{
DEBUG_PRINTLN("\nConnection timed out");
lv_label_set_text_fmt(statusLabel, "%s", "Failed!");
// Handle timeout here, for example, retry connection or take appropriate action
}
}


if(isConnected)
{
lv_obj_t *wifiImage = ui_WifiImage;
lv_obj_t *connectButton = ui_ConnectToWifiBtn;
DEBUG_PRINTLN("\nDisabling Button");
lv_obj_clear_state(connectButton,lv_obj_get_state(connectButton));
lv_obj_add_state(connectButton, LV_STATE_DISABLED);
lv_obj_t *connectButton = ui_ConnectToWifiBtn;
lv_img_set_src(wifiImage, &ui_img_wifi_connected_png);
lv_img_set_zoom(wifiImage, 100);
socketSend("Hello Server");
Expand Down Expand Up @@ -211,12 +215,24 @@ void connectToWifiTask(lv_event_t * e)
{
DEBUG_PRINTLN("\n Called Connect to WiFi");
lv_obj_t *wifiStatusLabel = ui_ConnectionStatusLabel;
xTaskCreate(connectWiFi, // Task function
if(!isConnected)
{
xTaskCreate(connectWiFi, // Task function
"LVGL Connect to WiFi Task", // Task name
4096, // Stack size
(void *)wifiStatusLabel, // Task parameters
1, // Priority
NULL); // Task handle (optional)
}
else
{
lv_obj_t *WiFiConnectBtnLabel = ui_WiFiConnectBtnLabel;
WiFi.disconnect();
lv_label_set_text_fmt(WiFiConnectBtnLabel, "%s", "Connect WiFi");
lv_label_set_text_fmt(wifiStatusLabel, "%s", "Disconnected");
isConnected = false;
}

}

void lockLaptopTask(lv_event_t * e)
Expand All @@ -242,13 +258,6 @@ void settingsScreenLoaded(lv_event_t * e)
{
lv_obj_clear_state(autoConnectSwitch,lv_obj_get_state(autoConnectSwitch));
}
if(isConnected)
{
lv_obj_t *connectButton = ui_ConnectToWifiBtn;
DEBUG_PRINTLN("\nDisabling Button");
lv_obj_clear_state(connectButton,lv_obj_get_state(connectButton));
lv_obj_add_state(connectButton, LV_STATE_DISABLED);
}
}


Expand Down

0 comments on commit 9d025c9

Please sign in to comment.