diff --git a/examples/simple_secure_chat_ui/main.cpp b/examples/simple_secure_chat_ui/main.cpp index 81b1c20f4..e752d3716 100644 --- a/examples/simple_secure_chat_ui/main.cpp +++ b/examples/simple_secure_chat_ui/main.cpp @@ -166,8 +166,7 @@ void my_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) void initializeUI() { Serial.println("initialize UI..."); - //ui_init_screen_events(); - + /* #ifdef ENABLE_STARTUP_LOGO lv_disp_load_scr(ui_ScreenLogo); @@ -181,8 +180,7 @@ void initializeUI() { #endif */ uiManager = new UIManager(); - uiManager->setNightMode(false); - + uiManager->setNightMode(false); } void createSemaphores() { @@ -296,6 +294,7 @@ class MyMesh : public BaseChatMesh, ContactVisitor { if (!success) break; // write failed } file.close(); + uiManager->addContactToUI(c); } } @@ -830,6 +829,13 @@ void setup() { Serial.println("Setup completed"); } +void handleCommand(char *msg) +{ + Serial.println("Outgoing data:"); + Serial.println(msg); + the_mesh.handleCommand(msg); +} + void core_task(void *pvParameters) { vTaskSuspend(NULL); diff --git a/examples/simple_secure_chat_ui/uiManager.cpp b/examples/simple_secure_chat_ui/uiManager.cpp index d93f523f8..ba76316c3 100644 --- a/examples/simple_secure_chat_ui/uiManager.cpp +++ b/examples/simple_secure_chat_ui/uiManager.cpp @@ -22,6 +22,8 @@ const char *UIManager::months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", #define TAG "UIManager" +extern void handleCommand(char *msg); + UIManager::UIManager() { tmp_buf = (char*)malloc(128); @@ -36,6 +38,13 @@ UIManager::UIManager() { } +void UIManager::format_time(uint32_t ts, char *buf, size_t len) +{ + time_t t = ts; + struct tm *tm_info = localtime(&t); + strftime(buf, len, "%H:%M:%S", tm_info); +} + void UIManager::format_datetime(char *buf, size_t size, const struct tm *timeinfo) { char tmp[64]; strftime(tmp, sizeof(tmp), "%a, %d %b %Y", timeinfo); @@ -499,15 +508,24 @@ static void s_onSendClick(lv_event_t *e) void UIManager::onSendClick(lv_event_t* e) { char fullMessage[260]; - onHideKeyboard(); + char msgCopy[200]; const char* msg = lv_textarea_get_text(ui_ChannelInput); - if(msg == NULL || strlen(msg) == 0) return; + if(msg == NULL || msg[0] == '\0') return; + + strncpy(msgCopy, msg, sizeof(msgCopy) - 1); + msgCopy[sizeof(msgCopy) - 1] = '\0'; lv_textarea_set_text(ui_ChannelInput, ""); - sprintf(fullMessage, "public %s", msg); - //handleCommand(fullMessage); + snprintf(fullMessage, sizeof(fullMessage), "public %s", msgCopy); + handleCommand(fullMessage); + + char time_buf[16]; + format_time(millis(), time_buf, sizeof(time_buf)); + addChatBubble(time_buf, "Me", msgCopy, true); + + onHideKeyboard(); } static void s_onKeyboardEvent(lv_event_t *e) @@ -684,9 +702,9 @@ void UIManager::ui_Screen1_screen_init(void) ui_ChannelMessages = lv_list_create(ui_TabPageChannels); //lv_list_set_options(ui_ChannelMessages, "Contact", LV_list_MODE_NORMAL); lv_obj_set_width(ui_ChannelMessages, 780); - lv_obj_set_height(ui_ChannelMessages, 260); + lv_obj_set_height(ui_ChannelMessages, 300); lv_obj_set_x(ui_ChannelMessages, 0); - lv_obj_set_y(ui_ChannelMessages, -40); + lv_obj_set_y(ui_ChannelMessages, 0); lv_obj_set_align(ui_ChannelMessages, LV_ALIGN_CENTER); lv_obj_set_style_bg_color(ui_ChannelMessages, lv_color_hex(0), 0); lv_obj_set_style_bg_opa(ui_ChannelMessages, LV_OPA_TRANSP, 0); diff --git a/include/uiConfiguration.h b/include/uiConfiguration.h deleted file mode 100644 index 217735c19..000000000 --- a/include/uiConfiguration.h +++ /dev/null @@ -1,14 +0,0 @@ -////////////// -// Settings // -////////////// -#define USE_MAIN_TAB_VIEW -#ifdef USE_MAIN_TAB_VIEW - //#define SHOW_TABS_AT_LEFT - //#define USE_HOME_PAGE - #define USE_MODULE_SETTINGS -#endif - -///////////// -// Modules // -///////////// -//#define SHOW_TOP_BAR diff --git a/include/uiDefines.h b/include/uiDefines.h index ce1d231a1..79a57e13d 100644 --- a/include/uiDefines.h +++ b/include/uiDefines.h @@ -1,7 +1,6 @@ #ifndef DEFINES_h #define DEFINES_h -#include "uiConfiguration.h" #define BUTTONS_ON_SCREEN 7 diff --git a/include/uiExternals.h b/include/uiExternals.h index 6e6508ad4..0928fd3a9 100644 --- a/include/uiExternals.h +++ b/include/uiExternals.h @@ -3,8 +3,6 @@ #include -#include "uiConfiguration.h" - extern void createTasks(); extern TaskHandle_t t_core0_lvgl; extern TaskHandle_t t_core1_clock; diff --git a/include/uiManager.h b/include/uiManager.h index 17425104c..7805dfc71 100644 --- a/include/uiManager.h +++ b/include/uiManager.h @@ -14,6 +14,7 @@ class UIManager { int windSpeedToBeaufort(float speed); void getInitials(const char *name, char *out); void formatLastSeen(uint32_t ts, char *out, size_t len); + void format_time(uint32_t ts, char *buf, size_t len); // Calendar days and months static const char *days[7]; diff --git a/include/uiVars.h b/include/uiVars.h index 74a5e395b..84069e152 100644 --- a/include/uiVars.h +++ b/include/uiVars.h @@ -15,9 +15,6 @@ extern TaskHandle_t t_core1_core; extern SemaphoreHandle_t semaphoreData; extern UIManager *uiManager; - -#ifdef USE_MAIN_TAB_VIEW - extern lv_obj_t * ui_MainTabView; -#endif +extern lv_obj_t * ui_MainTabView; #endif \ No newline at end of file