mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-20 00:48:11 -07:00
fmt
This commit is contained in:
@@ -2,20 +2,20 @@
|
|||||||
|
|
||||||
#define IFTTT_FOLDER "/ext/ifttt"
|
#define IFTTT_FOLDER "/ext/ifttt"
|
||||||
#define IFTTT_CONFIG_FOLDER "/ext/ifttt/config"
|
#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
|
#define FLIPPERZERO_SERIAL_BAUD 115200
|
||||||
typedef enum ESerialCommand { ESerialCommand_Config } ESerialCommand;
|
typedef enum ESerialCommand { ESerialCommand_Config } ESerialCommand;
|
||||||
|
|
||||||
Settings save_settings(Settings settings) {
|
Settings save_settings(Settings settings) {
|
||||||
Storage *storage = furi_record_open(RECORD_STORAGE);
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||||
FlipperFormat *file = flipper_format_file_alloc(storage);
|
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||||
if (flipper_format_file_open_existing(file, CONFIG_FILE_PATH)) {
|
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_SSID, settings.save_ssid);
|
||||||
flipper_format_update_string_cstr(file, CONF_PASSWORD, settings.save_password);
|
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_KEY, settings.save_key);
|
||||||
flipper_format_update_string_cstr(file, CONF_EVENT, settings.save_event);
|
flipper_format_update_string_cstr(file, CONF_EVENT, settings.save_event);
|
||||||
}else{
|
} else {
|
||||||
}
|
}
|
||||||
flipper_format_file_close(file);
|
flipper_format_file_close(file);
|
||||||
flipper_format_free(file);
|
flipper_format_free(file);
|
||||||
@@ -23,7 +23,7 @@ Settings save_settings(Settings settings) {
|
|||||||
return 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_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_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_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);
|
flipper_format_write_string_cstr(file, CONF_EVENT, settings->save_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings *load_settings() {
|
Settings* load_settings() {
|
||||||
Settings *settings=malloc(sizeof(Settings));
|
Settings* settings = malloc(sizeof(Settings));
|
||||||
|
|
||||||
Storage *storage = furi_record_open(RECORD_STORAGE);
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||||
FlipperFormat *file = flipper_format_file_alloc(storage);
|
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||||
|
|
||||||
FuriString *string_value;
|
FuriString* string_value;
|
||||||
string_value = furi_string_alloc();
|
string_value = furi_string_alloc();
|
||||||
FuriString *text_ssid_value;
|
FuriString* text_ssid_value;
|
||||||
text_ssid_value = furi_string_alloc();
|
text_ssid_value = furi_string_alloc();
|
||||||
FuriString *text_password_value;
|
FuriString* text_password_value;
|
||||||
text_password_value = furi_string_alloc();
|
text_password_value = furi_string_alloc();
|
||||||
FuriString *text_key_value;
|
FuriString* text_key_value;
|
||||||
text_key_value = furi_string_alloc();
|
text_key_value = furi_string_alloc();
|
||||||
FuriString *text_event_value;
|
FuriString* text_event_value;
|
||||||
text_event_value = furi_string_alloc();
|
text_event_value = furi_string_alloc();
|
||||||
|
|
||||||
if (storage_common_stat(storage, CONFIG_FILE_PATH, NULL) != FSE_OK) {
|
if(storage_common_stat(storage, CONFIG_FILE_PATH, NULL) != FSE_OK) {
|
||||||
if (!flipper_format_file_open_new(file, CONFIG_FILE_PATH)) {
|
if(!flipper_format_file_open_new(file, CONFIG_FILE_PATH)) {
|
||||||
flipper_format_file_close(file);
|
flipper_format_file_close(file);
|
||||||
} else {
|
} else {
|
||||||
settings->save_ssid = malloc( 1);
|
settings->save_ssid = malloc(1);
|
||||||
settings->save_password = malloc( 1);
|
settings->save_password = malloc(1);
|
||||||
settings->save_key = malloc( 1);
|
settings->save_key = malloc(1);
|
||||||
settings->save_event = malloc( 1);
|
settings->save_event = malloc(1);
|
||||||
|
|
||||||
settings->save_ssid[0]='\0';
|
settings->save_ssid[0] = '\0';
|
||||||
settings->save_password[0]='\0';
|
settings->save_password[0] = '\0';
|
||||||
settings->save_key[0]='\0';
|
settings->save_key[0] = '\0';
|
||||||
settings->save_event[0]='\0';
|
settings->save_event[0] = '\0';
|
||||||
|
|
||||||
save_settings_file(file, settings);
|
save_settings_file(file, settings);
|
||||||
flipper_format_file_close(file);
|
flipper_format_file_close(file);
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
flipper_format_file_close(file);
|
||||||
} else {
|
} else {
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
if (!flipper_format_read_header(file, string_value, &value)) {
|
if(!flipper_format_read_header(file, string_value, &value)) {
|
||||||
} else {
|
} 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);
|
settings->save_ssid = malloc(furi_string_size(text_ssid_value) + 1);
|
||||||
strcpy(settings->save_ssid, furi_string_get_cstr(text_ssid_value));
|
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);
|
settings->save_password = malloc(furi_string_size(text_password_value) + 1);
|
||||||
strcpy(settings->save_password, furi_string_get_cstr(text_password_value));
|
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);
|
settings->save_key = malloc(furi_string_size(text_key_value) + 1);
|
||||||
strcpy(settings->save_key, furi_string_get_cstr(text_key_value));
|
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);
|
settings->save_event = malloc(furi_string_size(text_event_value) + 1);
|
||||||
strcpy(settings->save_event, furi_string_get_cstr(text_event_value));
|
strcpy(settings->save_event, furi_string_get_cstr(text_event_value));
|
||||||
}
|
}
|
||||||
@@ -106,43 +106,43 @@ Settings *load_settings() {
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_serial_command_config(ESerialCommand command, Settings *settings) {
|
void send_serial_command_config(ESerialCommand command, Settings* settings) {
|
||||||
uint8_t data[1] = {0};
|
uint8_t data[1] = {0};
|
||||||
|
|
||||||
char config_tmp[100];
|
char config_tmp[100];
|
||||||
strcpy(config_tmp,"config,");
|
strcpy(config_tmp, "config,");
|
||||||
strcat(config_tmp, settings->save_key);
|
strcat(config_tmp, settings->save_key);
|
||||||
char config_tmp2[5];
|
char config_tmp2[5];
|
||||||
strcpy(config_tmp2, config_tmp);
|
strcpy(config_tmp2, config_tmp);
|
||||||
strcat(config_tmp2,",");
|
strcat(config_tmp2, ",");
|
||||||
char config_tmp3[100];
|
char config_tmp3[100];
|
||||||
strcpy(config_tmp3, config_tmp2);
|
strcpy(config_tmp3, config_tmp2);
|
||||||
strcat(config_tmp3,settings->save_ssid);
|
strcat(config_tmp3, settings->save_ssid);
|
||||||
char config_tmp4[5];
|
char config_tmp4[5];
|
||||||
strcpy(config_tmp4, config_tmp3);
|
strcpy(config_tmp4, config_tmp3);
|
||||||
strcat(config_tmp4,",");
|
strcat(config_tmp4, ",");
|
||||||
char config_tmp5[100];
|
char config_tmp5[100];
|
||||||
strcpy(config_tmp5, config_tmp4);
|
strcpy(config_tmp5, config_tmp4);
|
||||||
strcat(config_tmp5,settings->save_password);
|
strcat(config_tmp5, settings->save_password);
|
||||||
char config_tmp6[5];
|
char config_tmp6[5];
|
||||||
strcpy(config_tmp6, config_tmp5);
|
strcpy(config_tmp6, config_tmp5);
|
||||||
strcat(config_tmp6,",");
|
strcat(config_tmp6, ",");
|
||||||
char config[350];
|
char config[350];
|
||||||
strcpy(config, config_tmp6);
|
strcpy(config, config_tmp6);
|
||||||
strcat(config,settings->save_event);
|
strcat(config, settings->save_event);
|
||||||
|
|
||||||
int length = strlen(config);
|
int length = strlen(config);
|
||||||
for (int i = 0; i < length; i++){
|
for(int i = 0; i < length; i++) {
|
||||||
switch(command) {
|
switch(command) {
|
||||||
case ESerialCommand_Config:
|
case ESerialCommand_Config:
|
||||||
data[0] = config[i];
|
data[0] = config[i];
|
||||||
break;
|
break;
|
||||||
default:
|
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) {
|
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();
|
app->abou_view = about_view_alloc();
|
||||||
view_dispatcher_add_view(
|
view_dispatcher_add_view(
|
||||||
app->view_dispatcher,
|
app->view_dispatcher, VirtualButtonAppViewAboutView, about_view_get_view(app->abou_view));
|
||||||
VirtualButtonAppViewAboutView,
|
|
||||||
about_view_get_view(app->abou_view));
|
|
||||||
|
|
||||||
app->submenu = submenu_alloc();
|
app->submenu = submenu_alloc();
|
||||||
view_dispatcher_add_view(
|
view_dispatcher_add_view(
|
||||||
@@ -234,7 +232,7 @@ void ifttt_virtual_button_app_free(VirtualButtonApp* app) {
|
|||||||
|
|
||||||
int32_t ifttt_virtual_button_app(void* p) {
|
int32_t ifttt_virtual_button_app(void* p) {
|
||||||
UNUSED(p);
|
UNUSED(p);
|
||||||
|
|
||||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||||
if(!storage_simply_mkdir(storage, IFTTT_FOLDER)) {
|
if(!storage_simply_mkdir(storage, IFTTT_FOLDER)) {
|
||||||
}
|
}
|
||||||
@@ -244,7 +242,7 @@ int32_t ifttt_virtual_button_app(void* p) {
|
|||||||
|
|
||||||
uint32_t first_scene = VirtualButtonAppSceneStart;
|
uint32_t first_scene = VirtualButtonAppSceneStart;
|
||||||
VirtualButtonApp* app = ifttt_virtual_button_app_alloc(first_scene);
|
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));
|
send_serial_command_config(ESerialCommand_Config, &(app->settings));
|
||||||
|
|
||||||
view_dispatcher_run(app->view_dispatcher);
|
view_dispatcher_run(app->view_dispatcher);
|
||||||
|
|||||||
@@ -25,11 +25,11 @@
|
|||||||
#define CONFIG_FILE_HEADER "IFTTT Virtual Button Config File"
|
#define CONFIG_FILE_HEADER "IFTTT Virtual Button Config File"
|
||||||
#define CONFIG_FILE_VERSION 1
|
#define CONFIG_FILE_VERSION 1
|
||||||
|
|
||||||
typedef struct{
|
typedef struct {
|
||||||
char *save_ssid;
|
char* save_ssid;
|
||||||
char *save_password;
|
char* save_password;
|
||||||
char *save_key;
|
char* save_key;
|
||||||
char *save_event;
|
char* save_event;
|
||||||
} Settings;
|
} Settings;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -53,4 +53,4 @@ typedef enum {
|
|||||||
} VirtualButtonAppView;
|
} VirtualButtonAppView;
|
||||||
|
|
||||||
Settings save_settings(Settings settings);
|
Settings save_settings(Settings settings);
|
||||||
Settings *load_settings();
|
Settings* load_settings();
|
||||||
@@ -21,7 +21,6 @@ static void about_view_draw_callback(Canvas* canvas, void* context) {
|
|||||||
canvas_draw_str_aligned(canvas, 0, 50, AlignLeft, AlignTop, "press back");
|
canvas_draw_str_aligned(canvas, 0, 50, AlignLeft, AlignTop, "press back");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AboutView* about_view_alloc() {
|
AboutView* about_view_alloc() {
|
||||||
AboutView* about_view = malloc(sizeof(AboutView));
|
AboutView* about_view = malloc(sizeof(AboutView));
|
||||||
about_view->view = view_alloc();
|
about_view->view = view_alloc();
|
||||||
|
|||||||
@@ -29,19 +29,19 @@ static void Shake(void) {
|
|||||||
void send_serial_command_send(ESerialCommand command) {
|
void send_serial_command_send(ESerialCommand command) {
|
||||||
uint8_t data[1] = {0};
|
uint8_t data[1] = {0};
|
||||||
|
|
||||||
char name[10] = "send";
|
char name[10] = "send";
|
||||||
int length = strlen(name);
|
int length = strlen(name);
|
||||||
for (int i = 0; i < length; i++){
|
for(int i = 0; i < length; i++) {
|
||||||
switch(command) {
|
switch(command) {
|
||||||
case ESerialCommand_Send:
|
case ESerialCommand_Send:
|
||||||
data[0] = name[i];
|
data[0] = name[i];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1);
|
furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_view_draw_callback(Canvas* canvas, void* context) {
|
static void send_view_draw_callback(Canvas* canvas, void* context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user