Browse Source

public chat bug fix

pull/2568/head
Christos Themelis 5 months ago
parent
commit
3e4619995e
  1. 14
      examples/simple_secure_chat_ui/main.cpp
  2. 30
      examples/simple_secure_chat_ui/uiManager.cpp
  3. 14
      include/uiConfiguration.h
  4. 1
      include/uiDefines.h
  5. 2
      include/uiExternals.h
  6. 1
      include/uiManager.h
  7. 5
      include/uiVars.h

14
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() { void initializeUI() {
Serial.println("initialize UI..."); Serial.println("initialize UI...");
//ui_init_screen_events();
/* /*
#ifdef ENABLE_STARTUP_LOGO #ifdef ENABLE_STARTUP_LOGO
lv_disp_load_scr(ui_ScreenLogo); lv_disp_load_scr(ui_ScreenLogo);
@ -181,8 +180,7 @@ void initializeUI() {
#endif #endif
*/ */
uiManager = new UIManager(); uiManager = new UIManager();
uiManager->setNightMode(false); uiManager->setNightMode(false);
} }
void createSemaphores() { void createSemaphores() {
@ -296,6 +294,7 @@ class MyMesh : public BaseChatMesh, ContactVisitor {
if (!success) break; // write failed if (!success) break; // write failed
} }
file.close(); file.close();
uiManager->addContactToUI(c);
} }
} }
@ -830,6 +829,13 @@ void setup() {
Serial.println("Setup completed"); Serial.println("Setup completed");
} }
void handleCommand(char *msg)
{
Serial.println("Outgoing data:");
Serial.println(msg);
the_mesh.handleCommand(msg);
}
void core_task(void *pvParameters) { void core_task(void *pvParameters) {
vTaskSuspend(NULL); vTaskSuspend(NULL);

30
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" #define TAG "UIManager"
extern void handleCommand(char *msg);
UIManager::UIManager() { UIManager::UIManager() {
tmp_buf = (char*)malloc(128); 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) { void UIManager::format_datetime(char *buf, size_t size, const struct tm *timeinfo) {
char tmp[64]; char tmp[64];
strftime(tmp, sizeof(tmp), "%a, %d %b %Y", timeinfo); 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) void UIManager::onSendClick(lv_event_t* e)
{ {
char fullMessage[260]; char fullMessage[260];
onHideKeyboard(); char msgCopy[200];
const char* msg = lv_textarea_get_text(ui_ChannelInput); 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, ""); lv_textarea_set_text(ui_ChannelInput, "");
sprintf(fullMessage, "public %s", msg); snprintf(fullMessage, sizeof(fullMessage), "public %s", msgCopy);
//handleCommand(fullMessage); 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) 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); ui_ChannelMessages = lv_list_create(ui_TabPageChannels);
//lv_list_set_options(ui_ChannelMessages, "Contact", LV_list_MODE_NORMAL); //lv_list_set_options(ui_ChannelMessages, "Contact", LV_list_MODE_NORMAL);
lv_obj_set_width(ui_ChannelMessages, 780); 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_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_align(ui_ChannelMessages, LV_ALIGN_CENTER);
lv_obj_set_style_bg_color(ui_ChannelMessages, lv_color_hex(0), 0); 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); lv_obj_set_style_bg_opa(ui_ChannelMessages, LV_OPA_TRANSP, 0);

14
include/uiConfiguration.h

@ -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

1
include/uiDefines.h

@ -1,7 +1,6 @@
#ifndef DEFINES_h #ifndef DEFINES_h
#define DEFINES_h #define DEFINES_h
#include "uiConfiguration.h"
#define BUTTONS_ON_SCREEN 7 #define BUTTONS_ON_SCREEN 7

2
include/uiExternals.h

@ -3,8 +3,6 @@
#include <Arduino.h> #include <Arduino.h>
#include "uiConfiguration.h"
extern void createTasks(); extern void createTasks();
extern TaskHandle_t t_core0_lvgl; extern TaskHandle_t t_core0_lvgl;
extern TaskHandle_t t_core1_clock; extern TaskHandle_t t_core1_clock;

1
include/uiManager.h

@ -14,6 +14,7 @@ class UIManager {
int windSpeedToBeaufort(float speed); int windSpeedToBeaufort(float speed);
void getInitials(const char *name, char *out); void getInitials(const char *name, char *out);
void formatLastSeen(uint32_t ts, char *out, size_t len); 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 // Calendar days and months
static const char *days[7]; static const char *days[7];

5
include/uiVars.h

@ -15,9 +15,6 @@ extern TaskHandle_t t_core1_core;
extern SemaphoreHandle_t semaphoreData; extern SemaphoreHandle_t semaphoreData;
extern UIManager *uiManager; extern UIManager *uiManager;
extern lv_obj_t * ui_MainTabView;
#ifdef USE_MAIN_TAB_VIEW
extern lv_obj_t * ui_MainTabView;
#endif
#endif #endif
Loading…
Cancel
Save