Skip to content

Commit

Permalink
Merge pull request #1 from rdefeo/new-ui
Browse files Browse the repository at this point in the history
New UI
  • Loading branch information
rdefeo authored Mar 17, 2024
2 parents 59499e5 + 09230aa commit ffbe77d
Show file tree
Hide file tree
Showing 29 changed files with 1,185 additions and 166 deletions.
2 changes: 1 addition & 1 deletion actions/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "action_i.h"

void action_tx(void* context, Item* item, FuriString* error) {
FURI_LOG_I(TAG, "action_run: %s : %s", furi_string_get_cstr(item->name), item->ext);
// FURI_LOG_I(TAG, "action_run: %s : %s", furi_string_get_cstr(item->name), item->ext);

if(!strcmp(item->ext, ".sub")) {
action_subghz_tx(context, item->path, error);
Expand Down
8 changes: 4 additions & 4 deletions actions/action_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#define ACTION_SET_ERROR(_msg_fmt, ...) furi_string_printf(error, _msg_fmt, ##__VA_ARGS__)

void action_subghz_tx(void* context, FuriString* action_path, FuriString* error);
void action_rfid_tx(void* context, FuriString* action_path, FuriString* error);
void action_ir_tx(void* context, FuriString* action_path, FuriString* error);
void action_qpl_tx(void* context, FuriString* action_path, FuriString* error);
void action_subghz_tx(void* context, const FuriString* action_path, FuriString* error);
void action_rfid_tx(void* context, const FuriString* action_path, FuriString* error);
void action_ir_tx(void* context, const FuriString* action_path, FuriString* error);
void action_qpl_tx(void* context, const FuriString* action_path, FuriString* error);
2 changes: 1 addition & 1 deletion actions/action_ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ InfraredSignal* infrared_signal_alloc() {
return signal;
}

void action_ir_tx(void* context, FuriString* action_path, FuriString* error) {
void action_ir_tx(void* context, const FuriString* action_path, FuriString* error) {
UNUSED(action_path);
UNUSED(error);
UNUSED(context);
Expand Down
26 changes: 17 additions & 9 deletions actions/action_qpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,36 @@
#include "quac.h"

/** Open the Playlist file and then transmit each action
*
* Each line of the playlist file is one of:
* <file_path>
* Full SD card path, or relative path to action to be transmitted. Must be
* one of the supported filetypes (.sub, .rfid, [.ir coming soon])
* pause <ms> - NOT IMPLEMENTED
*
* If an .rfid file has a space followed by a number, that will be the
* duration for that RFID transmission. All other .rfid files will use
* the value specified in the Settings
*
* pause <ms>
* Pauses the playback for 'ms' milliseconds.
*
* Blank lines, and comments (start with '#') are ignored. Whitespace is trimmed.
*
* Not yet Implemented:
* - For RFID files, if they have a space followed by a number after their name,
* that number will be the duration of that RFID tx
*/
void action_qpl_tx(void* context, FuriString* action_path, FuriString* error) {
void action_qpl_tx(void* context, const FuriString* action_path, FuriString* error) {
App* app = context;

// Save the current RFID Duration, in case it is changed during playback
uint32_t orig_rfid_duration = app->settings.rfid_duration;

FuriString* buffer;
buffer = furi_string_alloc();

Stream* file = file_stream_alloc(app->storage);
if(file_stream_open(file, furi_string_get_cstr(action_path), FSAM_READ, FSOM_OPEN_EXISTING)) {
while(stream_read_line(file, buffer)) {
furi_string_trim(buffer); // remove '\n\r' line endings, cleanup spaces
FURI_LOG_I(TAG, "line: %s", furi_string_get_cstr(buffer));
// FURI_LOG_I(TAG, "line: %s", furi_string_get_cstr(buffer));

// Skip blank lines
if(furi_string_size(buffer) == 0) {
Expand Down Expand Up @@ -100,7 +106,7 @@ void action_qpl_tx(void* context, FuriString* action_path, FuriString* error) {
// FURI_LOG_I(TAG, "RFID file with duration");
if(sscanf(furi_string_get_cstr(buffer), "%lu", &rfid_duration) == 1) {
FURI_LOG_I(TAG, "RFID duration = %lu", rfid_duration);
// TODO: Need to get the duration to the action_rfid_tx command...
app->settings.rfid_duration = rfid_duration;
}
}

Expand Down Expand Up @@ -128,10 +134,12 @@ void action_qpl_tx(void* context, FuriString* action_path, FuriString* error) {
path_extract_extension(buffer, ext, MAX_EXT_LEN);
if(!strcmp(ext, ".sub")) {
action_subghz_tx(context, buffer, error);
} else if(!strcmp(ext, ".ir")) {
action_ir_tx(context, buffer, error);
} else if(!strcmp(ext, ".rfid")) {
action_rfid_tx(context, buffer, error);
// Reset our default duration back - in case it was changed during playback
app->settings.rfid_duration = orig_rfid_duration;
} else if(!strcmp(ext, ".ir")) {
action_ir_tx(context, buffer, error);
} else if(!strcmp(ext, ".qpl")) {
ACTION_SET_ERROR("Playlist: Can't call playlist from playlist");
} else {
Expand Down
39 changes: 15 additions & 24 deletions actions/action_rfid.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,34 @@
#include "quac.h"

// lifted from flipperzero-firmware/applications/main/lfrfid/lfrfid_cli.c
void action_rfid_tx(void* context, FuriString* action_path, FuriString* error) {
void action_rfid_tx(void* context, const FuriString* action_path, FuriString* error) {
UNUSED(error);

App* app = context;
FuriString* file_name = action_path;
const FuriString* file_name = action_path;

FlipperFormat* fff_data_file = flipper_format_file_alloc(app->storage);
FuriString* temp_str;
temp_str = furi_string_alloc();
uint32_t temp_data32;

FuriString* protocol_name;
FuriString* data_text;
protocol_name = furi_string_alloc();
data_text = furi_string_alloc();

ProtocolDict* dict = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax);
ProtocolId protocol;
size_t data_size = protocol_dict_get_max_data_size(dict);
uint8_t* data = malloc(data_size);

FURI_LOG_I(TAG, "Max dict data size is %d", data_size);
// FURI_LOG_I(TAG, "Max dict data size is %d", data_size);
bool successful_read = false;
do {
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
ACTION_SET_ERROR("RFID: Error opening %s", furi_string_get_cstr(file_name));
break;
}
FURI_LOG_I(TAG, "Opened file");
if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
ACTION_SET_ERROR("RFID: Missing or incorrect header");
break;
}
FURI_LOG_I(TAG, "Read file headers");
// FURI_LOG_I(TAG, "Read file headers");
// TODO: add better header checks here...
if(!strcmp(furi_string_get_cstr(temp_str), "Flipper RFID key")) {
} else {
Expand All @@ -55,21 +49,21 @@ void action_rfid_tx(void* context, FuriString* action_path, FuriString* error) {
}

// read and check the protocol field
if(!flipper_format_read_string(fff_data_file, "Key type", protocol_name)) {
if(!flipper_format_read_string(fff_data_file, "Key type", temp_str)) {
ACTION_SET_ERROR("RFID: Error reading protocol");
break;
}
protocol = protocol_dict_get_protocol_by_name(dict, furi_string_get_cstr(protocol_name));
protocol = protocol_dict_get_protocol_by_name(dict, furi_string_get_cstr(temp_str));
if(protocol == PROTOCOL_NO) {
ACTION_SET_ERROR("RFID: Unknown protocol: %s", furi_string_get_cstr(protocol_name));
ACTION_SET_ERROR("RFID: Unknown protocol: %s", furi_string_get_cstr(temp_str));
break;
}

// read and check data field
size_t required_size = protocol_dict_get_data_size(dict, protocol);
FURI_LOG_I(TAG, "Protocol req data size is %d", required_size);
// FURI_LOG_I(TAG, "Protocol req data size is %d", required_size);
if(!flipper_format_read_hex(fff_data_file, "Data", data, required_size)) {
FURI_LOG_E(TAG, "Error reading data");
FURI_LOG_E(TAG, "RFID: Error reading data");
ACTION_SET_ERROR("RFID: Error reading data");
break;
}
Expand All @@ -86,7 +80,7 @@ void action_rfid_tx(void* context, FuriString* action_path, FuriString* error) {

protocol_dict_set_data(dict, protocol, data, data_size);
successful_read = true;
FURI_LOG_I(TAG, "protocol dict setup complete!");
// FURI_LOG_I(TAG, "protocol dict setup complete!");
} while(false);

if(successful_read) {
Expand All @@ -95,26 +89,23 @@ void action_rfid_tx(void* context, FuriString* action_path, FuriString* error) {
lfrfid_worker_start_thread(worker);
lfrfid_worker_emulate_start(worker, protocol);

FURI_LOG_I(TAG, "Emulating RFID...");
int16_t time_ms = 3000;
int16_t interval_ms = 200;
int16_t time_ms = app->settings.rfid_duration;
FURI_LOG_I(
TAG, "RFID: Emulating RFID (%s) for %d ms", furi_string_get_cstr(file_name), time_ms);
int16_t interval_ms = 100;
while(time_ms > 0) {
furi_delay_ms(interval_ms);
time_ms -= interval_ms;
}
FURI_LOG_I(TAG, "Emulation stopped");
FURI_LOG_I(TAG, "RFID: Emulation stopped");

lfrfid_worker_stop(worker);
lfrfid_worker_stop_thread(worker);
lfrfid_worker_free(worker);
}

furi_string_free(temp_str);
furi_string_free(protocol_name);
furi_string_free(data_text);
free(data);

protocol_dict_free(dict);

flipper_format_free(fff_data_file);
}
14 changes: 7 additions & 7 deletions actions/action_subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ static FuriHalSubGhzPreset action_subghz_get_preset_name(const char* preset_name
}

// Lifted from flipperzero-firmware/applications/main/subghz/subghz_cli.c
void action_subghz_tx(void* context, FuriString* action_path, FuriString* error) {
void action_subghz_tx(void* context, const FuriString* action_path, FuriString* error) {
App* app = context;
FuriString* file_name = action_path;
const char* file_name = furi_string_get_cstr(action_path);
uint32_t repeat = 1; //
// uint32_t device_ind = 0; // 0 - CC1101_INT, 1 - CC1101_EXT

Expand Down Expand Up @@ -76,9 +76,9 @@ void action_subghz_tx(void* context, FuriString* action_path, FuriString* error)
// device_ind = 0;
}

if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
FURI_LOG_E(TAG, "Error opening %s", furi_string_get_cstr(file_name));
ACTION_SET_ERROR("SUBGHZ: Error opening %s", furi_string_get_cstr(file_name));
if(!flipper_format_file_open_existing(fff_data_file, file_name)) {
FURI_LOG_E(TAG, "Error opening %s", file_name);
ACTION_SET_ERROR("SUBGHZ: Error opening %s", file_name);
break;
}

Expand Down Expand Up @@ -169,7 +169,7 @@ void action_subghz_tx(void* context, FuriString* action_path, FuriString* error)
if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) {
FURI_LOG_I(TAG, "Protocol = RAW");
subghz_protocol_raw_gen_fff_data(
fff_data_raw, furi_string_get_cstr(file_name), subghz_devices_get_name(device));
fff_data_raw, file_name, subghz_devices_get_name(device));
transmitter =
subghz_transmitter_alloc_init(environment, furi_string_get_cstr(temp_str));
if(transmitter == NULL) {
Expand Down Expand Up @@ -219,7 +219,7 @@ void action_subghz_tx(void* context, FuriString* action_path, FuriString* error)
FURI_LOG_I(
TAG,
"Listening at %s. Frequency=%lu, Protocol=%s",
furi_string_get_cstr(file_name),
file_name,
frequency,
furi_string_get_cstr(temp_str));
do {
Expand Down
16 changes: 0 additions & 16 deletions flipper.h

This file was deleted.

Binary file added images/ArrowDown_8x4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ArrowUp_8x4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Directory_10px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/IR_10px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/NFC_10px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Playlist_10px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/RFID_10px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Settings_10px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/SubGHz_10px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ffbe77d

Please sign in to comment.