diff --git a/applications/plugins/ifttt/ifttt_virtual_button.c b/applications/plugins/ifttt/ifttt_virtual_button.c index 35baaa0b0..a2544b272 100644 --- a/applications/plugins/ifttt/ifttt_virtual_button.c +++ b/applications/plugins/ifttt/ifttt_virtual_button.c @@ -1,5 +1,150 @@ #include "ifttt_virtual_button.h" +#define IFTTT_FOLDER "/ext/ifttt" +#define IFTTT_CONFIG_FOLDER "/ext/ifttt/config" +const char *CONFIG_FILE_PATH = "/ext/ifttt/config/config.settings"; + +#define FLIPPERZERO_SERIAL_BAUD 115200 +typedef enum ESerialCommand { ESerialCommand_Config } ESerialCommand; + +Settings save_settings(Settings settings) { + Storage *storage = furi_record_open(RECORD_STORAGE); + FlipperFormat *file = flipper_format_file_alloc(storage); + if (flipper_format_file_open_existing(file, CONFIG_FILE_PATH)) { + flipper_format_update_string_cstr(file, CONF_SSID, settings.save_ssid); + flipper_format_update_string_cstr(file, CONF_PASSWORD, settings.save_password); + flipper_format_update_string_cstr(file, CONF_KEY, settings.save_key); + flipper_format_update_string_cstr(file, CONF_EVENT, settings.save_event); + }else{ + } + flipper_format_file_close(file); + flipper_format_free(file); + furi_record_close(RECORD_STORAGE); + return settings; +} + +void save_settings_file(FlipperFormat *file, Settings *settings) { + flipper_format_write_header_cstr(file, CONFIG_FILE_HEADER, CONFIG_FILE_VERSION); + flipper_format_write_comment_cstr(file, "Enter here the SSID of the wifi network"); + flipper_format_write_string_cstr(file, CONF_SSID, settings->save_ssid); + flipper_format_write_comment_cstr(file, "Enter here the PASSWORD of the wifi network"); + flipper_format_write_string_cstr(file, CONF_PASSWORD, settings->save_password); + flipper_format_write_comment_cstr(file, "Enter here the WEBHOOKS of your IFTTT account"); + flipper_format_write_string_cstr(file, CONF_KEY, settings->save_key); + flipper_format_write_comment_cstr(file, "Enter here the EVENT name of your trigger"); + flipper_format_write_string_cstr(file, CONF_EVENT, settings->save_event); +} + +Settings *load_settings() { + Settings *settings=malloc(sizeof(Settings)); + + Storage *storage = furi_record_open(RECORD_STORAGE); + FlipperFormat *file = flipper_format_file_alloc(storage); + + FuriString *string_value; + string_value = furi_string_alloc(); + FuriString *text_ssid_value; + text_ssid_value = furi_string_alloc(); + FuriString *text_password_value; + text_password_value = furi_string_alloc(); + FuriString *text_key_value; + text_key_value = furi_string_alloc(); + FuriString *text_event_value; + text_event_value = furi_string_alloc(); + + if (storage_common_stat(storage, CONFIG_FILE_PATH, NULL) != FSE_OK) { + if (!flipper_format_file_open_new(file, CONFIG_FILE_PATH)) { + flipper_format_file_close(file); + } else { + settings->save_ssid = malloc( 1); + settings->save_password = malloc( 1); + settings->save_key = malloc( 1); + settings->save_event = malloc( 1); + + settings->save_ssid[0]='\0'; + settings->save_password[0]='\0'; + settings->save_key[0]='\0'; + settings->save_event[0]='\0'; + + save_settings_file(file, settings); + flipper_format_file_close(file); + } + } else { + if (!flipper_format_file_open_existing(file, CONFIG_FILE_PATH)) { + flipper_format_file_close(file); + } else { + uint32_t value; + if (!flipper_format_read_header(file, string_value, &value)) { + } else { + if (flipper_format_read_string(file, CONF_SSID, text_ssid_value)) { + settings->save_ssid = malloc(furi_string_size(text_ssid_value) + 1); + strcpy(settings->save_ssid, furi_string_get_cstr(text_ssid_value)); + } + if (flipper_format_read_string(file, CONF_PASSWORD, text_password_value)) { + settings->save_password = malloc(furi_string_size(text_password_value) + 1); + strcpy(settings->save_password, furi_string_get_cstr(text_password_value)); + } + if (flipper_format_read_string(file, CONF_KEY, text_key_value)) { + settings->save_key = malloc(furi_string_size(text_key_value) + 1); + strcpy(settings->save_key, furi_string_get_cstr(text_key_value)); + } + if (flipper_format_read_string(file, CONF_EVENT, text_event_value)) { + settings->save_event = malloc(furi_string_size(text_event_value) + 1); + strcpy(settings->save_event, furi_string_get_cstr(text_event_value)); + } + } + flipper_format_file_close(file); + } + } + + furi_string_free(text_ssid_value); + furi_string_free(text_password_value); + furi_string_free(text_key_value); + furi_string_free(text_event_value); + flipper_format_free(file); + furi_record_close(RECORD_STORAGE); + return settings; +} + +void send_serial_command_config(ESerialCommand command, Settings *settings) { + uint8_t data[1] = {0}; + + char config_tmp[100]; + strcpy(config_tmp,"config,"); + strcat(config_tmp, settings->save_key); + char config_tmp2[5]; + strcpy(config_tmp2, config_tmp); + strcat(config_tmp2,","); + char config_tmp3[100]; + strcpy(config_tmp3, config_tmp2); + strcat(config_tmp3,settings->save_ssid); + char config_tmp4[5]; + strcpy(config_tmp4, config_tmp3); + strcat(config_tmp4,","); + char config_tmp5[100]; + strcpy(config_tmp5, config_tmp4); + strcat(config_tmp5,settings->save_password); + char config_tmp6[5]; + strcpy(config_tmp6, config_tmp5); + strcat(config_tmp6,","); + char config[350]; + strcpy(config, config_tmp6); + strcat(config,settings->save_event); + + int length = strlen(config); + for (int i = 0; i < length; i++){ + switch(command) { + case ESerialCommand_Config: + data[0] = config[i]; + break; + default: + return; + }; + + furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1); + } +} + static bool ifttt_virtual_button_custom_event_callback(void* context, uint32_t event) { furi_assert(context); VirtualButtonApp* app = context; @@ -43,21 +188,11 @@ VirtualButtonApp* ifttt_virtual_button_app_alloc(uint32_t first_scene) { view_dispatcher_add_view( app->view_dispatcher, VirtualButtonAppViewSendView, send_view_get_view(app->sen_view)); - app->modul_view = module_view_alloc(); + app->abou_view = about_view_alloc(); view_dispatcher_add_view( app->view_dispatcher, - VirtualButtonAppViewModuleView, - module_view_get_view(app->modul_view)); - - app->reboo_view = reboot_view_alloc(); - view_dispatcher_add_view( - app->view_dispatcher, - VirtualButtonAppViewRebootView, - reboot_view_get_view(app->reboo_view)); - - app->rese_view = reset_view_alloc(); - view_dispatcher_add_view( - app->view_dispatcher, VirtualButtonAppViewResetView, reset_view_get_view(app->rese_view)); + VirtualButtonAppViewAboutView, + about_view_get_view(app->abou_view)); app->submenu = submenu_alloc(); view_dispatcher_add_view( @@ -73,15 +208,16 @@ VirtualButtonApp* ifttt_virtual_button_app_alloc(uint32_t first_scene) { void ifttt_virtual_button_app_free(VirtualButtonApp* app) { furi_assert(app); + + free(app->settings.save_ssid); + free(app->settings.save_password); + free(app->settings.save_key); + // Views view_dispatcher_remove_view(app->view_dispatcher, VirtualButtonAppViewSendView); send_view_free(app->sen_view); - view_dispatcher_remove_view(app->view_dispatcher, VirtualButtonAppViewModuleView); - module_view_free(app->modul_view); - view_dispatcher_remove_view(app->view_dispatcher, VirtualButtonAppViewRebootView); - reboot_view_free(app->reboo_view); - view_dispatcher_remove_view(app->view_dispatcher, VirtualButtonAppViewResetView); - reset_view_free(app->rese_view); + view_dispatcher_remove_view(app->view_dispatcher, VirtualButtonAppViewAboutView); + about_view_free(app->abou_view); view_dispatcher_remove_view(app->view_dispatcher, VirtualButtonAppViewSubmenu); submenu_free(app->submenu); view_dispatcher_remove_view(app->view_dispatcher, VirtualButtonAppViewDialog); @@ -92,14 +228,26 @@ void ifttt_virtual_button_app_free(VirtualButtonApp* app) { // Records furi_record_close(RECORD_POWER); furi_record_close(RECORD_GUI); + free(app); } int32_t ifttt_virtual_button_app(void* p) { UNUSED(p); + + Storage* storage = furi_record_open(RECORD_STORAGE); + if(!storage_simply_mkdir(storage, IFTTT_FOLDER)) { + } + if(!storage_simply_mkdir(storage, IFTTT_CONFIG_FOLDER)) { + } + furi_record_close(RECORD_STORAGE); + uint32_t first_scene = VirtualButtonAppSceneStart; VirtualButtonApp* app = ifttt_virtual_button_app_alloc(first_scene); + memcpy(&app->settings,load_settings(),sizeof(Settings)); + send_serial_command_config(ESerialCommand_Config, &(app->settings)); + view_dispatcher_run(app->view_dispatcher); ifttt_virtual_button_app_free(app); return 0; -} +} \ No newline at end of file diff --git a/applications/plugins/ifttt/ifttt_virtual_button.h b/applications/plugins/ifttt/ifttt_virtual_button.h index baded9370..da1a735ea 100644 --- a/applications/plugins/ifttt/ifttt_virtual_button.h +++ b/applications/plugins/ifttt/ifttt_virtual_button.h @@ -6,35 +6,51 @@ #include #include #include - #include "views/send_view.h" -#include "views/module_view.h" -#include "views/reboot_view.h" -#include "views/reset_view.h" +#include "views/about_view.h" #include #include - +#include +#include +#include +#include #include "scenes/virtual_button_scene.h" +#define APP_NAME "[ESP8266] IFTTT Virtual Button" + +#define CONF_SSID "wifi_ssid" +#define CONF_PASSWORD "wifi_password" +#define CONF_KEY "webhooks_key" +#define CONF_EVENT "event" +#define CONFIG_FILE_HEADER "IFTTT Virtual Button Config File" +#define CONFIG_FILE_VERSION 1 + +typedef struct{ + char *save_ssid; + char *save_password; + char *save_key; + char *save_event; +} Settings; + typedef struct { Power* power; Gui* gui; SceneManager* scene_manager; ViewDispatcher* view_dispatcher; SendView* sen_view; - ModuleView* modul_view; - RebootView* reboo_view; - ResetView* rese_view; + AboutView* abou_view; Submenu* submenu; DialogEx* dialog; PowerInfo info; + Settings settings; } VirtualButtonApp; typedef enum { VirtualButtonAppViewSendView, - VirtualButtonAppViewModuleView, - VirtualButtonAppViewRebootView, - VirtualButtonAppViewResetView, + VirtualButtonAppViewAboutView, VirtualButtonAppViewSubmenu, VirtualButtonAppViewDialog, } VirtualButtonAppView; + +Settings save_settings(Settings settings); +Settings *load_settings(); \ No newline at end of file diff --git a/applications/plugins/ifttt/scenes/virtual_button_scene_reset.c b/applications/plugins/ifttt/scenes/virtual_button_scene_about.c similarity index 51% rename from applications/plugins/ifttt/scenes/virtual_button_scene_reset.c rename to applications/plugins/ifttt/scenes/virtual_button_scene_about.c index 675778b8f..86fe1a9d0 100644 --- a/applications/plugins/ifttt/scenes/virtual_button_scene_reset.c +++ b/applications/plugins/ifttt/scenes/virtual_button_scene_about.c @@ -1,26 +1,26 @@ #include "../ifttt_virtual_button.h" -static void virtual_button_scene_reset_view_update_model(VirtualButtonApp* app) { +static void virtual_button_scene_about_view_update_model(VirtualButtonApp* app) { power_get_info(app->power, &app->info); } -void virtual_button_scene_reset_view_on_enter(void* context) { +void virtual_button_scene_about_view_on_enter(void* context) { VirtualButtonApp* app = context; - virtual_button_scene_reset_view_update_model(app); - view_dispatcher_switch_to_view(app->view_dispatcher, VirtualButtonAppViewResetView); + virtual_button_scene_about_view_update_model(app); + view_dispatcher_switch_to_view(app->view_dispatcher, VirtualButtonAppViewAboutView); } -bool virtual_button_scene_reset_view_on_event(void* context, SceneManagerEvent event) { +bool virtual_button_scene_about_view_on_event(void* context, SceneManagerEvent event) { VirtualButtonApp* app = context; bool consumed = false; if(event.type == SceneManagerEventTypeTick) { - virtual_button_scene_reset_view_update_model(app); + virtual_button_scene_about_view_update_model(app); consumed = true; } return consumed; } -void virtual_button_scene_reset_view_on_exit(void* context) { +void virtual_button_scene_about_view_on_exit(void* context) { UNUSED(context); } diff --git a/applications/plugins/ifttt/scenes/virtual_button_scene_config.h b/applications/plugins/ifttt/scenes/virtual_button_scene_config.h index ca4c23435..70af5ccf7 100644 --- a/applications/plugins/ifttt/scenes/virtual_button_scene_config.h +++ b/applications/plugins/ifttt/scenes/virtual_button_scene_config.h @@ -1,5 +1,3 @@ ADD_SCENE(virtual_button, start, Start) ADD_SCENE(virtual_button, send_view, SendView) -ADD_SCENE(virtual_button, module_view, ModuleView) -ADD_SCENE(virtual_button, reboot_view, RebootView) -ADD_SCENE(virtual_button, reset_view, ResetView) \ No newline at end of file +ADD_SCENE(virtual_button, about_view, AboutView) diff --git a/applications/plugins/ifttt/scenes/virtual_button_scene_module.c b/applications/plugins/ifttt/scenes/virtual_button_scene_module.c deleted file mode 100644 index 33d5ae0c2..000000000 --- a/applications/plugins/ifttt/scenes/virtual_button_scene_module.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "../ifttt_virtual_button.h" - -static void virtual_button_scene_module_view_update_model(VirtualButtonApp* app) { - power_get_info(app->power, &app->info); -} - -void virtual_button_scene_module_view_on_enter(void* context) { - VirtualButtonApp* app = context; - virtual_button_scene_module_view_update_model(app); - view_dispatcher_switch_to_view(app->view_dispatcher, VirtualButtonAppViewModuleView); -} - -bool virtual_button_scene_module_view_on_event(void* context, SceneManagerEvent event) { - VirtualButtonApp* app = context; - bool consumed = false; - - if(event.type == SceneManagerEventTypeTick) { - virtual_button_scene_module_view_update_model(app); - consumed = true; - } - return consumed; -} - -void virtual_button_scene_module_view_on_exit(void* context) { - UNUSED(context); -} diff --git a/applications/plugins/ifttt/scenes/virtual_button_scene_reboot.c b/applications/plugins/ifttt/scenes/virtual_button_scene_reboot.c deleted file mode 100644 index 15a65516e..000000000 --- a/applications/plugins/ifttt/scenes/virtual_button_scene_reboot.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "../ifttt_virtual_button.h" - -static void virtual_button_scene_reboot_view_update_model(VirtualButtonApp* app) { - power_get_info(app->power, &app->info); -} - -void virtual_button_scene_reboot_view_on_enter(void* context) { - VirtualButtonApp* app = context; - virtual_button_scene_reboot_view_update_model(app); - view_dispatcher_switch_to_view(app->view_dispatcher, VirtualButtonAppViewRebootView); -} - -bool virtual_button_scene_reboot_view_on_event(void* context, SceneManagerEvent event) { - VirtualButtonApp* app = context; - bool consumed = false; - - if(event.type == SceneManagerEventTypeTick) { - virtual_button_scene_reboot_view_update_model(app); - consumed = true; - } - return consumed; -} - -void virtual_button_scene_reboot_view_on_exit(void* context) { - UNUSED(context); -} diff --git a/applications/plugins/ifttt/scenes/virtual_button_scene_start.c b/applications/plugins/ifttt/scenes/virtual_button_scene_start.c index 84cb60363..6b03a35f0 100644 --- a/applications/plugins/ifttt/scenes/virtual_button_scene_start.c +++ b/applications/plugins/ifttt/scenes/virtual_button_scene_start.c @@ -2,9 +2,7 @@ enum VirtualButtonSubmenuIndex { VirtualButtonSubmenuIndexSendView, - VirtualButtonSubmenuIndexModuleView, - VirtualButtonSubmenuIndexRebootView, - VirtualButtonSubmenuIndexResetView, + VirtualButtonSubmenuIndexAboutView, }; static void virtual_button_scene_start_submenu_callback(void* context, uint32_t index) { @@ -25,20 +23,8 @@ void virtual_button_scene_start_on_enter(void* context) { app); submenu_add_item( submenu, - "Configure module", - VirtualButtonSubmenuIndexModuleView, - virtual_button_scene_start_submenu_callback, - app); - submenu_add_item( - submenu, - "Reboot module", - VirtualButtonSubmenuIndexRebootView, - virtual_button_scene_start_submenu_callback, - app); - submenu_add_item( - submenu, - "Reset module", - VirtualButtonSubmenuIndexResetView, + "About", + VirtualButtonSubmenuIndexAboutView, virtual_button_scene_start_submenu_callback, app); submenu_set_selected_item( @@ -54,12 +40,8 @@ bool virtual_button_scene_start_on_event(void* context, SceneManagerEvent event) if(event.type == SceneManagerEventTypeCustom) { if(event.event == VirtualButtonSubmenuIndexSendView) { scene_manager_next_scene(app->scene_manager, VirtualButtonAppSceneSendView); - } else if(event.event == VirtualButtonSubmenuIndexModuleView) { - scene_manager_next_scene(app->scene_manager, VirtualButtonAppSceneModuleView); - } else if(event.event == VirtualButtonSubmenuIndexRebootView) { - scene_manager_next_scene(app->scene_manager, VirtualButtonAppSceneRebootView); - } else if(event.event == VirtualButtonSubmenuIndexResetView) { - scene_manager_next_scene(app->scene_manager, VirtualButtonAppSceneResetView); + } else if(event.event == VirtualButtonSubmenuIndexAboutView) { + scene_manager_next_scene(app->scene_manager, VirtualButtonAppSceneAboutView); } scene_manager_set_scene_state(app->scene_manager, VirtualButtonAppSceneStart, event.event); consumed = true; diff --git a/applications/plugins/ifttt/views/about_view.c b/applications/plugins/ifttt/views/about_view.c new file mode 100644 index 000000000..6ab48c675 --- /dev/null +++ b/applications/plugins/ifttt/views/about_view.c @@ -0,0 +1,49 @@ +#include "about_view.h" +#include +#include +#include +#include + +struct AboutView { + View* view; +}; + +typedef struct { + bool connected; +} AboutViewModel; + +static void about_view_draw_callback(Canvas* canvas, void* context) { + furi_assert(context); + canvas_clear(canvas); + canvas_set_color(canvas, ColorBlack); + canvas_draw_str_aligned(canvas, 0, 0, AlignLeft, AlignTop, "IFTTT Virtual button"); + canvas_draw_str_aligned(canvas, 0, 15, AlignLeft, AlignTop, "Version 0.2"); + canvas_draw_str_aligned(canvas, 0, 50, AlignLeft, AlignTop, "press back"); +} + + +AboutView* about_view_alloc() { + AboutView* about_view = malloc(sizeof(AboutView)); + about_view->view = view_alloc(); + view_set_context(about_view->view, about_view); + view_allocate_model(about_view->view, ViewModelTypeLocking, sizeof(AboutViewModel)); + view_set_draw_callback(about_view->view, about_view_draw_callback); + return about_view; +} + +void about_view_free(AboutView* about_view) { + furi_assert(about_view); + view_free(about_view->view); + free(about_view); +} + +View* about_view_get_view(AboutView* about_view) { + furi_assert(about_view); + return about_view->view; +} + +void about_view_set_data(AboutView* about_view, bool connected) { + furi_assert(about_view); + with_view_model( + about_view->view, AboutViewModel * model, { model->connected = connected; }, true); +} \ No newline at end of file diff --git a/applications/plugins/ifttt/views/about_view.h b/applications/plugins/ifttt/views/about_view.h new file mode 100644 index 000000000..d1ac287e3 --- /dev/null +++ b/applications/plugins/ifttt/views/about_view.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +typedef struct AboutView AboutView; + +AboutView* about_view_alloc(); + +void about_view_free(AboutView* about_view); + +View* about_view_get_view(AboutView* about_view); \ No newline at end of file diff --git a/applications/plugins/ifttt/views/module_view.c b/applications/plugins/ifttt/views/module_view.c deleted file mode 100644 index ef507bbe3..000000000 --- a/applications/plugins/ifttt/views/module_view.c +++ /dev/null @@ -1,147 +0,0 @@ -#include "module_view.h" -#include -#include -#include -#include -#include - -#define MODULE_CONTROL_COMMAND_CONFIG_ON 'c' -#define MODULE_CONTROL_COMMAND_CONFIG_OFF 'd' -#define FLIPPERZERO_SERIAL_BAUD 115200 - -bool configState; - -typedef enum ESerialCommand { ESerialCommand_Config_On, ESerialCommand_Config_Off } ESerialCommand; - -struct ModuleView { - View* view; -}; - -typedef struct { - bool right_pressed; - bool connected; -} ModuleViewModel; - -/* -static void Shake(void) { - NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION); - notification_message(notification, &sequence_single_vibro); - furi_record_close(RECORD_NOTIFICATION); -} -*/ - -void send_serial_command_module(ESerialCommand command) { - uint8_t data[1] = {0}; - - switch(command) { - case ESerialCommand_Config_On: - data[0] = MODULE_CONTROL_COMMAND_CONFIG_ON; - break; - case ESerialCommand_Config_Off: - data[0] = MODULE_CONTROL_COMMAND_CONFIG_OFF; - break; - default: - return; - }; - - furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1); -} - -static void module_view_draw_callback(Canvas* canvas, void* context) { - furi_assert(context); - ModuleViewModel* model = context; - canvas_clear(canvas); - canvas_set_color(canvas, ColorBlack); - canvas_draw_str_aligned(canvas, 64, 0, AlignCenter, AlignTop, "CONFIGURE MODULE"); - canvas_draw_line(canvas, 0, 10, 128, 10); - canvas_draw_str_aligned(canvas, 64, 15, AlignCenter, AlignTop, "Press right to start the"); - canvas_draw_str_aligned(canvas, 64, 25, AlignCenter, AlignTop, "configurator and connect"); - canvas_draw_str_aligned(canvas, 64, 35, AlignCenter, AlignTop, "to ip 192.168.4.1 or press"); - canvas_draw_str_aligned(canvas, 64, 45, AlignCenter, AlignTop, "and hold back to return"); - canvas_draw_str_aligned(canvas, 64, 55, AlignCenter, AlignTop, "to the menu"); - - if(configState == false) { - send_serial_command_module(ESerialCommand_Config_On); - configState = true; - } - - // Right - if(model->right_pressed) { - } -} - -static void module_view_process(ModuleView* module_view, InputEvent* event) { - with_view_model( - module_view->view, - ModuleViewModel * model, - { - if(event->type == InputTypePress) { - if(event->key == InputKeyUp) { - } else if(event->key == InputKeyDown) { - } else if(event->key == InputKeyLeft) { - } else if(event->key == InputKeyRight) { - model->right_pressed = true; - } else if(event->key == InputKeyOk) { - } else if(event->key == InputKeyBack) { - } - } else if(event->type == InputTypeRelease) { - if(event->key == InputKeyUp) { - } else if(event->key == InputKeyDown) { - } else if(event->key == InputKeyLeft) { - } else if(event->key == InputKeyRight) { - model->right_pressed = false; - } else if(event->key == InputKeyOk) { - } else if(event->key == InputKeyBack) { - } - } else if(event->type == InputTypeShort) { - if(event->key == InputKeyBack) { - } - } - }, - true); -} - -static bool module_view_input_callback(InputEvent* event, void* context) { - furi_assert(context); - ModuleView* module_view = context; - bool consumed = false; - - if(event->type == InputTypeLong && event->key == InputKeyBack) { - send_serial_command_module(ESerialCommand_Config_Off); - configState = false; - } else { - module_view_process(module_view, event); - consumed = true; - } - - return consumed; -} - -ModuleView* module_view_alloc() { - ModuleView* module_view = malloc(sizeof(ModuleView)); - module_view->view = view_alloc(); - view_set_context(module_view->view, module_view); - view_allocate_model(module_view->view, ViewModelTypeLocking, sizeof(ModuleViewModel)); - view_set_draw_callback(module_view->view, module_view_draw_callback); - view_set_input_callback(module_view->view, module_view_input_callback); - furi_hal_uart_set_br(FuriHalUartIdUSART1, FLIPPERZERO_SERIAL_BAUD); - configState = false; - return module_view; -} - -void module_view_free(ModuleView* module_view) { - furi_assert(module_view); - view_free(module_view->view); - free(module_view); -} - -View* module_view_get_view(ModuleView* module_view) { - furi_assert(module_view); - return module_view->view; -} - -void module_view_set_data(ModuleView* module_view, bool connected) { - furi_assert(module_view); - with_view_model( - module_view->view, ModuleViewModel * model, { model->connected = connected; }, true); -} \ No newline at end of file diff --git a/applications/plugins/ifttt/views/module_view.h b/applications/plugins/ifttt/views/module_view.h deleted file mode 100644 index d486aa9fa..000000000 --- a/applications/plugins/ifttt/views/module_view.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include - -typedef struct ModuleView ModuleView; - -ModuleView* module_view_alloc(); - -void module_view_free(ModuleView* module_view); - -View* module_view_get_view(ModuleView* module_view); \ No newline at end of file diff --git a/applications/plugins/ifttt/views/reboot_view.c b/applications/plugins/ifttt/views/reboot_view.c deleted file mode 100644 index ab1365b35..000000000 --- a/applications/plugins/ifttt/views/reboot_view.c +++ /dev/null @@ -1,132 +0,0 @@ -#include "reboot_view.h" -#include -#include -#include -#include -#include - -#define MODULE_CONTROL_COMMAND_REBOOT 'r' -#define FLIPPERZERO_SERIAL_BAUD 115200 - -typedef enum ESerialCommand { ESerialCommand_Reboot } ESerialCommand; - -struct RebootView { - View* view; -}; - -typedef struct { - bool right_pressed; - bool connected; -} RebootViewModel; - -static void Shake(void) { - NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION); - notification_message(notification, &sequence_single_vibro); - furi_record_close(RECORD_NOTIFICATION); -} - -void send_serial_command_reboot(ESerialCommand command) { - uint8_t data[1] = {0}; - - switch(command) { - case ESerialCommand_Reboot: - data[0] = MODULE_CONTROL_COMMAND_REBOOT; - break; - default: - return; - }; - - furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1); -} - -static void reboot_view_draw_callback(Canvas* canvas, void* context) { - furi_assert(context); - RebootViewModel* model = context; - canvas_clear(canvas); - canvas_set_color(canvas, ColorBlack); - canvas_draw_str_aligned(canvas, 64, 0, AlignCenter, AlignTop, "REBOOT MODULE"); - canvas_draw_line(canvas, 0, 10, 128, 10); - canvas_draw_str_aligned(canvas, 64, 15, AlignCenter, AlignTop, "Press right to restart the"); - canvas_draw_str_aligned(canvas, 64, 25, AlignCenter, AlignTop, "module or press and hold"); - canvas_draw_str_aligned(canvas, 64, 35, AlignCenter, AlignTop, "back to return to the menu"); - - // Right - if(model->right_pressed) { - } -} - -static void reboot_view_process(RebootView* reboot_view, InputEvent* event) { - with_view_model( - reboot_view->view, - RebootViewModel * model, - { - if(event->type == InputTypePress) { - if(event->key == InputKeyUp) { - } else if(event->key == InputKeyDown) { - } else if(event->key == InputKeyLeft) { - } else if(event->key == InputKeyRight) { - model->right_pressed = true; - Shake(); - send_serial_command_reboot(ESerialCommand_Reboot); - } else if(event->key == InputKeyOk) { - } else if(event->key == InputKeyBack) { - } - } else if(event->type == InputTypeRelease) { - if(event->key == InputKeyUp) { - } else if(event->key == InputKeyDown) { - } else if(event->key == InputKeyLeft) { - } else if(event->key == InputKeyRight) { - model->right_pressed = false; - } else if(event->key == InputKeyOk) { - } else if(event->key == InputKeyBack) { - } - } else if(event->type == InputTypeShort) { - if(event->key == InputKeyBack) { - } - } - }, - true); -} - -static bool reboot_view_input_callback(InputEvent* event, void* context) { - furi_assert(context); - RebootView* reboot_view = context; - bool consumed = false; - - if(event->type == InputTypeLong && event->key == InputKeyBack) { - } else { - reboot_view_process(reboot_view, event); - consumed = true; - } - - return consumed; -} - -RebootView* reboot_view_alloc() { - RebootView* reboot_view = malloc(sizeof(RebootView)); - reboot_view->view = view_alloc(); - view_set_context(reboot_view->view, reboot_view); - view_allocate_model(reboot_view->view, ViewModelTypeLocking, sizeof(RebootViewModel)); - view_set_draw_callback(reboot_view->view, reboot_view_draw_callback); - view_set_input_callback(reboot_view->view, reboot_view_input_callback); - furi_hal_uart_set_br(FuriHalUartIdUSART1, FLIPPERZERO_SERIAL_BAUD); - - return reboot_view; -} - -void reboot_view_free(RebootView* reboot_view) { - furi_assert(reboot_view); - view_free(reboot_view->view); - free(reboot_view); -} - -View* reboot_view_get_view(RebootView* reboot_view) { - furi_assert(reboot_view); - return reboot_view->view; -} - -void reboot_view_set_data(RebootView* reboot_view, bool connected) { - furi_assert(reboot_view); - with_view_model( - reboot_view->view, RebootViewModel * model, { model->connected = connected; }, true); -} \ No newline at end of file diff --git a/applications/plugins/ifttt/views/reboot_view.h b/applications/plugins/ifttt/views/reboot_view.h deleted file mode 100644 index 28d5841f1..000000000 --- a/applications/plugins/ifttt/views/reboot_view.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include - -typedef struct RebootView RebootView; - -RebootView* reboot_view_alloc(); - -void reboot_view_free(RebootView* reboot_view); - -View* reboot_view_get_view(RebootView* reboot_view); \ No newline at end of file diff --git a/applications/plugins/ifttt/views/reset_view.c b/applications/plugins/ifttt/views/reset_view.c deleted file mode 100644 index c16039eb6..000000000 --- a/applications/plugins/ifttt/views/reset_view.c +++ /dev/null @@ -1,132 +0,0 @@ -#include "reset_view.h" -#include -#include -#include -#include -#include - -#define MODULE_CONTROL_COMMAND_RESET 'a' -#define FLIPPERZERO_SERIAL_BAUD 115200 - -typedef enum ESerialCommand { ESerialCommand_Reset } ESerialCommand; - -struct ResetView { - View* view; -}; - -typedef struct { - bool right_pressed; - bool connected; -} ResetViewModel; - -static void Shake(void) { - NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION); - notification_message(notification, &sequence_single_vibro); - furi_record_close(RECORD_NOTIFICATION); -} - -void send_serial_command_reset(ESerialCommand command) { - uint8_t data[1] = {0}; - - switch(command) { - case ESerialCommand_Reset: - data[0] = MODULE_CONTROL_COMMAND_RESET; - break; - default: - return; - }; - - furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1); -} - -static void reset_view_draw_callback(Canvas* canvas, void* context) { - furi_assert(context); - ResetViewModel* model = context; - canvas_clear(canvas); - canvas_set_color(canvas, ColorBlack); - canvas_draw_str_aligned(canvas, 64, 0, AlignCenter, AlignTop, "RESET MODULE"); - canvas_draw_line(canvas, 0, 10, 128, 10); - canvas_draw_str_aligned(canvas, 64, 15, AlignCenter, AlignTop, "Press right to reset"); - canvas_draw_str_aligned(canvas, 64, 25, AlignCenter, AlignTop, "module or press and hold"); - canvas_draw_str_aligned(canvas, 64, 35, AlignCenter, AlignTop, "back to return to the menu"); - - // Right - if(model->right_pressed) { - } -} - -static void reset_view_process(ResetView* reset_view, InputEvent* event) { - with_view_model( - reset_view->view, - ResetViewModel * model, - { - if(event->type == InputTypePress) { - if(event->key == InputKeyUp) { - } else if(event->key == InputKeyDown) { - } else if(event->key == InputKeyLeft) { - } else if(event->key == InputKeyRight) { - model->right_pressed = true; - Shake(); - send_serial_command_reset(ESerialCommand_Reset); - } else if(event->key == InputKeyOk) { - } else if(event->key == InputKeyBack) { - } - } else if(event->type == InputTypeRelease) { - if(event->key == InputKeyUp) { - } else if(event->key == InputKeyDown) { - } else if(event->key == InputKeyLeft) { - } else if(event->key == InputKeyRight) { - model->right_pressed = false; - } else if(event->key == InputKeyOk) { - } else if(event->key == InputKeyBack) { - } - } else if(event->type == InputTypeShort) { - if(event->key == InputKeyBack) { - } - } - }, - true); -} - -static bool reset_view_input_callback(InputEvent* event, void* context) { - furi_assert(context); - ResetView* reset_view = context; - bool consumed = false; - - if(event->type == InputTypeLong && event->key == InputKeyBack) { - } else { - reset_view_process(reset_view, event); - consumed = true; - } - - return consumed; -} - -ResetView* reset_view_alloc() { - ResetView* reset_view = malloc(sizeof(ResetView)); - reset_view->view = view_alloc(); - view_set_context(reset_view->view, reset_view); - view_allocate_model(reset_view->view, ViewModelTypeLocking, sizeof(ResetViewModel)); - view_set_draw_callback(reset_view->view, reset_view_draw_callback); - view_set_input_callback(reset_view->view, reset_view_input_callback); - furi_hal_uart_set_br(FuriHalUartIdUSART1, FLIPPERZERO_SERIAL_BAUD); - - return reset_view; -} - -void reset_view_free(ResetView* reset_view) { - furi_assert(reset_view); - view_free(reset_view->view); - free(reset_view); -} - -View* reset_view_get_view(ResetView* reset_view) { - furi_assert(reset_view); - return reset_view->view; -} - -void reset_view_set_data(ResetView* reset_view, bool connected) { - furi_assert(reset_view); - with_view_model( - reset_view->view, ResetViewModel * model, { model->connected = connected; }, true); -} \ No newline at end of file diff --git a/applications/plugins/ifttt/views/reset_view.h b/applications/plugins/ifttt/views/reset_view.h deleted file mode 100644 index c71aad77d..000000000 --- a/applications/plugins/ifttt/views/reset_view.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include - -typedef struct ResetView ResetView; - -ResetView* reset_view_alloc(); - -void reset_view_free(ResetView* reset_view); - -View* reset_view_get_view(ResetView* reset_view); \ No newline at end of file diff --git a/applications/plugins/ifttt/views/send_view.c b/applications/plugins/ifttt/views/send_view.c index 4272b2e4d..ce5d53930 100644 --- a/applications/plugins/ifttt/views/send_view.c +++ b/applications/plugins/ifttt/views/send_view.c @@ -4,8 +4,9 @@ #include #include #include +#include +#include -#define MODULE_CONTROL_COMMAND_SEND 's' #define FLIPPERZERO_SERIAL_BAUD 115200 typedef enum ESerialCommand { ESerialCommand_Send } ESerialCommand; @@ -28,15 +29,19 @@ static void Shake(void) { void send_serial_command_send(ESerialCommand command) { uint8_t data[1] = {0}; + char name[10] = "send"; + int length = strlen(name); + for (int i = 0; i < length; i++){ switch(command) { - case ESerialCommand_Send: - data[0] = MODULE_CONTROL_COMMAND_SEND; + case ESerialCommand_Send: + data[0] = name[i]; break; - default: + default: return; }; furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1); + } } static void send_view_draw_callback(Canvas* canvas, void* context) {