This commit is contained in:
RogueMaster
2022-11-02 20:24:27 -04:00
parent 8f67320e7a
commit e1d3e67fc5
4 changed files with 70 additions and 73 deletions

View File

@@ -2,20 +2,20 @@
#define IFTTT_FOLDER "/ext/ifttt"
#define IFTTT_CONFIG_FOLDER "/ext/ifttt/config"
const char *CONFIG_FILE_PATH = "/ext/ifttt/config/config.settings";
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)) {
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{
} else {
}
flipper_format_file_close(file);
flipper_format_free(file);
@@ -23,7 +23,7 @@ Settings save_settings(Settings settings) {
return settings;
}
void save_settings_file(FlipperFormat *file, Settings *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);
@@ -35,60 +35,60 @@ void save_settings_file(FlipperFormat *file, Settings *settings) {
flipper_format_write_string_cstr(file, CONF_EVENT, settings->save_event);
}
Settings *load_settings() {
Settings *settings=malloc(sizeof(Settings));
Settings* load_settings() {
Settings* settings = malloc(sizeof(Settings));
Storage *storage = furi_record_open(RECORD_STORAGE);
FlipperFormat *file = flipper_format_file_alloc(storage);
Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* file = flipper_format_file_alloc(storage);
FuriString *string_value;
FuriString* string_value;
string_value = furi_string_alloc();
FuriString *text_ssid_value;
FuriString* text_ssid_value;
text_ssid_value = furi_string_alloc();
FuriString *text_password_value;
FuriString* text_password_value;
text_password_value = furi_string_alloc();
FuriString *text_key_value;
FuriString* text_key_value;
text_key_value = furi_string_alloc();
FuriString *text_event_value;
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)) {
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 = 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';
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)) {
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)) {
if(!flipper_format_read_header(file, string_value, &value)) {
} else {
if (flipper_format_read_string(file, CONF_SSID, text_ssid_value)) {
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)) {
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)) {
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)) {
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));
}
@@ -106,43 +106,43 @@ Settings *load_settings() {
return settings;
}
void send_serial_command_config(ESerialCommand command, Settings *settings) {
uint8_t data[1] = {0};
void send_serial_command_config(ESerialCommand command, Settings* settings) {
uint8_t data[1] = {0};
char config_tmp[100];
strcpy(config_tmp,"config,");
strcpy(config_tmp, "config,");
strcat(config_tmp, settings->save_key);
char config_tmp2[5];
strcpy(config_tmp2, config_tmp);
strcat(config_tmp2,",");
strcat(config_tmp2, ",");
char config_tmp3[100];
strcpy(config_tmp3, config_tmp2);
strcat(config_tmp3,settings->save_ssid);
strcat(config_tmp3, settings->save_ssid);
char config_tmp4[5];
strcpy(config_tmp4, config_tmp3);
strcat(config_tmp4,",");
strcat(config_tmp4, ",");
char config_tmp5[100];
strcpy(config_tmp5, config_tmp4);
strcat(config_tmp5,settings->save_password);
strcat(config_tmp5, settings->save_password);
char config_tmp6[5];
strcpy(config_tmp6, config_tmp5);
strcat(config_tmp6,",");
strcat(config_tmp6, ",");
char config[350];
strcpy(config, config_tmp6);
strcat(config,settings->save_event);
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;
int length = strlen(config);
for(int i = 0; i < length; i++) {
switch(command) {
case ESerialCommand_Config:
data[0] = config[i];
break;
default:
return;
};
return;
};
furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1);
}
furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1);
}
}
static bool ifttt_virtual_button_custom_event_callback(void* context, uint32_t event) {
@@ -190,9 +190,7 @@ VirtualButtonApp* ifttt_virtual_button_app_alloc(uint32_t first_scene) {
app->abou_view = about_view_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
VirtualButtonAppViewAboutView,
about_view_get_view(app->abou_view));
app->view_dispatcher, VirtualButtonAppViewAboutView, about_view_get_view(app->abou_view));
app->submenu = submenu_alloc();
view_dispatcher_add_view(
@@ -234,7 +232,7 @@ void ifttt_virtual_button_app_free(VirtualButtonApp* 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)) {
}
@@ -244,7 +242,7 @@ int32_t ifttt_virtual_button_app(void* p) {
uint32_t first_scene = VirtualButtonAppSceneStart;
VirtualButtonApp* app = ifttt_virtual_button_app_alloc(first_scene);
memcpy(&app->settings,load_settings(),sizeof(Settings));
memcpy(&app->settings, load_settings(), sizeof(Settings));
send_serial_command_config(ESerialCommand_Config, &(app->settings));
view_dispatcher_run(app->view_dispatcher);