From dd52051b75f50a3d2aada56f42a347068a149345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominic=20H=C3=B6glinger?= Date: Sun, 14 Sep 2025 09:45:41 +0200 Subject: [PATCH] ChripChatter: Uncomment all old LoRa API --- .../app/chirpchatter/ChirpChatterApp.cpp | 530 +++++++++++++++++- 1 file changed, 505 insertions(+), 25 deletions(-) diff --git a/Tactility/Source/app/chirpchatter/ChirpChatterApp.cpp b/Tactility/Source/app/chirpchatter/ChirpChatterApp.cpp index 7d44c24f..e759db08 100644 --- a/Tactility/Source/app/chirpchatter/ChirpChatterApp.cpp +++ b/Tactility/Source/app/chirpchatter/ChirpChatterApp.cpp @@ -3,13 +3,17 @@ #include #include #include -//#include +#include +#include #include "Tactility/lvgl/LvglSync.h" #include #include -//#include +#include +#include +#include +#include #include extern const lv_obj_class_t lv_label_class; @@ -28,9 +32,10 @@ enum CCViews class ChirpChatterApp; template -static void changeView(lv_event_t* e) { +static void changeViewHandler(lv_event_t* e) { auto* self = static_cast(lv_event_get_user_data(e)); TT_LOG_I(TAG, "Clicked %d", view); + self->changeView(view); } static void buttonRecolorFocus(lv_event_t *event) { @@ -47,6 +52,363 @@ static void buttonRecolorDefocus(lv_event_t *event) { } } +static void debugFocus(lv_event_t *event) { + lv_obj_t *target = (lv_obj_t *)lv_event_get_current_target(event); + if (target != NULL) { + lv_obj_set_style_bg_color(target, lv_color_hex(0xFF0000), 0); + } +} + +static void debugDefocus(lv_event_t *event) { + lv_obj_t *target = (lv_obj_t *)lv_event_get_current_target(event); + if (target != NULL) { + lv_obj_set_style_bg_color(target, lv_color_hex(0x00FF00), 0); + } +} + +class LoraView { +public: + using DeviceActivationCallback = std::function; +private: + //using LoraParameters = tt::hal::lora::LoraParameters; + + std::vector loraDevNames; + + DeviceActivationCallback cbDevActive; + DeviceActivationCallback cbDevInactive; + + std::vector getLoraDevNames() { + std::vector lora_names; + /*size_t dev_index = 0; + + std::vector lora_configs; + loraService->getLoraConfigurations(lora_configs); + + for (const auto& lora_config: lora_configs) { + std::string name(lora_config.name); + if (!name.empty()) { + lora_names.push_back(name); + } else { + std::stringstream stream; + stream << "Device " << std::to_string(dev_index); + lora_names.push_back(stream.str()); + } + dev_index++; + }*/ + return lora_names; + } + + lv_obj_t* initDropdownInput(int row, const char* const label, const char* const items) { + lv_obj_t* label_obj = lv_label_create(container); + lv_label_set_text(label_obj, label); + lv_obj_set_grid_cell(label_obj, + LV_GRID_ALIGN_STRETCH, 0, 1, + LV_GRID_ALIGN_CENTER, row, 1); + lv_obj_set_size(label_obj, lv_pct(100), LV_SIZE_CONTENT); + + lv_obj_t* input = lv_dropdown_create(container); + lv_obj_set_grid_cell(input, + LV_GRID_ALIGN_STRETCH, 1, 1, + LV_GRID_ALIGN_CENTER, row, 1); + lv_obj_set_size(input, lv_pct(100), LV_SIZE_CONTENT); + lv_dropdown_set_options(input, items); + + return input; + } + + lv_obj_t* initFormInput(int row, const char* const label, const char* const defval, const char* const unit) { + lv_obj_t* label_obj = lv_label_create(container); + lv_label_set_text(label_obj, label); + lv_obj_set_grid_cell(label_obj, + LV_GRID_ALIGN_STRETCH, 0, 1, + LV_GRID_ALIGN_CENTER, row, 1); + lv_obj_set_size(label_obj, lv_pct(100), LV_SIZE_CONTENT); + + lv_obj_t* input = lv_textarea_create(container); + lv_obj_set_grid_cell(input, + LV_GRID_ALIGN_STRETCH, 1, 1, + LV_GRID_ALIGN_CENTER, row, 1); + lv_obj_set_size(input, lv_pct(100), LV_SIZE_CONTENT); + lv_textarea_set_text(input, defval); + lv_textarea_set_one_line(input, true); + + lv_obj_t* unit_obj = lv_label_create(container); + lv_label_set_text(unit_obj, unit); + lv_obj_set_grid_cell(unit_obj, + LV_GRID_ALIGN_STRETCH, 2, 1, + LV_GRID_ALIGN_CENTER, row, 1); + lv_obj_set_size(unit_obj, lv_pct(100), LV_SIZE_CONTENT); + lv_obj_set_style_text_align(unit_obj , LV_TEXT_ALIGN_CENTER, 0); + + return input; + } + + lv_obj_t* initSliderInput(int row, const char* const label, int min, int max, int defval) { + lv_obj_t* label_obj = lv_label_create(container); + lv_label_set_text(label_obj, label); + lv_obj_set_grid_cell(label_obj, + LV_GRID_ALIGN_STRETCH, 0, 1, + LV_GRID_ALIGN_CENTER, row, 1); + lv_obj_set_size(label_obj, lv_pct(100), LV_SIZE_CONTENT); + + lv_obj_t* input = lv_slider_create(container); + lv_obj_set_grid_cell(input, + LV_GRID_ALIGN_STRETCH, 1, 1, + LV_GRID_ALIGN_CENTER, row, 1); + lv_obj_set_size(input, lv_pct(100), 10); + lv_slider_set_range(input, min, max); + + lv_obj_t* number_obj = lv_label_create(container); + //lv_label_set_text(number_obj, unit); + lv_obj_set_grid_cell(number_obj, + LV_GRID_ALIGN_STRETCH, 2, 1, + LV_GRID_ALIGN_CENTER, row, 1); + lv_obj_set_size(number_obj, lv_pct(100), LV_SIZE_CONTENT); + lv_obj_set_style_text_align(number_obj , LV_TEXT_ALIGN_CENTER, 0); + char buf[8] = {0}; + lv_snprintf(buf, sizeof(buf), "%d", defval); + lv_label_set_text(number_obj, buf); + + lv_obj_add_event_cb(input, [](lv_event_t * e) { + lv_obj_t* slider = lv_event_get_target_obj(e); + lv_obj_t* label = (lv_obj_t*)lv_event_get_user_data(e); + char buf[8] = {0}; + lv_snprintf(buf, sizeof(buf), "%d", (int)lv_slider_get_value(slider)); + lv_label_set_text(label, buf); + }, LV_EVENT_VALUE_CHANGED, number_obj); + + lv_slider_set_value(input, defval, LV_ANIM_OFF); + + return input; + } + + void initUi(lv_obj_t *parent) { + container = lv_obj_create(parent); + lv_obj_set_size(container, lv_pct(100), lv_pct(100)); + lv_obj_set_style_pad_all(container, 0, 0); + + int grid_row_size = 40; + static lv_coord_t lora_col_dsc[] = {LV_GRID_FR(3), LV_GRID_FR(2), 45, LV_GRID_TEMPLATE_LAST}; + static lv_coord_t lora_row_dsc[] = { + grid_row_size, + grid_row_size, + grid_row_size, + grid_row_size, + grid_row_size, + grid_row_size, + grid_row_size, + grid_row_size, + LV_GRID_TEMPLATE_LAST}; + lv_obj_set_grid_dsc_array(container, lora_col_dsc, lora_row_dsc); + + std::string dropdown_items = string::join(loraDevNames, "\n"); + loraDeviceInput = initDropdownInput(0, "LoRa Device", dropdown_items.c_str()); + loraDeviceOn = lv_switch_create(container); + lv_obj_set_grid_cell(loraDeviceOn, + LV_GRID_ALIGN_STRETCH, 2, 1, + LV_GRID_ALIGN_CENTER, 0, 1); + lv_obj_set_size(loraDeviceOn, lv_pct(100), 20); + + frequencyInput = initFormInput(1, "Frequency", "869.525", "MHz"); + bandwidthInput = initFormInput(2, "Bandwidth", "250", "kHz"); + syncwordInput = initFormInput(3, "Sync Word", "2B", "hex"); + deBitsInput = initSliderInput(4, "DE Bits", 0, 4, 2); + sfInput = initSliderInput(5, "Spread Factor", 7, 12, 11); + preambleChirpsInput = initSliderInput(6, "Preamble Chirps", 4, 32, 16); + txPowInput = initFormInput(7, "TX Power", "27", "dBm"); + /* + lv_obj_add_event_cb(frequencyInput, [](lv_event_t * e) { + lv_obj_t* input = lv_event_get_target_obj(e); + LoraParameters* params = (LoraParameters*)lv_event_get_user_data(e); + std::string buf(lv_textarea_get_text(input)); + if (!buf.empty()) { + params->frequency = std::stof(buf); + } + }, LV_EVENT_VALUE_CHANGED, &loraParams); + + lv_obj_add_event_cb(bandwidthInput, [](lv_event_t * e) { + lv_obj_t* input = lv_event_get_target_obj(e); + LoraParameters* params = (LoraParameters*)lv_event_get_user_data(e); + std::string buf(lv_textarea_get_text(input)); + if (!buf.empty()) { + params->bandwidth = std::stof(buf); + } + }, LV_EVENT_VALUE_CHANGED, &loraParams); + + lv_obj_add_event_cb(syncwordInput, [](lv_event_t * e) { + lv_obj_t* input = lv_event_get_target_obj(e); + LoraParameters* params = (LoraParameters*)lv_event_get_user_data(e); + std::string buf(lv_textarea_get_text(input)); + if (!buf.empty()) { + std::stringstream ss; + ss << std::hex << buf; + ss >> params->syncWord; + } + }, LV_EVENT_VALUE_CHANGED, &loraParams); + + lv_obj_add_event_cb(preambleChirpsInput, [](lv_event_t * e) { + lv_obj_t* input = lv_event_get_target_obj(e); + LoraParameters* params = (LoraParameters*)lv_event_get_user_data(e); + params->preambleLength = lv_slider_get_value(input); + }, LV_EVENT_VALUE_CHANGED, &loraParams); + + lv_obj_add_event_cb(deBitsInput, [](lv_event_t * e) { + lv_obj_t* input = lv_event_get_target_obj(e); + LoraParameters* params = (LoraParameters*)lv_event_get_user_data(e); + params->deBits = lv_slider_get_value(input); + }, LV_EVENT_VALUE_CHANGED, &loraParams); + + lv_obj_add_event_cb(sfInput, [](lv_event_t * e) { + lv_obj_t* input = lv_event_get_target_obj(e); + LoraParameters* params = (LoraParameters*)lv_event_get_user_data(e); + params->spreadFactor = lv_slider_get_value(input); + }, LV_EVENT_VALUE_CHANGED, &loraParams); + + lv_obj_add_event_cb(txPowInput, [](lv_event_t * e) { + lv_obj_t* input = lv_event_get_target_obj(e); + LoraParameters* params = (LoraParameters*)lv_event_get_user_data(e); + std::string buf(lv_textarea_get_text(input)); + if (!buf.empty()) { + params->power = std::stoi(buf); + } + }, LV_EVENT_VALUE_CHANGED, &loraParams); + */ + /* + if (loraDevNames.size() > 0) { + loraDevice = loraService->getDevice(loraDevNames[0]); + if (loraDevice) + { + using State = hal::lora::LoraDevice::State; + switch (loraDevice->getState()) { + case State::PendingOn: + case State::On: + setParameters(loraDevice->getParameters()); + disableForm(); + lv_obj_add_state(loraDeviceOn, LV_STATE_CHECKED); + break; + case State::Error: + case State::PendingOff: + case State::Off: + default: + break; + } + } else { + TT_LOG_E(TAG, "Attempted to load device \"%s\", what is happening!?", loraDevNames[0].c_str()); + } + }*/ + + lv_obj_add_event_cb(loraDeviceOn, [](lv_event_t * e) { + lv_obj_t* input = lv_event_get_target_obj(e); + LoraView* self = (LoraView*)lv_event_get_user_data(e); + if (lv_obj_has_state(input, LV_STATE_CHECKED)) { + self->enableDevice(); + } else { + self->disableDevice(); + } + }, LV_EVENT_VALUE_CHANGED, this); + + } + + void disableForm() + { + lv_obj_add_state(loraDeviceInput, LV_STATE_DISABLED); + lv_obj_add_state(frequencyInput, LV_STATE_DISABLED); + lv_obj_add_state(bandwidthInput, LV_STATE_DISABLED); + lv_obj_add_state(syncwordInput, LV_STATE_DISABLED); + lv_obj_add_state(deBitsInput, LV_STATE_DISABLED); + lv_obj_add_state(preambleChirpsInput, LV_STATE_DISABLED); + lv_obj_add_state(txPowInput, LV_STATE_DISABLED); + } + + void enableForm() + { + lv_obj_clear_state(loraDeviceInput, LV_STATE_DISABLED); + lv_obj_clear_state(frequencyInput, LV_STATE_DISABLED); + lv_obj_clear_state(bandwidthInput, LV_STATE_DISABLED); + lv_obj_clear_state(syncwordInput, LV_STATE_DISABLED); + lv_obj_clear_state(deBitsInput, LV_STATE_DISABLED); + lv_obj_clear_state(preambleChirpsInput, LV_STATE_DISABLED); + lv_obj_clear_state(txPowInput, LV_STATE_DISABLED); + } + +public: + //std::shared_ptr loraDevice; + lv_obj_t* container; + lv_obj_t* loraDeviceOn; + lv_obj_t* loraDeviceInput; + lv_obj_t* frequencyInput; + lv_obj_t* bandwidthInput; + lv_obj_t* syncwordInput; + lv_obj_t* deBitsInput; + lv_obj_t* sfInput; + lv_obj_t* preambleChirpsInput; + lv_obj_t* txPowInput; + + LoraView(lv_obj_t *parent) { + loraDevNames = getLoraDevNames(); + initUi(parent); + /* + setParameters(LoraParameters { + .spreadFactor = 11, + .deBits = 2, + .syncWord = 0x2B, + .preambleLength = 8, + .power = 22, + .tcxoVoltage = 3.0, + .frequency = 869.525, + .bandwidth = 250.0 + });*/ + } + + void onDeviceActivation(DeviceActivationCallback cb) { + cbDevActive = cb; + } + + void onDeviceDeactivation(DeviceActivationCallback cb) { + cbDevInactive = cb; + } + /* + void setParameters(LoraParameters params) { + std::string buf; + loraParams = params; + + buf = std::format("{:.6f}", loraParams.frequency); + lv_textarea_set_text(frequencyInput, buf.c_str()); + buf = std::format("{:.2f}", loraParams.bandwidth); + lv_textarea_set_text(bandwidthInput, buf.c_str()); + buf = std::format("{:X}", loraParams.syncWord); + lv_textarea_set_text(syncwordInput, buf.c_str()); + lv_slider_set_value(preambleChirpsInput, loraParams.preambleLength, LV_ANIM_OFF); + lv_slider_set_value(deBitsInput, loraParams.deBits, LV_ANIM_OFF); + lv_slider_set_value(sfInput, loraParams.spreadFactor, LV_ANIM_OFF); + buf = std::format("{:d}", loraParams.power); + lv_textarea_set_text(txPowInput, buf.c_str()); + }*/ + + void enableDevice() + { + /* + loraDevice = loraService->getDevice(loraDevNames[lv_dropdown_get_selected(loraDeviceInput)]); + if (loraDevice) { + disableForm(); + loraDevice->start(loraParams); + cbDevActive(*loraDevice); + } else { + lv_obj_clear_state(loraDeviceOn, LV_STATE_CHECKED); + }*/ + } + + void disableDevice() + {/* + if (loraDevice) { + loraDevice->stop(); + cbDevInactive(*loraDevice); + } + enableForm(); + */ + } +}; + class ChirpChatterApp : public App { lv_obj_t* sidebar = nullptr; @@ -56,6 +418,11 @@ class ChirpChatterApp : public App { lv_obj_t* messageList = nullptr; lv_obj_t* inputField = nullptr; + lv_obj_t* messageView = nullptr; + LoraView* loraView = nullptr; + + hal::radio::RadioDevice::RxSubscriptionId rxSubId; + template lv_obj_t* createSidebarButton(lv_obj_t* parent, const char* image_file) { auto* sidebar_button = lv_button_create(parent); @@ -81,8 +448,8 @@ class ChirpChatterApp : public App { lv_obj_add_style(sidebar_button, &style_focus, LV_PART_MAIN | LV_STATE_FOCUSED | LV_STATE_FOCUS_KEY); lv_obj_add_style(button_image, &style_focus, LV_PART_MAIN | LV_STATE_FOCUSED | LV_STATE_FOCUS_KEY); - lv_obj_add_event_cb(button_image, changeView, LV_EVENT_SHORT_CLICKED, (void*)this); - lv_obj_add_event_cb(sidebar_button, changeView, LV_EVENT_SHORT_CLICKED, (void*)this); + lv_obj_add_event_cb(button_image, changeViewHandler, LV_EVENT_SHORT_CLICKED, (void*)this); + lv_obj_add_event_cb(sidebar_button, changeViewHandler, LV_EVENT_SHORT_CLICKED, (void*)this); lv_obj_add_event_cb(sidebar_button, buttonRecolorFocus, LV_EVENT_FOCUSED, button_image); lv_obj_add_event_cb(sidebar_button, buttonRecolorDefocus, LV_EVENT_DEFOCUSED, button_image); @@ -95,6 +462,7 @@ class ChirpChatterApp : public App { lv_obj_set_flex_flow(msg_container, LV_FLEX_FLOW_COLUMN); lv_obj_set_flex_grow(msg_container, 0); lv_obj_set_style_pad_all(msg_container, 1, 0); + lv_obj_add_flag(msg_container, LV_OBJ_FLAG_CLICKABLE); lv_obj_t* msg_label = lv_label_create(msg_container); lv_label_set_text(msg_label, message); @@ -117,6 +485,54 @@ class ChirpChatterApp : public App { lv_obj_scroll_to_y(messageList, lv_obj_get_scroll_y(messageList) + 1000, LV_ANIM_ON); + /*auto* group = lv_group_get_default(); + lv_group_add_obj(group, msg_container);*/ + } + + void addPacketMessage(const hal::radio::RxPacket& packet) { + auto* msg_container = lv_obj_create(messageList); + lv_obj_set_flex_flow(msg_container, LV_FLEX_FLOW_COLUMN); + lv_obj_set_flex_grow(msg_container, 0); + lv_obj_set_style_pad_all(msg_container, 1, 0); + lv_obj_add_flag(msg_container, LV_OBJ_FLAG_CLICKABLE); + + lv_obj_t* msg_label = lv_label_create(msg_container); + + std::string buf((char*)packet.data, packet.size); + + lv_label_set_text(msg_label, buf.c_str()); + lv_obj_set_width(msg_label, lv_pct(100)); + lv_label_set_long_mode(msg_label, LV_LABEL_LONG_WRAP); + lv_obj_set_style_text_align(msg_label, LV_TEXT_ALIGN_LEFT, 0); + lv_obj_set_style_pad_all(msg_label, 0, 0); + + lv_obj_t* msg_info = lv_label_create(msg_container); + + auto t = std::time(nullptr); + auto tm = *std::localtime(&t); + std::stringstream ss; + ss << "RX/RAW "; + ss << std::put_time(&tm, "%Y-%m-%d %H:%M:%S"); + ss << " "; + ss << "RSSI:" << packet.rssi; + ss << " "; + ss << "SNR:" << packet.snr; + + lv_label_set_text(msg_info, ss.str().c_str()); + lv_obj_set_width(msg_info, lv_pct(100)); + lv_label_set_long_mode(msg_info, LV_LABEL_LONG_WRAP); + lv_obj_set_style_text_align(msg_info, LV_TEXT_ALIGN_LEFT, 0); + lv_obj_set_style_pad_all(msg_info, 0, 0); + lv_obj_set_style_text_font(msg_info, &lv_font_montserrat_10, 0); + + + lv_obj_set_width(msg_container, lv_pct(100)); + lv_obj_set_height(msg_container, LV_SIZE_CONTENT); + + lv_obj_scroll_to_y(messageList, lv_obj_get_scroll_y(messageList) + 1000, LV_ANIM_ON); + + /*auto* group = lv_group_get_default(); + * lv_group_add_obj(group, msg_container);*/ } public: @@ -133,11 +549,11 @@ public: void onShow(AppContext& context, lv_obj_t* parent) override { - static lv_coord_t col_dsc[] = {36, LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; - static lv_coord_t row_dsc[] = {40, LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; + static lv_coord_t grid_col_dsc[] = {36, LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; + static lv_coord_t grid_row_dsc[] = {40, LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; lv_obj_t * grid = lv_obj_create(parent); - lv_obj_set_grid_dsc_array(grid, col_dsc, row_dsc); + lv_obj_set_grid_dsc_array(grid, grid_col_dsc, grid_row_dsc); lv_obj_set_size(grid, lv_pct(100), lv_pct(100)); static lv_style_t style_grid; @@ -185,7 +601,7 @@ public: // Main view - mainView = lv_obj_create(grid); + /*mainView = lv_obj_create(grid); lv_obj_set_size(mainView, lv_pct(100), lv_pct(100)); lv_obj_set_grid_cell(mainView, LV_GRID_ALIGN_STRETCH, 1, 1, LV_GRID_ALIGN_STRETCH, 1, 1); @@ -193,24 +609,43 @@ public: lv_obj_set_style_bg_color(mainView, lv_color_hex(0x00FF00), 0); lv_obj_set_style_border_width(mainView, 0, 0); lv_obj_set_style_pad_all(mainView, 0, 0); - + */ // Message view - auto* msg_view = lv_obj_create(mainView); - //lv_obj_set_size(msg_view, lv_disp_get_hor_res(NULL) - 40, lv_disp_get_ver_res(NULL) - toolbar_height*2); - lv_obj_set_size(msg_view, lv_pct(100), lv_pct(100)); - lv_obj_set_flex_flow(msg_view, LV_FLEX_FLOW_COLUMN); - //lv_obj_set_flex_grow(msg_view, 1); - lv_obj_set_style_pad_all(msg_view, 0, 0); - messageList = lv_obj_create(msg_view); + messageView = lv_obj_create(grid); + //lv_obj_set_size(messageView, lv_disp_get_hor_res(NULL) - 40, lv_disp_get_ver_res(NULL) - toolbar_height*2); + lv_obj_set_size(messageView, lv_pct(100), lv_pct(100)); + //lv_obj_set_flex_flow(messageView, LV_FLEX_FLOW_COLUMN); + //lv_obj_set_flex_grow(messageView, 1); + lv_obj_set_size(messageView, lv_pct(100), lv_pct(100)); + lv_obj_set_grid_cell(messageView, LV_GRID_ALIGN_STRETCH, 1, 1, + LV_GRID_ALIGN_STRETCH, 1, 1); + + lv_obj_set_style_pad_all(messageView, 0, 0); + + + messageList = lv_obj_create(messageView); lv_obj_set_size(messageList, lv_pct(100), lv_pct(80)); lv_obj_set_flex_flow(messageList, LV_FLEX_FLOW_COLUMN); lv_obj_align(messageList, LV_ALIGN_TOP_MID, 0, 0); - lv_obj_set_style_bg_color(mainView, lv_color_hex(0xFF0000), 0); + ///lv_obj_set_style_bg_color(mainView, lv_color_hex(0xFF0000), 0); lv_obj_set_style_border_width(messageList, 0, 0); lv_obj_set_style_pad_all(messageList, 0, 0); + lv_obj_add_flag(messageList, (lv_obj_flag_t)(LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLL_ON_FOCUS)); + auto* group = lv_group_get_default(); + lv_group_add_obj(group, messageList); + + lv_obj_add_event_cb(messageList, buttonRecolorFocus, LV_EVENT_FOCUSED, nullptr); + lv_obj_add_event_cb(messageList, buttonRecolorDefocus, LV_EVENT_DEFOCUSED, nullptr); + + /* + messageList = lv_page_create(messageView, nullptr); + lv_obj_set_size(messageList, lv_pct(100), lv_pct(80)); + lv_obj_set_style_border_width(messageList, 0, 0); + lv_obj_set_style_pad_all(messageList, 0, 0); + */ // Input panel - auto* input_panel = lv_obj_create(msg_view); + auto* input_panel = lv_obj_create(messageView); lv_obj_set_flex_flow(input_panel, LV_FLEX_FLOW_ROW); lv_obj_set_size(input_panel, lv_pct(100), LV_SIZE_CONTENT); lv_obj_align(input_panel, LV_ALIGN_BOTTOM_MID, 0, 0); @@ -236,13 +671,58 @@ public: lv_obj_set_flex_grow(messageList, 1); lv_obj_set_flex_grow(input_panel, 0); - lv_obj_set_style_bg_color(messageList, lv_color_hex(0xFF0000), 0); - lv_obj_set_style_bg_color(input_panel, lv_color_hex(0x00FF00), 0); + //lv_obj_set_style_bg_color(messageList, lv_color_hex(0xFF0000), 0); + //lv_obj_set_style_bg_color(input_panel, lv_color_hex(0x00FF00), 0); - addDummyMessage("HELLO CHIRPCHAT!"); - addDummyMessage("How's biz?"); - addDummyMessage("Test"); - addDummyMessage("Test empfangen in Linz"); + //addDummyMessage("HELLO CHIRPCHAT!"); + //addDummyMessage("How's biz?"); + //addDummyMessage("Test"); + //addDummyMessage("Test empfangen in Linz"); + + // LoRa settings view + loraView = new LoraView(grid); + lv_obj_set_grid_cell(loraView->container, LV_GRID_ALIGN_STRETCH, 1, 1, + LV_GRID_ALIGN_STRETCH, 1, 1); + + //loraView->onDeviceActivation(std::bind(&ChirpChatterApp::onDeviceActivation, this)); + //loraView->onDeviceDeactivation(std::bind(&ChirpChatterApp::onDeviceDeactivation, this)); + + //loraView->onDeviceActivation([this](hal::lora::LoraDevice& dev) { this->onDeviceActivation(dev); }); + //loraView->onDeviceDeactivation([this](hal::lora::LoraDevice& dev) { this->onDeviceDeactivation(dev); }); + + changeView(CCView_Msgs); + } + + void onRxPacket(hal::Device::Id id, const hal::radio::RxPacket& packet) { + addPacketMessage(packet); + } + + void onDeviceActivation(hal::radio::RadioDevice& dev) { + //rxSubId = dev.subscribeRx(std::bind(&ChirpChatterApp::onRxPacket, this)); + rxSubId = dev.subscribeRx([this](hal::Device::Id id, const hal::radio::RxPacket& packet) { + this->onRxPacket(id, packet); + }); + } + + void onDeviceDeactivation(hal::radio::RadioDevice& dev) { + dev.unsubscribeRx(rxSubId); + } + + void changeView(const CCViews view) { + lv_obj_add_flag(messageView, LV_OBJ_FLAG_HIDDEN); + lv_obj_add_flag(loraView->container, LV_OBJ_FLAG_HIDDEN); + + switch (view) { + case CCView_Msgs: + lv_obj_clear_flag(messageView, LV_OBJ_FLAG_HIDDEN); + break; + case CCView_LoraSettings: + lv_obj_clear_flag(loraView->container, LV_OBJ_FLAG_HIDDEN); + break; + default: + break; + + } } ~ChirpChatterApp() override = default;