Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rdefeo committed Mar 6, 2024
0 parents commit e4a1dd8
Show file tree
Hide file tree
Showing 21 changed files with 913 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Simple On/Off Remote
## Sub-GHz

Main Display
* Saved device 1
* Saved device 2
* Manage Devices

Saved device View
* ON
* OFF
* other


## File System Layout
Inside the data folder, create sub-folders per device. Inside each of the device folders, store the raw files that contain the sub-ghz data, etc.

The device order list, and button list, is based on the sorted file order. This is enforced by the following naming convention:

```
/data_folder
- 00_Device_1
- 01_Device_2
- 00_Button_1.sub
- 01_Button_2.sub
```

The first two digits and underscore will be stripped before display. Additionally, underscores in folder and filenames will be replaced with spaces.

18 changes: 18 additions & 0 deletions actions/action.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#include "app_state.h"
#include "item.h"
#include "action_i.h"

void action_tx(void* context, Item* item) {
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);
} else if(!strcmp(item->ext, ".ir")) {
action_ir_tx(context, item);
} else if(!strcmp(item->ext, ".rfid")) {
action_rfid_tx(context, item);
} else {
FURI_LOG_E(TAG, "Unknown item type! %s", item->ext);
}
}
5 changes: 5 additions & 0 deletions actions/action.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

struct Item;

void action_tx(void* context, Item* item);
14 changes: 14 additions & 0 deletions actions/action_i.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include "../flipper.h"
#include <furi.h>
#include <furi_hal.h>

#include <flipper_format/flipper_format.h>

#include "../app_state.h"
#include "../item.h"

void action_subghz_tx(void* context, Item* item);
void action_rfid_tx(void* context, Item* item);
void action_ir_tx(void* context, Item* item);
8 changes: 8 additions & 0 deletions actions/action_ir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Methods for IR transmission

#include "action_i.h"

void action_ir_tx(void* context, Item* item) {
UNUSED(context);
UNUSED(item);
}
115 changes: 115 additions & 0 deletions actions/action_rfid.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Methods for RFID transmission

// lfrid
#include <lib/lfrfid/lfrfid_worker.h>
#include <toolbox/protocols/protocol_dict.h>
#include <lfrfid/protocols/lfrfid_protocols.h>
#include <lfrfid/lfrfid_raw_file.h>
#include <lib/toolbox/args.h>

#include "action_i.h"

// lifted from flipperzero-firmware/applications/main/lfrfid/lfrfid_cli.c
void action_rfid_tx(void* context, Item* item) {
App* app = context;
FuriString* file_name = item->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);
bool successful_read = false;
do {
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));
break;
}
FURI_LOG_I(TAG, "Opened file");
if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
FURI_LOG_E(TAG, "Missing or incorrect header");
break;
}
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 {
FURI_LOG_E(TAG, "Type or version mismatch");
break;
}

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

// 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);
if(!flipper_format_read_hex(fff_data_file, "Data", data, required_size)) {
FURI_LOG_E(TAG, "Error reading data");
break;
}
// FURI_LOG_I(TAG, "Data: %s", furi_string_get_cstr(data_text));

// if(data_size != required_size) {
// FURI_LOG_E(
// TAG,
// "%s data needs to be %zu bytes long",
// protocol_dict_get_name(dict, protocol),
// required_size);
// break;
// }

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

if(successful_read) {
LFRFIDWorker* worker = lfrfid_worker_alloc(dict);

lfrfid_worker_start_thread(worker);
lfrfid_worker_emulate_start(worker, protocol);

printf("Emulating RFID...\r\nPress Ctrl+C to abort\r\n");
int16_t time_ms = 3000;
int16_t interval_ms = 200;
while(time_ms > 0) {
furi_delay_ms(interval_ms);
time_ms -= interval_ms;
}
printf("Emulation stopped\r\n");

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);
}
Loading

0 comments on commit e4a1dd8

Please sign in to comment.