2022-06-01 21:40:20 +03:00
|
|
|
#include <furi.h>
|
2022-08-01 23:20:04 +03:00
|
|
|
|
2022-06-01 21:40:20 +03:00
|
|
|
#include <gui/gui.h>
|
|
|
|
#include <input/input.h>
|
2022-07-29 21:18:06 +03:00
|
|
|
#include <dialogs/dialogs.h>
|
2022-08-01 23:20:04 +03:00
|
|
|
#include <storage/storage.h>
|
2022-08-24 15:28:27 +03:00
|
|
|
|
|
|
|
#include <notification/notification.h>
|
2022-06-01 21:40:20 +03:00
|
|
|
#include <notification/notification_messages.h>
|
|
|
|
|
|
|
|
#include <assets_icons.h>
|
|
|
|
|
2022-08-01 23:20:04 +03:00
|
|
|
#include <flipper_format/flipper_format_i.h>
|
|
|
|
#include <lib/toolbox/path.h>
|
2022-09-14 21:04:04 +03:00
|
|
|
#include <applications/main/subghz/subghz_i.h>
|
2022-08-01 23:20:04 +03:00
|
|
|
|
2022-08-12 02:55:19 +03:00
|
|
|
#include <lib/subghz/protocols/raw.h>
|
2022-10-18 19:51:44 +03:00
|
|
|
#include <lib/subghz/protocols/protocol_items.h>
|
2022-08-15 00:26:49 +03:00
|
|
|
#include <lib/subghz/types.h>
|
2022-08-23 15:48:08 +03:00
|
|
|
#include <lib/subghz/protocols/keeloq.h>
|
|
|
|
#include <lib/subghz/protocols/star_line.h>
|
2022-08-12 02:55:19 +03:00
|
|
|
|
2022-08-01 23:20:04 +03:00
|
|
|
#define UNIRFMAP_FOLDER "/ext/unirf"
|
|
|
|
#define UNIRFMAP_EXTENSION ".txt"
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-08-01 23:20:04 +03:00
|
|
|
#define TAG "UniRF Remix"
|
2022-07-29 21:18:06 +03:00
|
|
|
|
2022-08-24 23:14:33 +03:00
|
|
|
typedef struct {
|
|
|
|
uint32_t frequency;
|
2022-10-05 21:27:13 +03:00
|
|
|
FuriString* name;
|
2022-08-24 23:14:33 +03:00
|
|
|
|
2022-10-05 21:27:13 +03:00
|
|
|
FuriString* protocol;
|
2022-08-24 23:14:33 +03:00
|
|
|
uint32_t repeat;
|
|
|
|
|
|
|
|
uint8_t* data;
|
|
|
|
size_t data_size;
|
|
|
|
|
|
|
|
SubGhzProtocolDecoderBase* decoder;
|
|
|
|
} UniRFPreset;
|
|
|
|
|
2022-06-01 21:40:20 +03:00
|
|
|
typedef struct {
|
2022-07-20 19:01:38 +03:00
|
|
|
FuriMutex* model_mutex;
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-07-20 19:01:38 +03:00
|
|
|
FuriMessageQueue* input_queue;
|
2022-06-01 21:40:20 +03:00
|
|
|
|
|
|
|
ViewPort* view_port;
|
|
|
|
Gui* gui;
|
|
|
|
|
2022-08-15 00:26:49 +03:00
|
|
|
SubGhzSetting* setting;
|
2022-08-23 15:48:08 +03:00
|
|
|
SubGhzEnvironment* environment;
|
2022-08-23 21:47:54 +03:00
|
|
|
SubGhzReceiver* subghz_receiver;
|
2022-08-24 15:28:27 +03:00
|
|
|
NotificationApp* notification;
|
2022-08-24 23:14:33 +03:00
|
|
|
UniRFPreset* txpreset;
|
2022-08-15 00:26:49 +03:00
|
|
|
|
2022-10-05 21:27:13 +03:00
|
|
|
FuriString* up_file;
|
|
|
|
FuriString* down_file;
|
|
|
|
FuriString* left_file;
|
|
|
|
FuriString* right_file;
|
|
|
|
FuriString* ok_file;
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-10-05 21:27:13 +03:00
|
|
|
FuriString* file_path;
|
2022-08-01 23:20:04 +03:00
|
|
|
|
2022-06-01 21:40:20 +03:00
|
|
|
char* up_label;
|
|
|
|
char* down_label;
|
|
|
|
char* left_label;
|
|
|
|
char* right_label;
|
|
|
|
char* ok_label;
|
|
|
|
|
|
|
|
int up_enabled;
|
|
|
|
int down_enabled;
|
|
|
|
int left_enabled;
|
|
|
|
int right_enabled;
|
|
|
|
int ok_enabled;
|
|
|
|
|
|
|
|
char* send_status;
|
|
|
|
int send_status_c;
|
|
|
|
int processing;
|
2022-08-24 23:14:33 +03:00
|
|
|
|
|
|
|
SubGhzTransmitter* tx_transmitter;
|
|
|
|
FlipperFormat* tx_fff_data;
|
|
|
|
const char* tx_file_path;
|
2022-06-01 21:40:20 +03:00
|
|
|
int button;
|
|
|
|
|
|
|
|
int file_result;
|
2022-08-03 04:53:11 +03:00
|
|
|
bool tx_not_allowed;
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-10-05 21:27:13 +03:00
|
|
|
FuriString* signal;
|
2022-06-01 21:40:20 +03:00
|
|
|
} UniRFRemix;
|
|
|
|
|
2022-08-23 21:47:54 +03:00
|
|
|
UniRFPreset* unirfremix_preset_alloc(void) {
|
2022-08-15 00:26:49 +03:00
|
|
|
UniRFPreset* preset = malloc(sizeof(UniRFPreset));
|
2022-10-05 21:27:13 +03:00
|
|
|
preset->name = furi_string_alloc();
|
|
|
|
preset->protocol = furi_string_alloc();
|
2022-08-23 21:47:54 +03:00
|
|
|
preset->repeat = 200;
|
2022-08-15 00:26:49 +03:00
|
|
|
return preset;
|
|
|
|
}
|
|
|
|
|
2022-08-23 21:47:54 +03:00
|
|
|
void unirfremix_preset_free(UniRFPreset* preset) {
|
2022-10-05 21:27:13 +03:00
|
|
|
furi_string_free(preset->name);
|
|
|
|
furi_string_free(preset->protocol);
|
2022-08-23 15:48:08 +03:00
|
|
|
free(preset);
|
|
|
|
}
|
|
|
|
|
2022-06-01 21:40:20 +03:00
|
|
|
static char* char_to_str(char* str, int i) {
|
|
|
|
char* converted = malloc(sizeof(char) * i + 1);
|
|
|
|
memcpy(converted, str, i);
|
|
|
|
|
|
|
|
converted[i] = '\0';
|
|
|
|
|
|
|
|
return converted;
|
|
|
|
}
|
2022-11-10 12:15:10 +03:00
|
|
|
|
2022-06-01 21:40:20 +03:00
|
|
|
//get filename without path
|
|
|
|
static char* extract_filename(const char* name, int len) {
|
2022-10-05 21:27:13 +03:00
|
|
|
FuriString* tmp;
|
|
|
|
tmp = furi_string_alloc();
|
2022-06-01 21:40:20 +03:00
|
|
|
|
|
|
|
//remove path
|
|
|
|
path_extract_filename_no_ext(name, tmp);
|
|
|
|
|
2022-10-05 21:27:13 +03:00
|
|
|
return char_to_str((char*)furi_string_get_cstr(tmp), len);
|
2022-06-01 21:40:20 +03:00
|
|
|
}
|
|
|
|
|
2022-11-10 12:15:10 +03:00
|
|
|
static void cfg_read_file_path(
|
|
|
|
FlipperFormat* fff_file,
|
|
|
|
FuriString* text_file_path,
|
|
|
|
char** text_file_label,
|
|
|
|
const char* read_key,
|
|
|
|
int* is_enabled) {
|
|
|
|
if(!flipper_format_read_string(fff_file, read_key, text_file_path)) {
|
|
|
|
FURI_LOG_W(TAG, "Could not read %s string", read_key);
|
|
|
|
*text_file_label = "N/A";
|
|
|
|
*is_enabled = 0;
|
|
|
|
} else {
|
|
|
|
*text_file_label = extract_filename(furi_string_get_cstr(text_file_path), 16);
|
|
|
|
FURI_LOG_D(TAG, "%s file: %s", read_key, furi_string_get_cstr(text_file_path));
|
|
|
|
*is_enabled = 1;
|
|
|
|
}
|
|
|
|
flipper_format_rewind(fff_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cfg_read_file_label(
|
|
|
|
FlipperFormat* fff_file,
|
|
|
|
char** text_file_label,
|
|
|
|
const char* read_key,
|
|
|
|
bool is_enabled) {
|
|
|
|
FuriString* temp_label = furi_string_alloc();
|
|
|
|
|
|
|
|
if(!flipper_format_read_string(fff_file, read_key, temp_label)) {
|
|
|
|
FURI_LOG_W(TAG, "Could not read %s string", read_key);
|
|
|
|
} else {
|
|
|
|
if(is_enabled == 1) {
|
|
|
|
*text_file_label = char_to_str((char*)furi_string_get_cstr(temp_label), 16);
|
|
|
|
}
|
|
|
|
FURI_LOG_D(TAG, "%s label: %s", read_key, *text_file_label);
|
|
|
|
}
|
|
|
|
flipper_format_rewind(fff_file);
|
|
|
|
furi_string_free(temp_label);
|
|
|
|
}
|
|
|
|
|
2022-06-01 21:40:20 +03:00
|
|
|
/*
|
2022-08-23 21:47:54 +03:00
|
|
|
* check that map file exists
|
|
|
|
* assign variables to values within map file
|
|
|
|
* set missing filenames to N/A
|
|
|
|
* set filename as label if label definitions are missing
|
|
|
|
* set error flag if all buttons are N/A
|
|
|
|
* set error flag if missing map file
|
|
|
|
*/
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-10-05 21:27:13 +03:00
|
|
|
void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) {
|
2022-08-15 00:26:49 +03:00
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
2022-06-01 21:40:20 +03:00
|
|
|
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
|
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
app->file_result = 1;
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
app->up_enabled = 0;
|
|
|
|
app->down_enabled = 0;
|
|
|
|
app->left_enabled = 0;
|
|
|
|
app->right_enabled = 0;
|
|
|
|
app->ok_enabled = 0;
|
2022-06-01 21:40:20 +03:00
|
|
|
|
|
|
|
//check that map file exists
|
2022-10-05 21:27:13 +03:00
|
|
|
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
|
|
|
|
FURI_LOG_E(TAG, "Could not open MAP file %s", furi_string_get_cstr(file_name));
|
2022-06-13 23:40:23 +03:00
|
|
|
} else {
|
|
|
|
//Filename Assignment/Check Start
|
2022-06-01 21:40:20 +03:00
|
|
|
|
|
|
|
//assign variables to values within map file
|
|
|
|
//set missing filenames to N/A
|
2022-11-10 12:15:10 +03:00
|
|
|
cfg_read_file_path(fff_data_file, app->up_file, &app->up_label, "UP", &app->up_enabled);
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-11-10 12:15:10 +03:00
|
|
|
cfg_read_file_path(
|
|
|
|
fff_data_file, app->down_file, &app->down_label, "DOWN", &app->down_enabled);
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-11-10 12:15:10 +03:00
|
|
|
cfg_read_file_path(
|
|
|
|
fff_data_file, app->left_file, &app->left_label, "LEFT", &app->left_enabled);
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-11-10 12:15:10 +03:00
|
|
|
cfg_read_file_path(
|
|
|
|
fff_data_file, app->right_file, &app->right_label, "RIGHT", &app->right_enabled);
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-11-10 12:15:10 +03:00
|
|
|
cfg_read_file_path(fff_data_file, app->ok_file, &app->ok_label, "OK", &app->ok_enabled);
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-06-12 05:42:37 +03:00
|
|
|
//File definitions are done.
|
|
|
|
//File checks will follow after label assignment in order to close the universal_rf_map file without the need to reopen it again.
|
|
|
|
|
2022-06-01 21:40:20 +03:00
|
|
|
//Label Assignment/Check Start
|
|
|
|
|
2022-11-10 12:15:10 +03:00
|
|
|
cfg_read_file_label(fff_data_file, &app->up_label, "ULABEL", app->up_enabled);
|
|
|
|
cfg_read_file_label(fff_data_file, &app->down_label, "DLABEL", app->down_enabled);
|
|
|
|
cfg_read_file_label(fff_data_file, &app->left_label, "LLABEL", app->left_enabled);
|
|
|
|
cfg_read_file_label(fff_data_file, &app->right_label, "RLABEL", app->right_enabled);
|
|
|
|
cfg_read_file_label(fff_data_file, &app->ok_label, "OKLABEL", app->ok_enabled);
|
2022-06-01 21:40:20 +03:00
|
|
|
}
|
|
|
|
|
2022-08-23 21:47:54 +03:00
|
|
|
flipper_format_file_close(fff_data_file);
|
2022-06-01 21:40:20 +03:00
|
|
|
flipper_format_free(fff_data_file);
|
2022-08-23 21:47:54 +03:00
|
|
|
|
2022-06-13 23:40:23 +03:00
|
|
|
//File Existence Check
|
|
|
|
//Check each file definition if not already set to "N/A"
|
|
|
|
|
|
|
|
//determine if files exist.
|
|
|
|
//determine whether or not to continue to launch app with missing variables
|
|
|
|
//if 5 files are missing, throw error
|
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
//if button is still enabled, check that file exists
|
|
|
|
if(app->up_enabled == 1) {
|
|
|
|
furi_string_set(file_name, app->up_file);
|
|
|
|
fff_data_file = flipper_format_file_alloc(storage);
|
2022-06-13 23:40:23 +03:00
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
|
|
|
|
FURI_LOG_W(TAG, "Could not open UP file %s", furi_string_get_cstr(file_name));
|
2022-06-13 23:40:23 +03:00
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
//disable button, and set label to "N/A"
|
|
|
|
app->up_enabled = 0;
|
|
|
|
app->up_label = "N/A";
|
2022-06-13 23:40:23 +03:00
|
|
|
}
|
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
//close the file
|
|
|
|
flipper_format_file_close(fff_data_file);
|
|
|
|
flipper_format_free(fff_data_file);
|
|
|
|
}
|
2022-06-13 23:40:23 +03:00
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
if(app->down_enabled == 1) {
|
|
|
|
furi_string_set(file_name, app->down_file);
|
|
|
|
fff_data_file = flipper_format_file_alloc(storage);
|
2022-06-13 23:40:23 +03:00
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
|
|
|
|
FURI_LOG_W(TAG, "Could not open DOWN file %s", furi_string_get_cstr(file_name));
|
2022-06-13 23:40:23 +03:00
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
app->down_enabled = 0;
|
|
|
|
app->down_label = "N/A";
|
2022-06-13 23:40:23 +03:00
|
|
|
}
|
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
flipper_format_file_close(fff_data_file);
|
|
|
|
flipper_format_free(fff_data_file);
|
|
|
|
}
|
2022-06-13 23:40:23 +03:00
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
if(app->left_enabled == 1) {
|
|
|
|
furi_string_set(file_name, app->left_file);
|
|
|
|
fff_data_file = flipper_format_file_alloc(storage);
|
2022-06-13 23:40:23 +03:00
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
|
|
|
|
FURI_LOG_W(TAG, "Could not open LEFT file %s", furi_string_get_cstr(file_name));
|
2022-06-13 23:40:23 +03:00
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
app->left_enabled = 0;
|
|
|
|
app->left_label = "N/A";
|
2022-06-13 23:40:23 +03:00
|
|
|
}
|
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
flipper_format_file_close(fff_data_file);
|
|
|
|
flipper_format_free(fff_data_file);
|
|
|
|
}
|
2022-06-13 23:40:23 +03:00
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
if(app->right_enabled == 1) {
|
|
|
|
furi_string_set(file_name, app->right_file);
|
|
|
|
fff_data_file = flipper_format_file_alloc(storage);
|
2022-06-13 23:40:23 +03:00
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
|
|
|
|
FURI_LOG_W(TAG, "Could not open RIGHT file %s", furi_string_get_cstr(file_name));
|
2022-06-13 23:40:23 +03:00
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
app->right_enabled = 0;
|
|
|
|
app->right_label = "N/A";
|
2022-06-13 23:40:23 +03:00
|
|
|
}
|
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
flipper_format_file_close(fff_data_file);
|
|
|
|
flipper_format_free(fff_data_file);
|
|
|
|
}
|
2022-06-13 23:40:23 +03:00
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
if(app->ok_enabled == 1) {
|
|
|
|
furi_string_set(file_name, app->ok_file);
|
|
|
|
fff_data_file = flipper_format_file_alloc(storage);
|
2022-06-13 23:40:23 +03:00
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
|
|
|
|
FURI_LOG_W(TAG, "Could not open OK file %s", furi_string_get_cstr(file_name));
|
2022-06-13 23:40:23 +03:00
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
app->ok_enabled = 0;
|
|
|
|
app->ok_label = "N/A";
|
2022-06-13 23:40:23 +03:00
|
|
|
}
|
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
flipper_format_file_close(fff_data_file);
|
|
|
|
flipper_format_free(fff_data_file);
|
|
|
|
}
|
2022-08-24 23:14:33 +03:00
|
|
|
|
2022-10-21 09:29:07 +03:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
|
|
|
|
|
|
|
if(app->up_enabled == 0 && app->down_enabled == 0 && app->left_enabled == 0 &&
|
|
|
|
app->right_enabled == 0 && app->ok_enabled == 0) {
|
|
|
|
app->file_result = 1;
|
|
|
|
} else {
|
|
|
|
app->file_result = 2;
|
2022-06-13 23:40:23 +03:00
|
|
|
}
|
2022-06-01 21:40:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void unirfremix_end_send(UniRFRemix* app) {
|
|
|
|
app->processing = 0;
|
|
|
|
}
|
|
|
|
|
2022-08-23 21:47:54 +03:00
|
|
|
bool unirfremix_set_preset(UniRFPreset* p, const char* preset) {
|
2022-08-15 00:26:49 +03:00
|
|
|
if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) {
|
2022-10-05 21:27:13 +03:00
|
|
|
furi_string_set(p->name, "AM270");
|
2022-08-15 00:26:49 +03:00
|
|
|
} else if(!strcmp(preset, "FuriHalSubGhzPresetOok650Async")) {
|
2022-10-05 21:27:13 +03:00
|
|
|
furi_string_set(p->name, "AM650");
|
2022-08-15 00:26:49 +03:00
|
|
|
} else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev238Async")) {
|
2022-10-05 21:27:13 +03:00
|
|
|
furi_string_set(p->name, "FM238");
|
2022-08-15 00:26:49 +03:00
|
|
|
} else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev476Async")) {
|
2022-10-05 21:27:13 +03:00
|
|
|
furi_string_set(p->name, "FM476");
|
2022-08-15 00:26:49 +03:00
|
|
|
} else if(!strcmp(preset, "FuriHalSubGhzPresetCustom")) {
|
2022-08-25 03:21:44 +03:00
|
|
|
FURI_LOG_E(TAG, "Custom preset unsupported now");
|
|
|
|
return false;
|
2022-10-05 21:27:13 +03:00
|
|
|
// furi_string_set(p->name, "CUSTOM");
|
2022-08-15 00:26:49 +03:00
|
|
|
} else {
|
|
|
|
FURI_LOG_E(TAG, "Unsupported preset");
|
|
|
|
return false;
|
2022-08-12 02:55:19 +03:00
|
|
|
}
|
2022-08-15 00:26:49 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-08-23 21:47:54 +03:00
|
|
|
bool unirfremix_key_load(
|
2022-08-15 00:26:49 +03:00
|
|
|
UniRFPreset* preset,
|
|
|
|
FlipperFormat* fff_file,
|
|
|
|
FlipperFormat* fff_data,
|
|
|
|
SubGhzSetting* setting,
|
|
|
|
SubGhzReceiver* receiver,
|
|
|
|
const char* path) {
|
|
|
|
//
|
|
|
|
if(!flipper_format_rewind(fff_file)) {
|
|
|
|
FURI_LOG_E(TAG, "Rewind error");
|
2022-08-24 15:28:27 +03:00
|
|
|
return false;
|
2022-08-12 02:55:19 +03:00
|
|
|
}
|
2022-08-15 00:26:49 +03:00
|
|
|
|
2022-10-05 21:27:13 +03:00
|
|
|
FuriString* temp_str;
|
|
|
|
temp_str = furi_string_alloc();
|
2022-08-15 00:26:49 +03:00
|
|
|
|
|
|
|
bool res = false;
|
|
|
|
|
|
|
|
do {
|
|
|
|
// load frequency from file
|
2022-08-23 21:47:54 +03:00
|
|
|
if(!flipper_format_read_uint32(fff_file, "Frequency", &preset->frequency, 1)) {
|
2022-08-15 00:26:49 +03:00
|
|
|
FURI_LOG_W(TAG, "Cannot read frequency. Defaulting to 433.92 MHz");
|
2022-08-23 21:47:54 +03:00
|
|
|
preset->frequency = 433920000;
|
2022-08-15 00:26:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// load preset from file
|
|
|
|
if(!flipper_format_read_string(fff_file, "Preset", temp_str)) {
|
|
|
|
FURI_LOG_W(TAG, "Could not read Preset. Defaulting to Ook650Async");
|
2022-10-05 21:27:13 +03:00
|
|
|
furi_string_set(temp_str, "FuriHalSubGhzPresetOok650Async");
|
2022-08-15 00:26:49 +03:00
|
|
|
}
|
2022-10-05 21:27:13 +03:00
|
|
|
if(!unirfremix_set_preset(preset, furi_string_get_cstr(temp_str))) {
|
2022-08-15 00:26:49 +03:00
|
|
|
FURI_LOG_E(TAG, "Could not set preset");
|
|
|
|
break;
|
|
|
|
}
|
2022-10-05 21:27:13 +03:00
|
|
|
if(!strcmp(furi_string_get_cstr(temp_str), "FuriHalSubGhzPresetCustom")) {
|
2022-08-15 00:26:49 +03:00
|
|
|
// TODO: check if preset is custom
|
2022-08-25 03:21:44 +03:00
|
|
|
FURI_LOG_E(TAG, "Could not use custom preset");
|
|
|
|
break;
|
2022-08-15 00:26:49 +03:00
|
|
|
}
|
|
|
|
size_t preset_index =
|
2022-10-05 21:27:13 +03:00
|
|
|
subghz_setting_get_inx_preset_by_name(setting, furi_string_get_cstr(preset->name));
|
2022-08-15 00:26:49 +03:00
|
|
|
preset->data = subghz_setting_get_preset_data(setting, preset_index);
|
|
|
|
preset->data_size = subghz_setting_get_preset_data_size(setting, preset_index);
|
|
|
|
|
|
|
|
// load protocol from file
|
2022-08-23 21:47:54 +03:00
|
|
|
if(!flipper_format_read_string(fff_file, "Protocol", preset->protocol)) {
|
|
|
|
FURI_LOG_E(TAG, "Could not read Protocol.");
|
2022-08-15 00:26:49 +03:00
|
|
|
break;
|
|
|
|
}
|
2022-10-05 21:27:13 +03:00
|
|
|
if(!furi_string_cmp_str(preset->protocol, "RAW")) {
|
2022-08-15 00:26:49 +03:00
|
|
|
subghz_protocol_raw_gen_fff_data(fff_data, path);
|
|
|
|
} else {
|
|
|
|
stream_copy_full(
|
|
|
|
flipper_format_get_raw_stream(fff_file), flipper_format_get_raw_stream(fff_data));
|
|
|
|
}
|
2022-08-19 04:38:35 +03:00
|
|
|
|
2022-08-23 21:47:54 +03:00
|
|
|
// repeat
|
|
|
|
if(!flipper_format_insert_or_update_uint32(fff_file, "Repeat", &preset->repeat, 1)) {
|
|
|
|
FURI_LOG_E(TAG, "Unable to insert or update Repeat");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
preset->decoder = subghz_receiver_search_decoder_base_by_name(
|
2022-10-05 21:27:13 +03:00
|
|
|
receiver, furi_string_get_cstr(preset->protocol));
|
2022-08-19 04:38:35 +03:00
|
|
|
if(preset->decoder) {
|
|
|
|
if(!subghz_protocol_decoder_base_deserialize(preset->decoder, fff_data)) {
|
2022-08-15 00:26:49 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2022-10-05 21:27:13 +03:00
|
|
|
FURI_LOG_E(TAG, "Protocol %s not found", furi_string_get_cstr(temp_str));
|
2022-08-15 00:26:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
res = true;
|
|
|
|
} while(0);
|
|
|
|
|
2022-10-05 21:27:13 +03:00
|
|
|
furi_string_free(temp_str);
|
2022-08-15 00:26:49 +03:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
// method modified from subghz_i.c
|
2022-08-23 21:47:54 +03:00
|
|
|
// https://github.com/flipperdevices/flipperzero-firmware/blob/b0daa601ad5b87427a45f9089c8b403a01f72c2a/applications/subghz/subghz_i.c#L417-L456
|
|
|
|
bool unirfremix_save_protocol_to_file(FlipperFormat* fff_file, const char* dev_file_name) {
|
2022-08-15 00:26:49 +03:00
|
|
|
furi_assert(fff_file);
|
|
|
|
furi_assert(dev_file_name);
|
|
|
|
|
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
|
Stream* flipper_format_stream = flipper_format_get_raw_stream(fff_file);
|
|
|
|
|
|
|
|
bool saved = false;
|
2022-10-05 21:27:13 +03:00
|
|
|
FuriString* file_dir;
|
|
|
|
file_dir = furi_string_alloc();
|
2022-08-15 00:26:49 +03:00
|
|
|
|
|
|
|
path_extract_dirname(dev_file_name, file_dir);
|
|
|
|
do {
|
|
|
|
flipper_format_delete_key(fff_file, "Repeat");
|
2022-10-12 04:18:29 +03:00
|
|
|
//flipper_format_delete_key(fff_file, "Manufacture");
|
2022-08-15 00:26:49 +03:00
|
|
|
|
2022-10-05 21:27:13 +03:00
|
|
|
if(!storage_simply_mkdir(storage, furi_string_get_cstr(file_dir))) {
|
2022-08-15 00:52:05 +03:00
|
|
|
FURI_LOG_E(TAG, "(save) Cannot mkdir");
|
2022-08-15 00:26:49 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!storage_simply_remove(storage, dev_file_name)) {
|
2022-08-15 00:52:05 +03:00
|
|
|
FURI_LOG_E(TAG, "(save) Cannot remove");
|
2022-08-15 00:26:49 +03:00
|
|
|
break;
|
|
|
|
}
|
2022-08-24 15:28:27 +03:00
|
|
|
|
2022-08-15 00:26:49 +03:00
|
|
|
stream_seek(flipper_format_stream, 0, StreamOffsetFromStart);
|
|
|
|
stream_save_to_file(flipper_format_stream, storage, dev_file_name, FSOM_CREATE_ALWAYS);
|
|
|
|
|
|
|
|
saved = true;
|
2022-08-23 21:47:54 +03:00
|
|
|
FURI_LOG_D(TAG, "(save) OK Save");
|
2022-08-15 00:26:49 +03:00
|
|
|
} while(0);
|
2022-10-05 21:27:13 +03:00
|
|
|
furi_string_free(file_dir);
|
2022-08-15 00:26:49 +03:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
|
|
|
return saved;
|
2022-08-12 02:55:19 +03:00
|
|
|
}
|
|
|
|
|
2022-08-24 23:14:33 +03:00
|
|
|
void unirfremix_tx_stop(UniRFRemix* app) {
|
2022-08-25 03:21:44 +03:00
|
|
|
if(app->processing == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-05 21:27:13 +03:00
|
|
|
if(!furi_string_cmp_str(app->txpreset->protocol, "RAW")) {
|
2022-08-24 23:14:33 +03:00
|
|
|
while(!furi_hal_subghz_is_async_tx_complete()) {
|
2022-08-25 03:21:44 +03:00
|
|
|
furi_delay_ms(15);
|
2022-08-24 23:14:33 +03:00
|
|
|
}
|
|
|
|
}
|
2022-08-25 03:21:44 +03:00
|
|
|
|
2022-08-24 23:14:33 +03:00
|
|
|
//Stop TX
|
|
|
|
furi_hal_subghz_stop_async_tx();
|
2022-11-10 12:15:10 +03:00
|
|
|
//FURI_LOG_I(TAG, "TX Done!");
|
2022-08-24 23:14:33 +03:00
|
|
|
subghz_transmitter_stop(app->tx_transmitter);
|
|
|
|
|
|
|
|
FURI_LOG_D(TAG, "Checking if protocol is dynamic");
|
2022-10-18 19:51:44 +03:00
|
|
|
const SubGhzProtocolRegistry* protocol_registry_items =
|
|
|
|
subghz_environment_get_protocol_registry(app->environment);
|
|
|
|
const SubGhzProtocol* proto = subghz_protocol_registry_get_by_name(
|
|
|
|
protocol_registry_items, furi_string_get_cstr(app->txpreset->protocol));
|
|
|
|
FURI_LOG_D(TAG, "Protocol-TYPE %d", proto->type);
|
|
|
|
if(proto && proto->type == SubGhzProtocolTypeDynamic) {
|
2022-08-24 23:14:33 +03:00
|
|
|
FURI_LOG_D(TAG, "Protocol is dynamic. Saving key");
|
|
|
|
unirfremix_save_protocol_to_file(app->tx_fff_data, app->tx_file_path);
|
|
|
|
|
|
|
|
keeloq_reset_mfname();
|
|
|
|
keeloq_reset_kl_type();
|
|
|
|
star_line_reset_mfname();
|
|
|
|
star_line_reset_kl_type();
|
|
|
|
}
|
|
|
|
|
|
|
|
subghz_transmitter_free(app->tx_transmitter);
|
|
|
|
furi_hal_subghz_idle();
|
|
|
|
|
|
|
|
notification_message(app->notification, &sequence_blink_stop);
|
|
|
|
|
|
|
|
unirfremix_preset_free(app->txpreset);
|
|
|
|
flipper_format_free(app->tx_fff_data);
|
|
|
|
unirfremix_end_send(app);
|
|
|
|
}
|
2022-08-12 02:55:19 +03:00
|
|
|
|
2022-08-24 23:14:33 +03:00
|
|
|
static bool unirfremix_send_sub(UniRFRemix* app, FlipperFormat* fff_data) {
|
|
|
|
//
|
2022-08-23 21:47:54 +03:00
|
|
|
bool res = false;
|
|
|
|
do {
|
2022-08-24 23:14:33 +03:00
|
|
|
if(!furi_hal_subghz_is_tx_allowed(app->txpreset->frequency)) {
|
2022-08-15 00:26:49 +03:00
|
|
|
printf(
|
|
|
|
"In your settings, only reception on this frequency (%lu) is allowed,\r\n"
|
|
|
|
"the actual operation of the unirf app is not possible\r\n ",
|
2022-08-24 23:14:33 +03:00
|
|
|
app->txpreset->frequency);
|
2022-08-15 00:26:49 +03:00
|
|
|
app->tx_not_allowed = true;
|
|
|
|
unirfremix_end_send(app);
|
2022-08-23 21:47:54 +03:00
|
|
|
break;
|
2022-08-15 00:26:49 +03:00
|
|
|
} else {
|
|
|
|
app->tx_not_allowed = false;
|
|
|
|
}
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-08-24 23:14:33 +03:00
|
|
|
app->tx_transmitter = subghz_transmitter_alloc_init(
|
2022-10-05 21:27:13 +03:00
|
|
|
app->environment, furi_string_get_cstr(app->txpreset->protocol));
|
2022-08-24 23:14:33 +03:00
|
|
|
if(!app->tx_transmitter) {
|
2022-08-15 00:26:49 +03:00
|
|
|
break;
|
|
|
|
}
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-08-24 23:14:33 +03:00
|
|
|
subghz_transmitter_deserialize(app->tx_transmitter, fff_data);
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-08-23 21:47:54 +03:00
|
|
|
furi_hal_subghz_reset();
|
|
|
|
furi_hal_subghz_idle();
|
2022-08-24 23:14:33 +03:00
|
|
|
furi_hal_subghz_load_custom_preset(app->txpreset->data);
|
2022-08-23 21:47:54 +03:00
|
|
|
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
2022-08-15 00:26:49 +03:00
|
|
|
|
2022-08-23 21:47:54 +03:00
|
|
|
furi_hal_subghz_idle();
|
2022-10-26 22:47:32 +03:00
|
|
|
|
2022-08-24 23:14:33 +03:00
|
|
|
furi_hal_subghz_set_frequency_and_path(app->txpreset->frequency);
|
2022-10-26 22:47:32 +03:00
|
|
|
furi_hal_gpio_write(&gpio_cc1101_g0, false);
|
2022-08-23 21:47:54 +03:00
|
|
|
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-08-23 21:47:54 +03:00
|
|
|
if(!furi_hal_subghz_tx()) {
|
|
|
|
FURI_LOG_E(TAG, "Sending not allowed");
|
2022-08-24 15:28:27 +03:00
|
|
|
break;
|
2022-08-23 21:47:54 +03:00
|
|
|
}
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-11-10 12:15:10 +03:00
|
|
|
//FURI_LOG_I(TAG, "Sending...");
|
2022-08-24 23:14:33 +03:00
|
|
|
notification_message(app->notification, &sequence_blink_start_magenta);
|
2022-08-19 04:38:35 +03:00
|
|
|
|
2022-08-24 23:14:33 +03:00
|
|
|
furi_hal_subghz_start_async_tx(subghz_transmitter_yield, app->tx_transmitter);
|
2022-08-15 00:26:49 +03:00
|
|
|
|
2022-08-15 00:52:05 +03:00
|
|
|
res = true;
|
2022-08-23 21:47:54 +03:00
|
|
|
} while(0);
|
2022-08-23 15:48:08 +03:00
|
|
|
|
2022-08-15 00:52:05 +03:00
|
|
|
return res;
|
2022-08-12 02:55:19 +03:00
|
|
|
}
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-08-19 04:38:35 +03:00
|
|
|
static void unirfremix_send_signal(UniRFRemix* app, Storage* storage, const char* path) {
|
2022-11-10 12:15:10 +03:00
|
|
|
FURI_LOG_D(TAG, "Sending: %s", path);
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-08-24 23:14:33 +03:00
|
|
|
app->tx_file_path = path;
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-08-24 23:14:33 +03:00
|
|
|
app->tx_fff_data = flipper_format_string_alloc();
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-08-24 23:14:33 +03:00
|
|
|
app->txpreset = unirfremix_preset_alloc();
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-08-24 23:14:33 +03:00
|
|
|
// load settings/stream from .sub file
|
|
|
|
FlipperFormat* fff_file = flipper_format_file_alloc(storage);
|
|
|
|
bool open_ok = false;
|
|
|
|
do {
|
|
|
|
if(!flipper_format_file_open_existing(fff_file, path)) {
|
|
|
|
FURI_LOG_E(TAG, "Could not open file %s", path);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!unirfremix_key_load(
|
|
|
|
app->txpreset,
|
|
|
|
fff_file,
|
|
|
|
app->tx_fff_data,
|
|
|
|
app->setting,
|
|
|
|
app->subghz_receiver,
|
|
|
|
path)) {
|
|
|
|
FURI_LOG_E(TAG, "Could not load key");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
open_ok = true;
|
|
|
|
} while(0);
|
|
|
|
flipper_format_free(fff_file);
|
|
|
|
if(!open_ok) {
|
|
|
|
FURI_LOG_E(TAG, "Could not load file!");
|
|
|
|
return;
|
|
|
|
}
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-08-24 23:14:33 +03:00
|
|
|
unirfremix_send_sub(app, app->tx_fff_data);
|
2022-08-12 02:55:19 +03:00
|
|
|
}
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-10-05 21:27:13 +03:00
|
|
|
static void unirfremix_process_signal(UniRFRemix* app, FuriString* signal) {
|
2022-08-12 02:55:19 +03:00
|
|
|
view_port_update(app->view_port);
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-11-10 12:15:10 +03:00
|
|
|
FURI_LOG_D(TAG, "signal = %s", furi_string_get_cstr(signal));
|
2022-06-13 23:40:23 +03:00
|
|
|
|
2022-10-05 21:27:13 +03:00
|
|
|
if(strlen(furi_string_get_cstr(signal)) > 12) {
|
2022-08-12 02:55:19 +03:00
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
2022-10-05 21:27:13 +03:00
|
|
|
unirfremix_send_signal(app, storage, furi_string_get_cstr(signal));
|
2022-08-12 02:55:19 +03:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2022-10-05 21:27:13 +03:00
|
|
|
} else if(strlen(furi_string_get_cstr(signal)) < 10) {
|
2022-06-01 21:40:20 +03:00
|
|
|
unirfremix_end_send(app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void render_callback(Canvas* canvas, void* ctx) {
|
|
|
|
UniRFRemix* app = ctx;
|
2022-07-20 19:01:38 +03:00
|
|
|
furi_check(furi_mutex_acquire(app->model_mutex, FuriWaitForever) == FuriStatusOk);
|
2022-06-01 21:40:20 +03:00
|
|
|
|
|
|
|
//setup different canvas settings
|
|
|
|
if(app->file_result == 1) {
|
|
|
|
//if map has no valid filenames defined
|
|
|
|
canvas_clear(canvas);
|
|
|
|
canvas_set_font(canvas, FontPrimary);
|
2022-08-01 23:20:04 +03:00
|
|
|
canvas_draw_str_aligned(canvas, 62, 5, AlignCenter, AlignTop, "Config is incorrect.");
|
2022-06-01 21:40:20 +03:00
|
|
|
canvas_set_font(canvas, FontSecondary);
|
2022-08-01 23:20:04 +03:00
|
|
|
canvas_draw_str_aligned(canvas, 62, 30, AlignCenter, AlignTop, "Please configure map.");
|
2022-08-24 23:14:33 +03:00
|
|
|
canvas_draw_str_aligned(canvas, 62, 60, AlignCenter, AlignBottom, "Press Back to Exit.");
|
2022-10-21 09:29:07 +03:00
|
|
|
} else if(app->file_result == 3) {
|
|
|
|
//if map has no valid filenames defined
|
|
|
|
canvas_clear(canvas);
|
|
|
|
canvas_set_font(canvas, FontPrimary);
|
|
|
|
canvas_draw_str_aligned(canvas, 62, 5, AlignCenter, AlignTop, "Checking config.");
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
|
canvas_draw_str_aligned(canvas, 62, 30, AlignCenter, AlignTop, "If app is stuck...");
|
|
|
|
canvas_draw_str_aligned(canvas, 62, 60, AlignCenter, AlignBottom, "Press Back to Exit.");
|
2022-08-03 04:53:11 +03:00
|
|
|
} else if(app->tx_not_allowed) {
|
|
|
|
canvas_clear(canvas);
|
|
|
|
canvas_set_font(canvas, FontPrimary);
|
|
|
|
canvas_draw_str_aligned(canvas, 62, 5, AlignCenter, AlignTop, "Transmission is blocked.");
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
|
canvas_draw_str_aligned(canvas, 62, 15, AlignCenter, AlignTop, "Frequency is outside of");
|
|
|
|
canvas_draw_str_aligned(canvas, 62, 25, AlignCenter, AlignTop, "default range.");
|
|
|
|
canvas_draw_str_aligned(canvas, 62, 35, AlignCenter, AlignTop, "Check docs.");
|
2022-08-24 23:14:33 +03:00
|
|
|
canvas_draw_str_aligned(canvas, 62, 60, AlignCenter, AlignBottom, "Press Back to Exit.");
|
2022-06-01 21:40:20 +03:00
|
|
|
} else {
|
|
|
|
//map found, draw all the things
|
|
|
|
canvas_clear(canvas);
|
|
|
|
|
|
|
|
//canvas_set_font(canvas, FontPrimary);
|
|
|
|
//canvas_draw_str(canvas, 0, 10, "U: ");
|
|
|
|
//canvas_draw_str(canvas, 0, 20, "L: ");
|
|
|
|
//canvas_draw_str(canvas, 0, 30, "R: ");
|
|
|
|
//canvas_draw_str(canvas, 0, 40, "D: ");
|
|
|
|
//canvas_draw_str(canvas, 0, 50, "Ok: ");
|
|
|
|
|
|
|
|
//PNGs are located in assets/icons/UniRFRemix before compiliation
|
|
|
|
|
|
|
|
//Icons for Labels
|
2022-08-01 23:20:04 +03:00
|
|
|
//canvas_draw_icon(canvas, 0, 0, &I_UniRFRemix_LeftAlignedButtons_9x64);
|
|
|
|
canvas_draw_icon(canvas, 1, 5, &I_ButtonUp_7x4);
|
|
|
|
canvas_draw_icon(canvas, 1, 15, &I_ButtonDown_7x4);
|
|
|
|
canvas_draw_icon(canvas, 2, 23, &I_ButtonLeft_4x7);
|
|
|
|
canvas_draw_icon(canvas, 2, 33, &I_ButtonRight_4x7);
|
|
|
|
canvas_draw_icon(canvas, 0, 42, &I_Ok_btn_9x9);
|
|
|
|
canvas_draw_icon(canvas, 0, 53, &I_back_10px);
|
2022-06-01 21:40:20 +03:00
|
|
|
|
|
|
|
//Labels
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
2022-08-01 23:20:04 +03:00
|
|
|
canvas_draw_str(canvas, 10, 10, app->up_label);
|
|
|
|
canvas_draw_str(canvas, 10, 20, app->down_label);
|
|
|
|
canvas_draw_str(canvas, 10, 30, app->left_label);
|
|
|
|
canvas_draw_str(canvas, 10, 40, app->right_label);
|
|
|
|
canvas_draw_str(canvas, 10, 50, app->ok_label);
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-08-24 23:14:33 +03:00
|
|
|
canvas_draw_str_aligned(canvas, 11, 62, AlignLeft, AlignBottom, "Press=Exit.");
|
2022-06-01 21:40:20 +03:00
|
|
|
|
|
|
|
//Status text and indicator
|
2022-08-01 23:20:04 +03:00
|
|
|
canvas_draw_str_aligned(canvas, 126, 10, AlignRight, AlignBottom, app->send_status);
|
2022-06-01 21:40:20 +03:00
|
|
|
|
|
|
|
switch(app->send_status_c) {
|
|
|
|
case 0:
|
2022-08-01 23:20:04 +03:00
|
|
|
canvas_draw_icon(canvas, 113, 15, &I_Pin_cell_13x13);
|
2022-06-01 21:40:20 +03:00
|
|
|
break;
|
|
|
|
case 1:
|
2022-08-01 23:20:04 +03:00
|
|
|
canvas_draw_icon(canvas, 113, 15, &I_Pin_cell_13x13);
|
2022-09-19 21:21:31 +03:00
|
|
|
canvas_draw_icon(canvas, 116, 17, &I_Pin_arrow_up_7x9);
|
2022-06-01 21:40:20 +03:00
|
|
|
break;
|
|
|
|
case 2:
|
2022-08-01 23:20:04 +03:00
|
|
|
canvas_draw_icon(canvas, 113, 15, &I_Pin_cell_13x13);
|
|
|
|
canvas_draw_icon(canvas, 116, 17, &I_Pin_arrow_down_7x9);
|
2022-06-01 21:40:20 +03:00
|
|
|
break;
|
|
|
|
case 3:
|
2022-08-01 23:20:04 +03:00
|
|
|
canvas_draw_icon(canvas, 113, 15, &I_Pin_cell_13x13);
|
|
|
|
canvas_draw_icon(canvas, 115, 18, &I_Pin_arrow_right_9x7);
|
2022-06-01 21:40:20 +03:00
|
|
|
break;
|
|
|
|
case 4:
|
2022-08-01 23:20:04 +03:00
|
|
|
canvas_draw_icon(canvas, 113, 15, &I_Pin_cell_13x13);
|
|
|
|
canvas_draw_icon(canvas, 115, 18, &I_Pin_arrow_left_9x7);
|
2022-06-01 21:40:20 +03:00
|
|
|
break;
|
|
|
|
case 5:
|
2022-08-01 23:20:04 +03:00
|
|
|
canvas_draw_icon(canvas, 113, 15, &I_Pin_cell_13x13);
|
|
|
|
canvas_draw_icon(canvas, 116, 18, &I_Pin_star_7x7);
|
2022-06-01 21:40:20 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Repeat indicator
|
|
|
|
//canvas_draw_str_aligned(canvas, 125, 40, AlignRight, AlignBottom, "Repeat:");
|
2022-08-01 23:20:04 +03:00
|
|
|
//canvas_draw_icon(canvas, 115, 39, &I_UniRFRemix_Repeat_12x14);
|
2022-08-24 23:14:33 +03:00
|
|
|
//canvas_draw_str_aligned(canvas, 125, 62, AlignRight, AlignBottom, int_to_char(app->repeat));
|
2022-06-01 21:40:20 +03:00
|
|
|
}
|
|
|
|
|
2022-07-20 19:01:38 +03:00
|
|
|
furi_mutex_release(app->model_mutex);
|
2022-06-01 21:40:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void input_callback(InputEvent* input_event, void* ctx) {
|
|
|
|
UniRFRemix* app = ctx;
|
2022-08-01 23:20:04 +03:00
|
|
|
furi_message_queue_put(app->input_queue, input_event, 0);
|
2022-06-01 21:40:20 +03:00
|
|
|
}
|
|
|
|
|
2022-08-24 23:14:33 +03:00
|
|
|
void unirfremix_subghz_alloc(UniRFRemix* app) {
|
2022-08-23 15:48:08 +03:00
|
|
|
// load subghz presets
|
2022-08-15 00:26:49 +03:00
|
|
|
app->setting = subghz_setting_alloc();
|
2022-10-02 08:50:41 +03:00
|
|
|
subghz_setting_load(app->setting, EXT_PATH("subghz/assets/setting_user"), false);
|
2022-08-15 00:26:49 +03:00
|
|
|
|
2022-08-23 15:48:08 +03:00
|
|
|
// load mfcodes
|
|
|
|
app->environment = subghz_environment_alloc();
|
|
|
|
subghz_environment_load_keystore(app->environment, EXT_PATH("subghz/assets/keeloq_mfcodes"));
|
|
|
|
subghz_environment_load_keystore(
|
|
|
|
app->environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user"));
|
|
|
|
subghz_environment_set_came_atomo_rainbow_table_file_name(
|
|
|
|
app->environment, EXT_PATH("subghz/assets/came_atomo"));
|
|
|
|
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
|
|
|
app->environment, EXT_PATH("subghz/assets/nice_flor_s"));
|
2022-10-18 19:51:44 +03:00
|
|
|
subghz_environment_set_protocol_registry(app->environment, (void*)&subghz_protocol_registry);
|
2022-08-23 15:48:08 +03:00
|
|
|
|
2022-08-23 21:47:54 +03:00
|
|
|
app->subghz_receiver = subghz_receiver_alloc_init(app->environment);
|
2022-08-24 23:14:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
UniRFRemix* unirfremix_alloc(void) {
|
|
|
|
UniRFRemix* app = malloc(sizeof(UniRFRemix));
|
|
|
|
|
2022-09-19 05:22:50 +03:00
|
|
|
furi_hal_power_suppress_charge_enter();
|
|
|
|
|
2022-08-24 23:14:33 +03:00
|
|
|
app->model_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
|
|
|
|
|
|
|
app->input_queue = furi_message_queue_alloc(32, sizeof(InputEvent));
|
|
|
|
|
|
|
|
app->view_port = view_port_alloc();
|
|
|
|
view_port_draw_callback_set(app->view_port, render_callback, app);
|
|
|
|
view_port_input_callback_set(app->view_port, input_callback, app);
|
|
|
|
|
|
|
|
// Open GUI and register view_port
|
|
|
|
app->gui = furi_record_open(RECORD_GUI);
|
|
|
|
gui_add_view_port(app->gui, app->view_port, GuiLayerFullscreen);
|
2022-08-23 21:47:54 +03:00
|
|
|
|
2022-08-24 15:28:27 +03:00
|
|
|
app->notification = furi_record_open(RECORD_NOTIFICATION);
|
|
|
|
|
2022-06-01 21:40:20 +03:00
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
2022-09-19 05:22:50 +03:00
|
|
|
void unirfremix_free(UniRFRemix* app, bool with_subghz) {
|
|
|
|
furi_hal_power_suppress_charge_exit();
|
|
|
|
|
2022-10-05 21:27:13 +03:00
|
|
|
furi_string_free(app->up_file);
|
|
|
|
furi_string_free(app->down_file);
|
|
|
|
furi_string_free(app->left_file);
|
|
|
|
furi_string_free(app->right_file);
|
|
|
|
furi_string_free(app->ok_file);
|
2022-06-13 23:40:23 +03:00
|
|
|
|
2022-10-05 21:27:13 +03:00
|
|
|
furi_string_free(app->file_path);
|
|
|
|
furi_string_free(app->signal);
|
2022-08-01 23:20:04 +03:00
|
|
|
|
2022-06-01 21:40:20 +03:00
|
|
|
gui_remove_view_port(app->gui, app->view_port);
|
2022-08-01 23:20:04 +03:00
|
|
|
furi_record_close(RECORD_GUI);
|
2022-06-01 21:40:20 +03:00
|
|
|
view_port_free(app->view_port);
|
2022-09-17 17:53:44 +03:00
|
|
|
app->gui = NULL;
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-07-20 19:01:38 +03:00
|
|
|
furi_message_queue_free(app->input_queue);
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-07-20 19:01:38 +03:00
|
|
|
furi_mutex_free(app->model_mutex);
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-09-19 05:22:50 +03:00
|
|
|
if(with_subghz) {
|
|
|
|
furi_hal_subghz_sleep();
|
|
|
|
subghz_setting_free(app->setting);
|
|
|
|
subghz_receiver_free(app->subghz_receiver);
|
|
|
|
subghz_environment_free(app->environment);
|
|
|
|
}
|
2022-08-23 15:48:08 +03:00
|
|
|
|
2022-08-24 15:28:27 +03:00
|
|
|
furi_record_close(RECORD_NOTIFICATION);
|
2022-09-17 17:53:44 +03:00
|
|
|
app->notification = NULL;
|
2022-08-24 15:28:27 +03:00
|
|
|
|
2022-06-01 21:40:20 +03:00
|
|
|
free(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t unirfremix_app(void* p) {
|
|
|
|
UNUSED(p);
|
|
|
|
UniRFRemix* app = unirfremix_alloc();
|
|
|
|
|
2022-10-05 21:27:13 +03:00
|
|
|
app->file_path = furi_string_alloc();
|
2022-10-06 02:30:40 +03:00
|
|
|
app->signal = furi_string_alloc();
|
2022-08-01 23:20:04 +03:00
|
|
|
|
2022-06-01 21:40:20 +03:00
|
|
|
//setup variables before population
|
2022-10-05 21:27:13 +03:00
|
|
|
app->up_file = furi_string_alloc();
|
|
|
|
app->down_file = furi_string_alloc();
|
|
|
|
app->left_file = furi_string_alloc();
|
|
|
|
app->right_file = furi_string_alloc();
|
|
|
|
app->ok_file = furi_string_alloc();
|
|
|
|
|
2022-06-13 23:40:23 +03:00
|
|
|
app->file_result = 3;
|
|
|
|
|
2022-08-15 00:26:49 +03:00
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
2022-08-01 23:20:04 +03:00
|
|
|
if(!storage_simply_mkdir(storage, UNIRFMAP_FOLDER)) {
|
|
|
|
FURI_LOG_E(TAG, "Could not create folder %s", UNIRFMAP_FOLDER);
|
|
|
|
}
|
2022-08-15 00:26:49 +03:00
|
|
|
furi_record_close(RECORD_STORAGE);
|
2022-08-01 23:20:04 +03:00
|
|
|
|
2022-10-05 21:27:13 +03:00
|
|
|
furi_string_set(app->file_path, UNIRFMAP_FOLDER);
|
2022-08-01 23:20:04 +03:00
|
|
|
|
|
|
|
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
|
2022-09-14 21:04:04 +03:00
|
|
|
|
|
|
|
DialogsFileBrowserOptions browser_options;
|
|
|
|
dialog_file_browser_set_basic_options(&browser_options, UNIRFMAP_EXTENSION, &I_sub1_10px);
|
2022-12-08 10:10:38 +03:00
|
|
|
browser_options.base_path = UNIRFMAP_FOLDER;
|
2022-09-14 21:04:04 +03:00
|
|
|
|
|
|
|
bool res = dialog_file_browser_show(dialogs, app->file_path, app->file_path, &browser_options);
|
2022-08-01 23:20:04 +03:00
|
|
|
|
|
|
|
furi_record_close(RECORD_DIALOGS);
|
|
|
|
if(!res) {
|
|
|
|
FURI_LOG_E(TAG, "No file selected");
|
2022-09-19 05:22:50 +03:00
|
|
|
unirfremix_free(app, false);
|
|
|
|
return 255;
|
2022-08-01 23:20:04 +03:00
|
|
|
} else {
|
|
|
|
//check map and population variables
|
|
|
|
unirfremix_cfg_set_check(app, app->file_path);
|
|
|
|
}
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-08-24 23:14:33 +03:00
|
|
|
// init subghz stuff
|
|
|
|
unirfremix_subghz_alloc(app);
|
|
|
|
|
2022-06-01 21:40:20 +03:00
|
|
|
bool exit_loop = false;
|
|
|
|
|
2022-08-01 23:20:04 +03:00
|
|
|
if(app->file_result == 2) {
|
2022-08-23 21:47:54 +03:00
|
|
|
FURI_LOG_D(
|
2022-06-01 21:40:20 +03:00
|
|
|
TAG,
|
|
|
|
"U: %s - D: %s - L: %s - R: %s - O: %s ",
|
2022-10-05 21:27:13 +03:00
|
|
|
furi_string_get_cstr(app->up_file),
|
|
|
|
furi_string_get_cstr(app->down_file),
|
|
|
|
furi_string_get_cstr(app->left_file),
|
|
|
|
furi_string_get_cstr(app->right_file),
|
|
|
|
furi_string_get_cstr(app->ok_file));
|
2022-06-01 21:40:20 +03:00
|
|
|
|
|
|
|
//variables to control multiple button presses and status updates
|
|
|
|
app->send_status = "Idle";
|
|
|
|
app->send_status_c = 0;
|
|
|
|
app->processing = 0;
|
2022-08-24 23:14:33 +03:00
|
|
|
//app->repeat = 1;
|
2022-06-01 21:40:20 +03:00
|
|
|
app->button = 0;
|
|
|
|
|
2022-06-12 05:42:37 +03:00
|
|
|
//refresh screen to update variables before processing main screen or error screens
|
2022-07-20 19:01:38 +03:00
|
|
|
furi_mutex_release(app->model_mutex);
|
2022-06-12 05:42:37 +03:00
|
|
|
view_port_update(app->view_port);
|
|
|
|
|
2022-06-01 21:40:20 +03:00
|
|
|
//input detect loop start
|
|
|
|
InputEvent input;
|
|
|
|
while(1) {
|
2022-07-26 21:52:34 +03:00
|
|
|
furi_check(
|
|
|
|
furi_message_queue_get(app->input_queue, &input, FuriWaitForever) == FuriStatusOk);
|
2022-08-23 21:47:54 +03:00
|
|
|
FURI_LOG_D(
|
2022-06-01 21:40:20 +03:00
|
|
|
TAG,
|
|
|
|
"key: %s type: %s",
|
|
|
|
input_get_key_name(input.key),
|
|
|
|
input_get_type_name(input.type));
|
|
|
|
|
|
|
|
switch(input.key) {
|
|
|
|
case InputKeyUp:
|
2022-08-24 23:14:33 +03:00
|
|
|
if(input.type == InputTypePress) {
|
2022-06-01 21:40:20 +03:00
|
|
|
if(app->up_enabled) {
|
|
|
|
if(app->processing == 0) {
|
2022-10-06 02:30:40 +03:00
|
|
|
furi_string_reset(app->signal);
|
2022-10-06 15:10:08 +03:00
|
|
|
furi_string_set(app->signal, app->up_file);
|
2022-08-01 23:20:04 +03:00
|
|
|
app->button = 1;
|
2022-06-01 21:40:20 +03:00
|
|
|
app->processing = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-24 23:14:33 +03:00
|
|
|
if(input.type == InputTypeRelease) {
|
|
|
|
if(app->up_enabled) {
|
|
|
|
unirfremix_tx_stop(app);
|
|
|
|
}
|
|
|
|
}
|
2022-06-01 21:40:20 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case InputKeyDown:
|
2022-08-24 23:14:33 +03:00
|
|
|
if(input.type == InputTypePress) {
|
2022-06-01 21:40:20 +03:00
|
|
|
if(app->down_enabled) {
|
|
|
|
if(app->processing == 0) {
|
2022-10-06 02:30:40 +03:00
|
|
|
furi_string_reset(app->signal);
|
2022-10-06 15:10:08 +03:00
|
|
|
furi_string_set(app->signal, app->down_file);
|
2022-08-01 23:20:04 +03:00
|
|
|
app->button = 2;
|
2022-06-01 21:40:20 +03:00
|
|
|
app->processing = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-24 23:14:33 +03:00
|
|
|
if(input.type == InputTypeRelease) {
|
|
|
|
if(app->down_enabled) {
|
|
|
|
unirfremix_tx_stop(app);
|
|
|
|
}
|
|
|
|
}
|
2022-06-01 21:40:20 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case InputKeyRight:
|
2022-08-24 23:14:33 +03:00
|
|
|
if(input.type == InputTypePress) {
|
2022-06-01 21:40:20 +03:00
|
|
|
if(app->right_enabled) {
|
|
|
|
if(app->processing == 0) {
|
2022-10-06 02:30:40 +03:00
|
|
|
furi_string_reset(app->signal);
|
2022-10-06 15:10:08 +03:00
|
|
|
furi_string_set(app->signal, app->right_file);
|
2022-08-01 23:20:04 +03:00
|
|
|
app->button = 3;
|
2022-06-01 21:40:20 +03:00
|
|
|
app->processing = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-24 23:14:33 +03:00
|
|
|
if(input.type == InputTypeRelease) {
|
|
|
|
if(app->right_enabled) {
|
|
|
|
unirfremix_tx_stop(app);
|
|
|
|
}
|
|
|
|
}
|
2022-06-01 21:40:20 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case InputKeyLeft:
|
2022-08-24 23:14:33 +03:00
|
|
|
if(input.type == InputTypePress) {
|
2022-06-01 21:40:20 +03:00
|
|
|
if(app->left_enabled) {
|
|
|
|
if(app->processing == 0) {
|
2022-10-06 02:30:40 +03:00
|
|
|
furi_string_reset(app->signal);
|
2022-10-06 15:10:08 +03:00
|
|
|
furi_string_set(app->signal, app->left_file);
|
2022-08-01 23:20:04 +03:00
|
|
|
app->button = 4;
|
2022-06-01 21:40:20 +03:00
|
|
|
app->processing = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-24 23:14:33 +03:00
|
|
|
if(input.type == InputTypeRelease) {
|
|
|
|
if(app->left_enabled) {
|
|
|
|
unirfremix_tx_stop(app);
|
|
|
|
}
|
|
|
|
}
|
2022-06-01 21:40:20 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case InputKeyOk:
|
2022-08-24 23:14:33 +03:00
|
|
|
if(input.type == InputTypePress) {
|
2022-06-01 21:40:20 +03:00
|
|
|
if(app->ok_enabled) {
|
|
|
|
if(app->processing == 0) {
|
2022-10-06 02:30:40 +03:00
|
|
|
furi_string_reset(app->signal);
|
2022-10-06 15:10:08 +03:00
|
|
|
furi_string_set(app->signal, app->ok_file);
|
2022-06-01 21:40:20 +03:00
|
|
|
app->button = 5;
|
|
|
|
app->processing = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-24 23:14:33 +03:00
|
|
|
if(input.type == InputTypeRelease) {
|
|
|
|
if(app->ok_enabled) {
|
|
|
|
unirfremix_tx_stop(app);
|
|
|
|
}
|
|
|
|
}
|
2022-06-01 21:40:20 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case InputKeyBack:
|
2022-08-25 03:21:44 +03:00
|
|
|
unirfremix_tx_stop(app);
|
|
|
|
exit_loop = true;
|
2022-06-01 21:40:20 +03:00
|
|
|
break;
|
2022-11-02 23:07:00 +03:00
|
|
|
default:
|
|
|
|
break;
|
2022-06-01 21:40:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(app->processing == 0) {
|
2022-08-23 21:47:54 +03:00
|
|
|
FURI_LOG_D(TAG, "processing 0");
|
2022-06-01 21:40:20 +03:00
|
|
|
app->send_status = "Idle";
|
|
|
|
app->send_status_c = 0;
|
|
|
|
app->button = 0;
|
|
|
|
} else if(app->processing == 1) {
|
2022-08-23 21:47:54 +03:00
|
|
|
FURI_LOG_D(TAG, "processing 1");
|
2022-06-01 21:40:20 +03:00
|
|
|
|
2022-06-13 23:40:23 +03:00
|
|
|
app->send_status = "Send";
|
2022-06-01 21:40:20 +03:00
|
|
|
|
|
|
|
switch(app->button) {
|
|
|
|
case 1:
|
|
|
|
app->send_status_c = 1;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
app->send_status_c = 2;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
app->send_status_c = 3;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
app->send_status_c = 4;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
app->send_status_c = 5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
app->processing = 2;
|
|
|
|
|
|
|
|
unirfremix_process_signal(app, app->signal);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(exit_loop == true) {
|
2022-07-20 19:01:38 +03:00
|
|
|
furi_mutex_release(app->model_mutex);
|
2022-06-01 21:40:20 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-07-20 19:01:38 +03:00
|
|
|
furi_mutex_release(app->model_mutex);
|
2022-06-01 21:40:20 +03:00
|
|
|
view_port_update(app->view_port);
|
|
|
|
}
|
2022-10-21 09:29:07 +03:00
|
|
|
} else if(app->file_result == 1 || app->file_result == 3) {
|
2022-06-12 05:42:37 +03:00
|
|
|
//refresh screen to update variables before processing main screen or error screens
|
|
|
|
view_port_update(app->view_port);
|
|
|
|
|
2022-06-01 21:40:20 +03:00
|
|
|
InputEvent input;
|
|
|
|
while(1) {
|
2022-07-26 21:52:34 +03:00
|
|
|
furi_check(
|
|
|
|
furi_message_queue_get(app->input_queue, &input, FuriWaitForever) == FuriStatusOk);
|
2022-08-23 21:47:54 +03:00
|
|
|
FURI_LOG_D(
|
2022-06-01 21:40:20 +03:00
|
|
|
TAG,
|
|
|
|
"key: %s type: %s",
|
|
|
|
input_get_key_name(input.key),
|
|
|
|
input_get_type_name(input.type));
|
|
|
|
|
|
|
|
switch(input.key) {
|
|
|
|
case InputKeyRight:
|
|
|
|
break;
|
|
|
|
case InputKeyLeft:
|
|
|
|
break;
|
|
|
|
case InputKeyUp:
|
|
|
|
break;
|
|
|
|
case InputKeyDown:
|
|
|
|
break;
|
|
|
|
case InputKeyOk:
|
|
|
|
break;
|
|
|
|
case InputKeyBack:
|
2022-08-25 03:21:44 +03:00
|
|
|
exit_loop = true;
|
2022-06-01 21:40:20 +03:00
|
|
|
break;
|
2022-11-02 23:07:00 +03:00
|
|
|
default:
|
|
|
|
break;
|
2022-06-01 21:40:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(exit_loop == true) {
|
2022-07-20 19:01:38 +03:00
|
|
|
furi_mutex_release(app->model_mutex);
|
2022-06-01 21:40:20 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-07-20 19:01:38 +03:00
|
|
|
furi_mutex_release(app->model_mutex);
|
2022-06-01 21:40:20 +03:00
|
|
|
view_port_update(app->view_port);
|
|
|
|
}
|
2022-08-01 23:20:04 +03:00
|
|
|
} else {
|
|
|
|
furi_mutex_release(app->model_mutex);
|
2022-06-01 21:40:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove & free all stuff created by app
|
2022-09-19 05:22:50 +03:00
|
|
|
unirfremix_free(app, true);
|
2022-08-24 15:28:27 +03:00
|
|
|
|
2022-06-01 21:40:20 +03:00
|
|
|
return 0;
|
2022-08-01 23:20:04 +03:00
|
|
|
}
|