[FL-2627] Flipper applications: SDK, build and debug system (#1387)
* Added support for running applications from SD card (FAPs - Flipper Application Packages) * Added plugin_dist target for fbt to build FAPs * All apps of type FlipperAppType.EXTERNAL and FlipperAppType.PLUGIN are built as FAPs by default * Updated VSCode configuration for new fbt features - re-deploy stock configuration to use them * Added debugging support for FAPs with fbt debug & VSCode * Added public firmware API with automated versioning Co-authored-by: hedger <hedger@users.noreply.github.com> Co-authored-by: SG <who.just.the.doctor@gmail.com> Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
committed by
Aleksandr Kutuzov
co-authored by
hedger
あく
parent
0f6f9ad52e
commit
b9a766d909
@@ -0,0 +1,24 @@
|
||||
App(
|
||||
appid="subghz",
|
||||
name="Sub-GHz",
|
||||
apptype=FlipperAppType.APP,
|
||||
entry_point="subghz_app",
|
||||
cdefines=["APP_SUBGHZ"],
|
||||
requires=[
|
||||
"gui",
|
||||
"cli",
|
||||
"dialogs",
|
||||
],
|
||||
provides=["subghz_start"],
|
||||
icon="A_Sub1ghz_14",
|
||||
stack_size=2 * 1024,
|
||||
order=10,
|
||||
)
|
||||
|
||||
App(
|
||||
appid="subghz_start",
|
||||
apptype=FlipperAppType.STARTUP,
|
||||
entry_point="subghz_on_system_start",
|
||||
requires=["subghz"],
|
||||
order=40,
|
||||
)
|
||||
@@ -0,0 +1,148 @@
|
||||
#include "subghz_chat.h"
|
||||
#include <lib/subghz/subghz_tx_rx_worker.h>
|
||||
|
||||
#define TAG "SubGhzChat"
|
||||
#define SUBGHZ_CHAT_WORKER_TIMEOUT_BETWEEN_MESSAGES 500
|
||||
|
||||
struct SubGhzChatWorker {
|
||||
FuriThread* thread;
|
||||
SubGhzTxRxWorker* subghz_txrx;
|
||||
|
||||
volatile bool worker_running;
|
||||
volatile bool worker_stoping;
|
||||
FuriMessageQueue* event_queue;
|
||||
uint32_t last_time_rx_data;
|
||||
|
||||
Cli* cli;
|
||||
};
|
||||
|
||||
/** Worker thread
|
||||
*
|
||||
* @param context
|
||||
* @return exit code
|
||||
*/
|
||||
static int32_t subghz_chat_worker_thread(void* context) {
|
||||
SubGhzChatWorker* instance = context;
|
||||
FURI_LOG_I(TAG, "Worker start");
|
||||
char c;
|
||||
SubGhzChatEvent event;
|
||||
event.event = SubGhzChatEventUserEntrance;
|
||||
furi_message_queue_put(instance->event_queue, &event, 0);
|
||||
while(instance->worker_running) {
|
||||
if(cli_read_timeout(instance->cli, (uint8_t*)&c, 1, 1000) == 1) {
|
||||
event.event = SubGhzChatEventInputData;
|
||||
event.c = c;
|
||||
furi_message_queue_put(instance->event_queue, &event, FuriWaitForever);
|
||||
}
|
||||
}
|
||||
|
||||
FURI_LOG_I(TAG, "Worker stop");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void subghz_chat_worker_update_rx_event_chat(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzChatWorker* instance = context;
|
||||
SubGhzChatEvent event;
|
||||
if((furi_get_tick() - instance->last_time_rx_data) >
|
||||
SUBGHZ_CHAT_WORKER_TIMEOUT_BETWEEN_MESSAGES) {
|
||||
event.event = SubGhzChatEventNewMessage;
|
||||
furi_message_queue_put(instance->event_queue, &event, FuriWaitForever);
|
||||
}
|
||||
instance->last_time_rx_data = furi_get_tick();
|
||||
event.event = SubGhzChatEventRXData;
|
||||
furi_message_queue_put(instance->event_queue, &event, FuriWaitForever);
|
||||
}
|
||||
|
||||
SubGhzChatWorker* subghz_chat_worker_alloc(Cli* cli) {
|
||||
SubGhzChatWorker* instance = malloc(sizeof(SubGhzChatWorker));
|
||||
|
||||
instance->cli = cli;
|
||||
|
||||
instance->thread = furi_thread_alloc();
|
||||
furi_thread_set_name(instance->thread, "SubGhzChat");
|
||||
furi_thread_set_stack_size(instance->thread, 2048);
|
||||
furi_thread_set_context(instance->thread, instance);
|
||||
furi_thread_set_callback(instance->thread, subghz_chat_worker_thread);
|
||||
instance->subghz_txrx = subghz_tx_rx_worker_alloc();
|
||||
instance->event_queue = furi_message_queue_alloc(80, sizeof(SubGhzChatEvent));
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_chat_worker_free(SubGhzChatWorker* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(!instance->worker_running);
|
||||
furi_message_queue_free(instance->event_queue);
|
||||
subghz_tx_rx_worker_free(instance->subghz_txrx);
|
||||
furi_thread_free(instance->thread);
|
||||
|
||||
free(instance);
|
||||
}
|
||||
|
||||
bool subghz_chat_worker_start(SubGhzChatWorker* instance, uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
furi_assert(!instance->worker_running);
|
||||
bool res = false;
|
||||
|
||||
if(subghz_tx_rx_worker_start(instance->subghz_txrx, frequency)) {
|
||||
furi_message_queue_reset(instance->event_queue);
|
||||
subghz_tx_rx_worker_set_callback_have_read(
|
||||
instance->subghz_txrx, subghz_chat_worker_update_rx_event_chat, instance);
|
||||
|
||||
instance->worker_running = true;
|
||||
instance->last_time_rx_data = 0;
|
||||
|
||||
furi_thread_start(instance->thread);
|
||||
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void subghz_chat_worker_stop(SubGhzChatWorker* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(instance->worker_running);
|
||||
if(subghz_tx_rx_worker_is_running(instance->subghz_txrx)) {
|
||||
subghz_tx_rx_worker_stop(instance->subghz_txrx);
|
||||
}
|
||||
|
||||
instance->worker_running = false;
|
||||
|
||||
furi_thread_join(instance->thread);
|
||||
}
|
||||
|
||||
bool subghz_chat_worker_is_running(SubGhzChatWorker* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->worker_running;
|
||||
}
|
||||
|
||||
SubGhzChatEvent subghz_chat_worker_get_event_chat(SubGhzChatWorker* instance) {
|
||||
furi_assert(instance);
|
||||
SubGhzChatEvent event;
|
||||
if(furi_message_queue_get(instance->event_queue, &event, FuriWaitForever) == FuriStatusOk) {
|
||||
return event;
|
||||
} else {
|
||||
event.event = SubGhzChatEventNoEvent;
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_chat_worker_put_event_chat(SubGhzChatWorker* instance, SubGhzChatEvent* event) {
|
||||
furi_assert(instance);
|
||||
furi_message_queue_put(instance->event_queue, event, FuriWaitForever);
|
||||
}
|
||||
|
||||
size_t subghz_chat_worker_available(SubGhzChatWorker* instance) {
|
||||
furi_assert(instance);
|
||||
return subghz_tx_rx_worker_available(instance->subghz_txrx);
|
||||
}
|
||||
|
||||
size_t subghz_chat_worker_read(SubGhzChatWorker* instance, uint8_t* data, size_t size) {
|
||||
furi_assert(instance);
|
||||
return subghz_tx_rx_worker_read(instance->subghz_txrx, data, size);
|
||||
}
|
||||
|
||||
bool subghz_chat_worker_write(SubGhzChatWorker* instance, uint8_t* data, size_t size) {
|
||||
furi_assert(instance);
|
||||
return subghz_tx_rx_worker_write(instance->subghz_txrx, data, size);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include "../subghz_i.h"
|
||||
#include <cli/cli.h>
|
||||
|
||||
typedef struct SubGhzChatWorker SubGhzChatWorker;
|
||||
|
||||
typedef enum {
|
||||
SubGhzChatEventNoEvent,
|
||||
SubGhzChatEventUserEntrance,
|
||||
SubGhzChatEventUserExit,
|
||||
SubGhzChatEventInputData,
|
||||
SubGhzChatEventRXData,
|
||||
SubGhzChatEventNewMessage,
|
||||
} SubGhzChatEventType;
|
||||
|
||||
typedef struct {
|
||||
SubGhzChatEventType event;
|
||||
char c;
|
||||
} SubGhzChatEvent;
|
||||
|
||||
SubGhzChatWorker* subghz_chat_worker_alloc(Cli* cli);
|
||||
void subghz_chat_worker_free(SubGhzChatWorker* instance);
|
||||
bool subghz_chat_worker_start(SubGhzChatWorker* instance, uint32_t frequency);
|
||||
void subghz_chat_worker_stop(SubGhzChatWorker* instance);
|
||||
bool subghz_chat_worker_is_running(SubGhzChatWorker* instance);
|
||||
SubGhzChatEvent subghz_chat_worker_get_event_chat(SubGhzChatWorker* instance);
|
||||
void subghz_chat_worker_put_event_chat(SubGhzChatWorker* instance, SubGhzChatEvent* event);
|
||||
size_t subghz_chat_worker_available(SubGhzChatWorker* instance);
|
||||
size_t subghz_chat_worker_read(SubGhzChatWorker* instance, uint8_t* data, size_t size);
|
||||
bool subghz_chat_worker_write(SubGhzChatWorker* instance, uint8_t* data, size_t size);
|
||||
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum {
|
||||
SubGhzCustomEventManagerNoSet = 0,
|
||||
SubGhzCustomEventManagerSet,
|
||||
SubGhzCustomEventManagerSetRAW,
|
||||
|
||||
//SubmenuIndex
|
||||
SubmenuIndexPricenton,
|
||||
SubmenuIndexNiceFlo12bit,
|
||||
SubmenuIndexNiceFlo24bit,
|
||||
SubmenuIndexCAME12bit,
|
||||
SubmenuIndexCAME24bit,
|
||||
SubmenuIndexCAMETwee,
|
||||
SubmenuIndexNeroSketch,
|
||||
SubmenuIndexNeroRadio,
|
||||
SubmenuIndexGateTX,
|
||||
SubmenuIndexDoorHan_315_00,
|
||||
SubmenuIndexDoorHan_433_92,
|
||||
SubmenuIndexLinear_300_00,
|
||||
SubmenuIndexLiftMaster_315_00,
|
||||
SubmenuIndexLiftMaster_390_00,
|
||||
SubmenuIndexSecPlus_v2_310_00,
|
||||
SubmenuIndexSecPlus_v2_315_00,
|
||||
SubmenuIndexSecPlus_v2_390_00,
|
||||
|
||||
//SubGhzCustomEvent
|
||||
SubGhzCustomEventSceneDeleteSuccess = 100,
|
||||
SubGhzCustomEventSceneDelete,
|
||||
SubGhzCustomEventSceneDeleteRAW,
|
||||
SubGhzCustomEventSceneDeleteRAWBack,
|
||||
|
||||
SubGhzCustomEventSceneReceiverInfoTxStart,
|
||||
SubGhzCustomEventSceneReceiverInfoTxStop,
|
||||
SubGhzCustomEventSceneReceiverInfoSave,
|
||||
SubGhzCustomEventSceneSaveName,
|
||||
SubGhzCustomEventSceneSaveSuccess,
|
||||
SubGhzCustomEventSceneShowErrorBack,
|
||||
SubGhzCustomEventSceneShowErrorOk,
|
||||
SubGhzCustomEventSceneShowErrorSub,
|
||||
SubGhzCustomEventSceneShowOnlyRX,
|
||||
SubGhzCustomEventSceneAnalyzerLock,
|
||||
SubGhzCustomEventSceneAnalyzerUnlock,
|
||||
SubGhzCustomEventSceneSettingLock,
|
||||
|
||||
SubGhzCustomEventSceneExit,
|
||||
SubGhzCustomEventSceneStay,
|
||||
|
||||
SubGhzCustomEventSceneRpcLoad,
|
||||
SubGhzCustomEventSceneRpcButtonPress,
|
||||
SubGhzCustomEventSceneRpcButtonRelease,
|
||||
SubGhzCustomEventSceneRpcSessionClose,
|
||||
|
||||
SubGhzCustomEventViewReceiverOK,
|
||||
SubGhzCustomEventViewReceiverConfig,
|
||||
SubGhzCustomEventViewReceiverBack,
|
||||
SubGhzCustomEventViewReceiverOffDisplay,
|
||||
SubGhzCustomEventViewReceiverUnlock,
|
||||
|
||||
SubGhzCustomEventViewReadRAWBack,
|
||||
SubGhzCustomEventViewReadRAWIDLE,
|
||||
SubGhzCustomEventViewReadRAWREC,
|
||||
SubGhzCustomEventViewReadRAWConfig,
|
||||
SubGhzCustomEventViewReadRAWErase,
|
||||
SubGhzCustomEventViewReadRAWSendStart,
|
||||
SubGhzCustomEventViewReadRAWSendStop,
|
||||
SubGhzCustomEventViewReadRAWSave,
|
||||
SubGhzCustomEventViewReadRAWTXRXStop,
|
||||
SubGhzCustomEventViewReadRAWMore,
|
||||
|
||||
SubGhzCustomEventViewTransmitterBack,
|
||||
SubGhzCustomEventViewTransmitterSendStart,
|
||||
SubGhzCustomEventViewTransmitterSendStop,
|
||||
SubGhzCustomEventViewTransmitterError,
|
||||
} SubGhzCustomEvent;
|
||||
@@ -0,0 +1,299 @@
|
||||
#include "subghz_frequency_analyzer_worker.h"
|
||||
#include <lib/drivers/cc1101.h>
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#define TAG "SubghzFrequencyAnalyzerWorker"
|
||||
|
||||
#define SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD -95.0f
|
||||
|
||||
static const uint8_t subghz_preset_ook_58khz[][2] = {
|
||||
{CC1101_MDMCFG4, 0b11110111}, // Rx BW filter is 58.035714kHz
|
||||
/* End */
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
static const uint8_t subghz_preset_ook_650khz[][2] = {
|
||||
{CC1101_MDMCFG4, 0b00010111}, // Rx BW filter is 650.000kHz
|
||||
/* End */
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
struct SubGhzFrequencyAnalyzerWorker {
|
||||
FuriThread* thread;
|
||||
|
||||
volatile bool worker_running;
|
||||
uint8_t sample_hold_counter;
|
||||
FrequencyRSSI frequency_rssi_buf;
|
||||
SubGhzSetting* setting;
|
||||
|
||||
float filVal;
|
||||
|
||||
SubGhzFrequencyAnalyzerWorkerPairCallback pair_callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
static void subghz_frequency_analyzer_worker_load_registers(const uint8_t data[][2]) {
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
size_t i = 0;
|
||||
while(data[i][0]) {
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, data[i][0], data[i][1]);
|
||||
i++;
|
||||
}
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
}
|
||||
|
||||
// running average with adaptive coefficient
|
||||
static uint32_t subghz_frequency_analyzer_worker_expRunningAverageAdaptive(
|
||||
SubGhzFrequencyAnalyzerWorker* instance,
|
||||
uint32_t newVal) {
|
||||
float k;
|
||||
float newValFloat = newVal;
|
||||
// the sharpness of the filter depends on the absolute value of the difference
|
||||
if(fabs(newValFloat - instance->filVal) > 500000)
|
||||
k = 0.9;
|
||||
else
|
||||
k = 0.03;
|
||||
|
||||
instance->filVal += (newValFloat - instance->filVal) * k;
|
||||
return (uint32_t)instance->filVal;
|
||||
}
|
||||
|
||||
/** Worker thread
|
||||
*
|
||||
* @param context
|
||||
* @return exit code
|
||||
*/
|
||||
static int32_t subghz_frequency_analyzer_worker_thread(void* context) {
|
||||
SubGhzFrequencyAnalyzerWorker* instance = context;
|
||||
|
||||
FrequencyRSSI frequency_rssi = {
|
||||
.frequency_coarse = 0, .rssi_coarse = 0, .frequency_fine = 0, .rssi_fine = 0};
|
||||
float rssi = 0;
|
||||
uint32_t frequency = 0;
|
||||
CC1101Status status;
|
||||
|
||||
//Start CC1101
|
||||
furi_hal_subghz_reset();
|
||||
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_flush_rx(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_flush_tx(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG0, CC1101IocfgHW);
|
||||
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_MDMCFG3,
|
||||
0b01111111); // symbol rate
|
||||
cc1101_write_reg(
|
||||
&furi_hal_spi_bus_handle_subghz,
|
||||
CC1101_AGCCTRL2,
|
||||
0b00000111); // 00 - DVGA all; 000 - MAX LNA+LNA2; 111 - MAGN_TARGET 42 dB
|
||||
cc1101_write_reg(
|
||||
&furi_hal_spi_bus_handle_subghz,
|
||||
CC1101_AGCCTRL1,
|
||||
0b00001000); // 0; 0 - LNA 2 gain is decreased to minimum before decreasing LNA gain; 00 - Relative carrier sense threshold disabled; 1000 - Absolute carrier sense threshold disabled
|
||||
cc1101_write_reg(
|
||||
&furi_hal_spi_bus_handle_subghz,
|
||||
CC1101_AGCCTRL0,
|
||||
0b00110000); // 00 - No hysteresis, medium asymmetric dead zone, medium gain ; 11 - 64 samples agc; 00 - Normal AGC, 00 - 4dB boundary
|
||||
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
|
||||
furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate);
|
||||
|
||||
while(instance->worker_running) {
|
||||
furi_delay_ms(10);
|
||||
|
||||
float rssi_min = 26.0f;
|
||||
float rssi_avg = 0;
|
||||
size_t rssi_avg_samples = 0;
|
||||
|
||||
frequency_rssi.rssi_coarse = -127.0f;
|
||||
frequency_rssi.rssi_fine = -127.0f;
|
||||
furi_hal_subghz_idle();
|
||||
subghz_frequency_analyzer_worker_load_registers(subghz_preset_ook_650khz);
|
||||
|
||||
// First stage: coarse scan
|
||||
for(size_t i = 0; i < subghz_setting_get_frequency_count(instance->setting); i++) {
|
||||
if(furi_hal_subghz_is_frequency_valid(
|
||||
subghz_setting_get_frequency(instance->setting, i))) {
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_switch_to_idle(&furi_hal_spi_bus_handle_subghz);
|
||||
frequency = cc1101_set_frequency(
|
||||
&furi_hal_spi_bus_handle_subghz,
|
||||
subghz_setting_get_frequency(instance->setting, i));
|
||||
|
||||
cc1101_calibrate(&furi_hal_spi_bus_handle_subghz);
|
||||
do {
|
||||
status = cc1101_get_status(&furi_hal_spi_bus_handle_subghz);
|
||||
} while(status.STATE != CC1101StateIDLE);
|
||||
|
||||
cc1101_switch_to_rx(&furi_hal_spi_bus_handle_subghz);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
|
||||
furi_delay_ms(2);
|
||||
|
||||
rssi = furi_hal_subghz_get_rssi();
|
||||
|
||||
rssi_avg += rssi;
|
||||
rssi_avg_samples++;
|
||||
|
||||
if(rssi < rssi_min) rssi_min = rssi;
|
||||
|
||||
if(frequency_rssi.rssi_coarse < rssi) {
|
||||
frequency_rssi.rssi_coarse = rssi;
|
||||
frequency_rssi.frequency_coarse = frequency;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FURI_LOG_T(
|
||||
TAG,
|
||||
"RSSI: avg %f, max %f at %u, min %f",
|
||||
(double)(rssi_avg / rssi_avg_samples),
|
||||
(double)frequency_rssi.rssi_coarse,
|
||||
frequency_rssi.frequency_coarse,
|
||||
(double)rssi_min);
|
||||
|
||||
// Second stage: fine scan
|
||||
if(frequency_rssi.rssi_coarse > SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD) {
|
||||
furi_hal_subghz_idle();
|
||||
subghz_frequency_analyzer_worker_load_registers(subghz_preset_ook_58khz);
|
||||
//for example -0.3 ... 433.92 ... +0.3 step 20KHz
|
||||
for(uint32_t i = frequency_rssi.frequency_coarse - 300000;
|
||||
i < frequency_rssi.frequency_coarse + 300000;
|
||||
i += 20000) {
|
||||
if(furi_hal_subghz_is_frequency_valid(i)) {
|
||||
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
|
||||
cc1101_switch_to_idle(&furi_hal_spi_bus_handle_subghz);
|
||||
frequency = cc1101_set_frequency(&furi_hal_spi_bus_handle_subghz, i);
|
||||
|
||||
cc1101_calibrate(&furi_hal_spi_bus_handle_subghz);
|
||||
do {
|
||||
status = cc1101_get_status(&furi_hal_spi_bus_handle_subghz);
|
||||
} while(status.STATE != CC1101StateIDLE);
|
||||
|
||||
cc1101_switch_to_rx(&furi_hal_spi_bus_handle_subghz);
|
||||
furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz);
|
||||
|
||||
furi_delay_ms(2);
|
||||
|
||||
rssi = furi_hal_subghz_get_rssi();
|
||||
|
||||
FURI_LOG_T(TAG, "#:%u:%f", frequency, (double)rssi);
|
||||
|
||||
if(frequency_rssi.rssi_fine < rssi) {
|
||||
frequency_rssi.rssi_fine = rssi;
|
||||
frequency_rssi.frequency_fine = frequency;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Deliver results fine
|
||||
if(frequency_rssi.rssi_fine > SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD) {
|
||||
FURI_LOG_D(
|
||||
TAG, "=:%u:%f", frequency_rssi.frequency_fine, (double)frequency_rssi.rssi_fine);
|
||||
|
||||
instance->sample_hold_counter = 20;
|
||||
if(instance->filVal) {
|
||||
frequency_rssi.frequency_fine =
|
||||
subghz_frequency_analyzer_worker_expRunningAverageAdaptive(
|
||||
instance, frequency_rssi.frequency_fine);
|
||||
}
|
||||
// Deliver callback
|
||||
if(instance->pair_callback) {
|
||||
instance->pair_callback(
|
||||
instance->context, frequency_rssi.frequency_fine, frequency_rssi.rssi_fine);
|
||||
}
|
||||
} else if( // Deliver results coarse
|
||||
(frequency_rssi.rssi_coarse > SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD) &&
|
||||
(instance->sample_hold_counter < 10)) {
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
"~:%u:%f",
|
||||
frequency_rssi.frequency_coarse,
|
||||
(double)frequency_rssi.rssi_coarse);
|
||||
|
||||
instance->sample_hold_counter = 20;
|
||||
if(instance->filVal) {
|
||||
frequency_rssi.frequency_coarse =
|
||||
subghz_frequency_analyzer_worker_expRunningAverageAdaptive(
|
||||
instance, frequency_rssi.frequency_coarse);
|
||||
}
|
||||
// Deliver callback
|
||||
if(instance->pair_callback) {
|
||||
instance->pair_callback(
|
||||
instance->context,
|
||||
frequency_rssi.frequency_coarse,
|
||||
frequency_rssi.rssi_coarse);
|
||||
}
|
||||
} else {
|
||||
if(instance->sample_hold_counter > 0) {
|
||||
instance->sample_hold_counter--;
|
||||
} else {
|
||||
instance->filVal = 0;
|
||||
if(instance->pair_callback) instance->pair_callback(instance->context, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Stop CC1101
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_sleep();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SubGhzFrequencyAnalyzerWorker* subghz_frequency_analyzer_worker_alloc(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzFrequencyAnalyzerWorker* instance = malloc(sizeof(SubGhzFrequencyAnalyzerWorker));
|
||||
|
||||
instance->thread = furi_thread_alloc();
|
||||
furi_thread_set_name(instance->thread, "SubGhzFAWorker");
|
||||
furi_thread_set_stack_size(instance->thread, 2048);
|
||||
furi_thread_set_context(instance->thread, instance);
|
||||
furi_thread_set_callback(instance->thread, subghz_frequency_analyzer_worker_thread);
|
||||
|
||||
SubGhz* subghz = context;
|
||||
instance->setting = subghz->setting;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_worker_free(SubGhzFrequencyAnalyzerWorker* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
furi_thread_free(instance->thread);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_worker_set_pair_callback(
|
||||
SubGhzFrequencyAnalyzerWorker* instance,
|
||||
SubGhzFrequencyAnalyzerWorkerPairCallback callback,
|
||||
void* context) {
|
||||
furi_assert(instance);
|
||||
furi_assert(context);
|
||||
instance->pair_callback = callback;
|
||||
instance->context = context;
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_worker_start(SubGhzFrequencyAnalyzerWorker* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(!instance->worker_running);
|
||||
|
||||
instance->worker_running = true;
|
||||
|
||||
furi_thread_start(instance->thread);
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_worker_stop(SubGhzFrequencyAnalyzerWorker* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(instance->worker_running);
|
||||
|
||||
instance->worker_running = false;
|
||||
|
||||
furi_thread_join(instance->thread);
|
||||
}
|
||||
|
||||
bool subghz_frequency_analyzer_worker_is_running(SubGhzFrequencyAnalyzerWorker* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->worker_running;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <furi_hal.h>
|
||||
#include "../subghz_i.h"
|
||||
|
||||
typedef struct SubGhzFrequencyAnalyzerWorker SubGhzFrequencyAnalyzerWorker;
|
||||
|
||||
typedef void (
|
||||
*SubGhzFrequencyAnalyzerWorkerPairCallback)(void* context, uint32_t frequency, float rssi);
|
||||
|
||||
typedef struct {
|
||||
uint32_t frequency_coarse;
|
||||
float rssi_coarse;
|
||||
uint32_t frequency_fine;
|
||||
float rssi_fine;
|
||||
} FrequencyRSSI;
|
||||
|
||||
/** Allocate SubGhzFrequencyAnalyzerWorker
|
||||
*
|
||||
* @param context SubGhz* context
|
||||
* @return SubGhzFrequencyAnalyzerWorker*
|
||||
*/
|
||||
SubGhzFrequencyAnalyzerWorker* subghz_frequency_analyzer_worker_alloc(void* context);
|
||||
|
||||
/** Free SubGhzFrequencyAnalyzerWorker
|
||||
*
|
||||
* @param instance SubGhzFrequencyAnalyzerWorker instance
|
||||
*/
|
||||
void subghz_frequency_analyzer_worker_free(SubGhzFrequencyAnalyzerWorker* instance);
|
||||
|
||||
/** Pair callback SubGhzFrequencyAnalyzerWorker
|
||||
*
|
||||
* @param instance SubGhzFrequencyAnalyzerWorker instance
|
||||
* @param callback SubGhzFrequencyAnalyzerWorkerOverrunCallback callback
|
||||
* @param context
|
||||
*/
|
||||
void subghz_frequency_analyzer_worker_set_pair_callback(
|
||||
SubGhzFrequencyAnalyzerWorker* instance,
|
||||
SubGhzFrequencyAnalyzerWorkerPairCallback callback,
|
||||
void* context);
|
||||
|
||||
/** Start SubGhzFrequencyAnalyzerWorker
|
||||
*
|
||||
* @param instance SubGhzFrequencyAnalyzerWorker instance
|
||||
*/
|
||||
void subghz_frequency_analyzer_worker_start(SubGhzFrequencyAnalyzerWorker* instance);
|
||||
|
||||
/** Stop SubGhzFrequencyAnalyzerWorker
|
||||
*
|
||||
* @param instance SubGhzFrequencyAnalyzerWorker instance
|
||||
*/
|
||||
void subghz_frequency_analyzer_worker_stop(SubGhzFrequencyAnalyzerWorker* instance);
|
||||
|
||||
/** Check if worker is running
|
||||
* @param instance SubGhzFrequencyAnalyzerWorker instance
|
||||
* @return bool - true if running
|
||||
*/
|
||||
bool subghz_frequency_analyzer_worker_is_running(SubGhzFrequencyAnalyzerWorker* instance);
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "subghz_testing.h"
|
||||
|
||||
const uint32_t subghz_frequencies_testing[] = {
|
||||
/* 300 - 348 */
|
||||
300000000,
|
||||
304500000,
|
||||
310000000,
|
||||
312025000,
|
||||
313250000,
|
||||
313625000,
|
||||
315000000,
|
||||
315225000,
|
||||
321950000,
|
||||
348000000,
|
||||
/* 387 - 464 */
|
||||
387000000,
|
||||
433075000, /* LPD433 first */
|
||||
433825000,
|
||||
433920000, /* LPD433 mid */
|
||||
434420000,
|
||||
434775000, /* LPD433 last channels */
|
||||
438900000,
|
||||
464000000,
|
||||
/* 779 - 928 */
|
||||
779000000,
|
||||
868150000,
|
||||
868350000,
|
||||
868550000,
|
||||
915000000,
|
||||
925000000,
|
||||
926500000,
|
||||
927950000,
|
||||
928000000,
|
||||
};
|
||||
|
||||
const uint32_t subghz_frequencies_count_testing =
|
||||
sizeof(subghz_frequencies_testing) / sizeof(uint32_t);
|
||||
const uint32_t subghz_frequencies_433_92_testing = 13;
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include "../subghz_i.h"
|
||||
|
||||
extern const uint32_t subghz_frequencies_testing[];
|
||||
extern const uint32_t subghz_frequencies_count_testing;
|
||||
extern const uint32_t subghz_frequencies_433_92_testing;
|
||||
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include "m-string.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
/** SubGhzNotification state */
|
||||
typedef enum {
|
||||
SubGhzNotificationStateStarting,
|
||||
SubGhzNotificationStateIDLE,
|
||||
SubGhzNotificationStateTx,
|
||||
SubGhzNotificationStateRx,
|
||||
SubGhzNotificationStateRxDone,
|
||||
} SubGhzNotificationState;
|
||||
|
||||
/** SubGhzTxRx state */
|
||||
typedef enum {
|
||||
SubGhzTxRxStateIDLE,
|
||||
SubGhzTxRxStateRx,
|
||||
SubGhzTxRxStateTx,
|
||||
SubGhzTxRxStateSleep,
|
||||
} SubGhzTxRxState;
|
||||
|
||||
/** SubGhzHopperState state */
|
||||
typedef enum {
|
||||
SubGhzHopperStateOFF,
|
||||
SubGhzHopperStateRunnig,
|
||||
SubGhzHopperStatePause,
|
||||
SubGhzHopperStateRSSITimeOut,
|
||||
} SubGhzHopperState;
|
||||
|
||||
/** SubGhzRxKeyState state */
|
||||
typedef enum {
|
||||
SubGhzRxKeyStateIDLE,
|
||||
SubGhzRxKeyStateNoSave,
|
||||
SubGhzRxKeyStateNeedSave,
|
||||
SubGhzRxKeyStateBack,
|
||||
SubGhzRxKeyStateStart,
|
||||
SubGhzRxKeyStateAddKey,
|
||||
SubGhzRxKeyStateExit,
|
||||
SubGhzRxKeyStateRAWLoad,
|
||||
SubGhzRxKeyStateRAWSave,
|
||||
} SubGhzRxKeyState;
|
||||
|
||||
/** SubGhzLoadKeyState state */
|
||||
typedef enum {
|
||||
SubGhzLoadKeyStateUnknown,
|
||||
SubGhzLoadKeyStateOK,
|
||||
SubGhzLoadKeyStateParseErr,
|
||||
SubGhzLoadKeyStateOnlyRx,
|
||||
} SubGhzLoadKeyState;
|
||||
|
||||
/** SubGhzLock */
|
||||
typedef enum {
|
||||
SubGhzLockOff,
|
||||
SubGhzLockOn,
|
||||
} SubGhzLock;
|
||||
|
||||
typedef enum {
|
||||
SubGhzViewIdMenu,
|
||||
SubGhzViewIdReceiver,
|
||||
SubGhzViewIdPopup,
|
||||
SubGhzViewIdTextInput,
|
||||
SubGhzViewIdWidget,
|
||||
SubGhzViewIdTransmitter,
|
||||
SubGhzViewIdVariableItemList,
|
||||
SubGhzViewIdFrequencyAnalyzer,
|
||||
SubGhzViewIdReadRAW,
|
||||
|
||||
SubGhzViewIdStatic,
|
||||
SubGhzViewIdTestCarrier,
|
||||
SubGhzViewIdTestPacket,
|
||||
} SubGhzViewId;
|
||||
|
||||
struct SubGhzPresetDefinition {
|
||||
string_t name;
|
||||
uint32_t frequency;
|
||||
uint8_t* data;
|
||||
size_t data_size;
|
||||
};
|
||||
|
||||
typedef struct SubGhzPresetDefinition SubGhzPresetDefinition;
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "subghz_scene.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const subghz_on_enter_handlers[])(void*) = {
|
||||
#include "subghz_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||
bool (*const subghz_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "subghz_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||
void (*const subghz_on_exit_handlers[])(void* context) = {
|
||||
#include "subghz_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers subghz_scene_handlers = {
|
||||
.on_enter_handlers = subghz_on_enter_handlers,
|
||||
.on_event_handlers = subghz_on_event_handlers,
|
||||
.on_exit_handlers = subghz_on_exit_handlers,
|
||||
.scene_num = SubGhzSceneNum,
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) SubGhzScene##id,
|
||||
typedef enum {
|
||||
#include "subghz_scene_config.h"
|
||||
SubGhzSceneNum,
|
||||
} SubGhzScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers subghz_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "subghz_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) \
|
||||
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
|
||||
#include "subghz_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
|
||||
#include "subghz_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
@@ -0,0 +1,25 @@
|
||||
ADD_SCENE(subghz, start, Start)
|
||||
ADD_SCENE(subghz, receiver, Receiver)
|
||||
ADD_SCENE(subghz, receiver_config, ReceiverConfig)
|
||||
ADD_SCENE(subghz, receiver_info, ReceiverInfo)
|
||||
ADD_SCENE(subghz, save_name, SaveName)
|
||||
ADD_SCENE(subghz, save_success, SaveSuccess)
|
||||
ADD_SCENE(subghz, saved, Saved)
|
||||
ADD_SCENE(subghz, transmitter, Transmitter)
|
||||
ADD_SCENE(subghz, show_error, ShowError)
|
||||
ADD_SCENE(subghz, show_error_sub, ShowErrorSub)
|
||||
ADD_SCENE(subghz, show_only_rx, ShowOnlyRx)
|
||||
ADD_SCENE(subghz, saved_menu, SavedMenu)
|
||||
ADD_SCENE(subghz, delete, Delete)
|
||||
ADD_SCENE(subghz, delete_success, DeleteSuccess)
|
||||
ADD_SCENE(subghz, test, Test)
|
||||
ADD_SCENE(subghz, test_static, TestStatic)
|
||||
ADD_SCENE(subghz, test_carrier, TestCarrier)
|
||||
ADD_SCENE(subghz, test_packet, TestPacket)
|
||||
ADD_SCENE(subghz, set_type, SetType)
|
||||
ADD_SCENE(subghz, frequency_analyzer, FrequencyAnalyzer)
|
||||
ADD_SCENE(subghz, read_raw, ReadRAW)
|
||||
ADD_SCENE(subghz, more_raw, MoreRAW)
|
||||
ADD_SCENE(subghz, delete_raw, DeleteRAW)
|
||||
ADD_SCENE(subghz, need_saving, NeedSaving)
|
||||
ADD_SCENE(subghz, rpc, Rpc)
|
||||
@@ -0,0 +1,68 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
void subghz_scene_delete_callback(GuiButtonType result, InputType type, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneDelete);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_scene_delete_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
string_t frequency_str;
|
||||
string_t modulation_str;
|
||||
string_t text;
|
||||
|
||||
string_init(frequency_str);
|
||||
string_init(modulation_str);
|
||||
string_init(text);
|
||||
|
||||
subghz_get_frequency_modulation(subghz, frequency_str, modulation_str);
|
||||
widget_add_string_element(
|
||||
subghz->widget, 78, 0, AlignLeft, AlignTop, FontSecondary, string_get_cstr(frequency_str));
|
||||
|
||||
widget_add_string_element(
|
||||
subghz->widget,
|
||||
113,
|
||||
0,
|
||||
AlignLeft,
|
||||
AlignTop,
|
||||
FontSecondary,
|
||||
string_get_cstr(modulation_str));
|
||||
subghz_protocol_decoder_base_get_string(subghz->txrx->decoder_result, text);
|
||||
widget_add_string_multiline_element(
|
||||
subghz->widget, 0, 0, AlignLeft, AlignTop, FontSecondary, string_get_cstr(text));
|
||||
|
||||
string_clear(frequency_str);
|
||||
string_clear(modulation_str);
|
||||
string_clear(text);
|
||||
|
||||
widget_add_button_element(
|
||||
subghz->widget, GuiButtonTypeRight, "Delete", subghz_scene_delete_callback, subghz);
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
|
||||
}
|
||||
|
||||
bool subghz_scene_delete_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzCustomEventSceneDelete) {
|
||||
string_set(subghz->file_path_tmp, subghz->file_path);
|
||||
if(subghz_delete_file(subghz)) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneDeleteSuccess);
|
||||
} else {
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneStart);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_delete_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
widget_reset(subghz->widget);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
void subghz_scene_delete_raw_callback(GuiButtonType result, InputType type, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzCustomEventSceneDeleteRAW);
|
||||
} else if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) {
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzCustomEventSceneDeleteRAWBack);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_scene_delete_raw_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
string_t frequency_str;
|
||||
string_t modulation_str;
|
||||
|
||||
string_init(frequency_str);
|
||||
string_init(modulation_str);
|
||||
|
||||
char delete_str[SUBGHZ_MAX_LEN_NAME + 16];
|
||||
string_t file_name;
|
||||
string_init(file_name);
|
||||
path_extract_filename(subghz->file_path, file_name, true);
|
||||
snprintf(delete_str, sizeof(delete_str), "\e#Delete %s?\e#", string_get_cstr(file_name));
|
||||
string_clear(file_name);
|
||||
|
||||
widget_add_text_box_element(
|
||||
subghz->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, delete_str, false);
|
||||
|
||||
widget_add_string_element(
|
||||
subghz->widget, 38, 25, AlignLeft, AlignTop, FontSecondary, "RAW signal");
|
||||
subghz_get_frequency_modulation(subghz, frequency_str, modulation_str);
|
||||
widget_add_string_element(
|
||||
subghz->widget, 35, 37, AlignLeft, AlignTop, FontSecondary, string_get_cstr(frequency_str));
|
||||
|
||||
widget_add_string_element(
|
||||
subghz->widget,
|
||||
72,
|
||||
37,
|
||||
AlignLeft,
|
||||
AlignTop,
|
||||
FontSecondary,
|
||||
string_get_cstr(modulation_str));
|
||||
|
||||
string_clear(frequency_str);
|
||||
string_clear(modulation_str);
|
||||
|
||||
widget_add_button_element(
|
||||
subghz->widget, GuiButtonTypeRight, "Delete", subghz_scene_delete_raw_callback, subghz);
|
||||
widget_add_button_element(
|
||||
subghz->widget, GuiButtonTypeLeft, "Back", subghz_scene_delete_raw_callback, subghz);
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
|
||||
}
|
||||
|
||||
bool subghz_scene_delete_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzCustomEventSceneDeleteRAW) {
|
||||
string_set(subghz->file_path_tmp, subghz->file_path);
|
||||
if(subghz_delete_file(subghz)) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneDeleteSuccess);
|
||||
} else {
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneStart);
|
||||
}
|
||||
return true;
|
||||
} else if(event.event == SubGhzCustomEventSceneDeleteRAWBack) {
|
||||
return scene_manager_previous_scene(subghz->scene_manager);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_delete_raw_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
widget_reset(subghz->widget);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
void subghz_scene_delete_success_popup_callback(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzCustomEventSceneDeleteSuccess);
|
||||
}
|
||||
|
||||
void subghz_scene_delete_success_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
// Setup view
|
||||
Popup* popup = subghz->popup;
|
||||
popup_set_icon(popup, 0, 2, &I_DolphinMafia_115x62);
|
||||
popup_set_header(popup, "Deleted", 83, 19, AlignLeft, AlignBottom);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_set_context(popup, subghz);
|
||||
popup_set_callback(popup, subghz_scene_delete_success_popup_callback);
|
||||
popup_enable_timeout(popup);
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdPopup);
|
||||
}
|
||||
|
||||
bool subghz_scene_delete_success_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzCustomEventSceneDeleteSuccess) {
|
||||
if(scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneReadRAW)) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW);
|
||||
} else if(scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneSaved)) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaved);
|
||||
} else {
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneStart);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_delete_success_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
// Clear view
|
||||
Popup* popup = subghz->popup;
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 0, NULL);
|
||||
popup_set_callback(popup, NULL);
|
||||
popup_set_context(popup, NULL);
|
||||
popup_set_timeout(popup, 0);
|
||||
popup_disable_timeout(popup);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../views/subghz_frequency_analyzer.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
void subghz_scene_frequency_analyzer_callback(SubGhzCustomEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void subghz_scene_frequency_analyzer_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
DOLPHIN_DEED(DolphinDeedSubGhzFrequencyAnalyzer);
|
||||
subghz_frequency_analyzer_set_callback(
|
||||
subghz->subghz_frequency_analyzer, subghz_scene_frequency_analyzer_callback, subghz);
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdFrequencyAnalyzer);
|
||||
}
|
||||
|
||||
bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzCustomEventSceneAnalyzerLock) {
|
||||
notification_message(subghz->notifications, &sequence_set_green_255);
|
||||
return true;
|
||||
} else if(event.event == SubGhzCustomEventSceneAnalyzerUnlock) {
|
||||
notification_message(subghz->notifications, &sequence_reset_rgb);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_frequency_analyzer_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
notification_message(subghz->notifications, &sequence_reset_rgb);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "../subghz_i.h"
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexEdit,
|
||||
SubmenuIndexDelete,
|
||||
};
|
||||
|
||||
void subghz_scene_more_raw_submenu_callback(void* context, uint32_t index) {
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void subghz_scene_more_raw_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Rename",
|
||||
SubmenuIndexEdit,
|
||||
subghz_scene_more_raw_submenu_callback,
|
||||
subghz);
|
||||
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Delete",
|
||||
SubmenuIndexDelete,
|
||||
subghz_scene_more_raw_submenu_callback,
|
||||
subghz);
|
||||
|
||||
submenu_set_selected_item(
|
||||
subghz->submenu, scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneMoreRAW));
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdMenu);
|
||||
}
|
||||
|
||||
bool subghz_scene_more_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubmenuIndexDelete) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet);
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneMoreRAW, SubmenuIndexDelete);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneDeleteRAW);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexEdit) {
|
||||
string_reset(subghz->file_path_tmp);
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneMoreRAW, SubmenuIndexEdit);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_more_raw_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
submenu_reset(subghz->submenu);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
void subghz_scene_need_saving_callback(GuiButtonType result, InputType type, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneStay);
|
||||
} else if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) {
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneExit);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_scene_need_saving_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
widget_add_string_multiline_element(
|
||||
subghz->widget, 64, 13, AlignCenter, AlignCenter, FontPrimary, "Exit to Sub-GHz menu?");
|
||||
widget_add_string_multiline_element(
|
||||
subghz->widget,
|
||||
64,
|
||||
32,
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
FontSecondary,
|
||||
"All unsaved will be\nlost.");
|
||||
|
||||
widget_add_button_element(
|
||||
subghz->widget, GuiButtonTypeRight, "Stay", subghz_scene_need_saving_callback, subghz);
|
||||
widget_add_button_element(
|
||||
subghz->widget, GuiButtonTypeLeft, "Exit", subghz_scene_need_saving_callback, subghz);
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
|
||||
}
|
||||
|
||||
bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeBack) {
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateBack;
|
||||
scene_manager_previous_scene(subghz->scene_manager);
|
||||
return true;
|
||||
} else if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzCustomEventSceneStay) {
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateBack;
|
||||
scene_manager_previous_scene(subghz->scene_manager);
|
||||
return true;
|
||||
} else if(event.event == SubGhzCustomEventSceneExit) {
|
||||
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateExit) {
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
subghz_preset_init(
|
||||
subghz,
|
||||
"AM650",
|
||||
subghz_setting_get_default_frequency(subghz->setting),
|
||||
NULL,
|
||||
0);
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneStart);
|
||||
} else {
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
scene_manager_previous_scene(subghz->scene_manager);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_need_saving_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
widget_reset(subghz->widget);
|
||||
}
|
||||
@@ -0,0 +1,342 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../views/subghz_read_raw.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
#include <lib/subghz/protocols/raw.h>
|
||||
#include <lib/toolbox/path.h>
|
||||
|
||||
#define RAW_FILE_NAME "Raw_signal_"
|
||||
#define TAG "SubGhzSceneReadRAW"
|
||||
|
||||
bool subghz_scene_read_raw_update_filename(SubGhz* subghz) {
|
||||
bool ret = false;
|
||||
//set the path to read the file
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
do {
|
||||
if(!flipper_format_rewind(subghz->txrx->fff_data)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_format_read_string(subghz->txrx->fff_data, "File_name", temp_str)) {
|
||||
FURI_LOG_E(TAG, "Missing File_name");
|
||||
break;
|
||||
}
|
||||
|
||||
string_set(subghz->file_path, temp_str);
|
||||
|
||||
ret = true;
|
||||
} while(false);
|
||||
|
||||
string_clear(temp_str);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void subghz_scene_read_raw_update_statusbar(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
|
||||
string_t frequency_str;
|
||||
string_t modulation_str;
|
||||
|
||||
string_init(frequency_str);
|
||||
string_init(modulation_str);
|
||||
|
||||
subghz_get_frequency_modulation(subghz, frequency_str, modulation_str);
|
||||
subghz_read_raw_add_data_statusbar(
|
||||
subghz->subghz_read_raw, string_get_cstr(frequency_str), string_get_cstr(modulation_str));
|
||||
|
||||
string_clear(frequency_str);
|
||||
string_clear(modulation_str);
|
||||
}
|
||||
|
||||
void subghz_scene_read_raw_callback(SubGhzCustomEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void subghz_scene_read_raw_callback_end_tx(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzCustomEventViewReadRAWSendStop);
|
||||
}
|
||||
|
||||
void subghz_scene_read_raw_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
string_t file_name;
|
||||
string_init(file_name);
|
||||
|
||||
switch(subghz->txrx->rx_key_state) {
|
||||
case SubGhzRxKeyStateBack:
|
||||
subghz_read_raw_set_status(subghz->subghz_read_raw, SubGhzReadRAWStatusIDLE, "");
|
||||
break;
|
||||
case SubGhzRxKeyStateRAWLoad:
|
||||
path_extract_filename(subghz->file_path, file_name, true);
|
||||
subghz_read_raw_set_status(
|
||||
subghz->subghz_read_raw, SubGhzReadRAWStatusLoadKeyTX, string_get_cstr(file_name));
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
break;
|
||||
case SubGhzRxKeyStateRAWSave:
|
||||
path_extract_filename(subghz->file_path, file_name, true);
|
||||
subghz_read_raw_set_status(
|
||||
subghz->subghz_read_raw, SubGhzReadRAWStatusSaveKey, string_get_cstr(file_name));
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
break;
|
||||
default:
|
||||
subghz_read_raw_set_status(subghz->subghz_read_raw, SubGhzReadRAWStatusStart, "");
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
break;
|
||||
}
|
||||
string_clear(file_name);
|
||||
subghz_scene_read_raw_update_statusbar(subghz);
|
||||
|
||||
//set callback view raw
|
||||
subghz_read_raw_set_callback(subghz->subghz_read_raw, subghz_scene_read_raw_callback, subghz);
|
||||
|
||||
subghz->txrx->decoder_result = subghz_receiver_search_decoder_base_by_name(
|
||||
subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME);
|
||||
furi_assert(subghz->txrx->decoder_result);
|
||||
|
||||
//set filter RAW feed
|
||||
subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_RAW);
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdReadRAW);
|
||||
}
|
||||
|
||||
bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
bool consumed = false;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case SubGhzCustomEventViewReadRAWBack:
|
||||
//Stop TX
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
|
||||
subghz_tx_stop(subghz);
|
||||
subghz_sleep(subghz);
|
||||
}
|
||||
//Stop RX
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||
subghz_rx_end(subghz);
|
||||
subghz_sleep(subghz);
|
||||
};
|
||||
//Stop save file
|
||||
subghz_protocol_raw_save_to_file_stop(
|
||||
(SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result);
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
//needed save?
|
||||
if((subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) ||
|
||||
(subghz->txrx->rx_key_state == SubGhzRxKeyStateBack)) {
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateExit;
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
|
||||
} else {
|
||||
//Restore default setting
|
||||
subghz_preset_init(
|
||||
subghz,
|
||||
"AM650",
|
||||
subghz_setting_get_default_frequency(subghz->setting),
|
||||
NULL,
|
||||
0);
|
||||
if(!scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneSaved)) {
|
||||
if(!scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneStart)) {
|
||||
scene_manager_stop(subghz->scene_manager);
|
||||
view_dispatcher_stop(subghz->view_dispatcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
case SubGhzCustomEventViewReadRAWTXRXStop:
|
||||
//Stop TX
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
|
||||
subghz_tx_stop(subghz);
|
||||
subghz_sleep(subghz);
|
||||
}
|
||||
//Stop RX
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||
subghz_rx_end(subghz);
|
||||
subghz_sleep(subghz);
|
||||
};
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
case SubGhzCustomEventViewReadRAWConfig:
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSet);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
case SubGhzCustomEventViewReadRAWErase:
|
||||
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) {
|
||||
if(subghz_scene_read_raw_update_filename(subghz)) {
|
||||
string_set(subghz->file_path_tmp, subghz->file_path);
|
||||
subghz_delete_file(subghz);
|
||||
}
|
||||
}
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
notification_message(subghz->notifications, &sequence_reset_rgb);
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
case SubGhzCustomEventViewReadRAWMore:
|
||||
if(subghz_scene_read_raw_update_filename(subghz)) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSet);
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad;
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneMoreRAW);
|
||||
consumed = true;
|
||||
} else {
|
||||
furi_crash("SubGhz: RAW file name update error.");
|
||||
}
|
||||
break;
|
||||
|
||||
case SubGhzCustomEventViewReadRAWSendStart:
|
||||
|
||||
if(subghz_scene_read_raw_update_filename(subghz)) {
|
||||
//start send
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||
subghz_rx_end(subghz);
|
||||
}
|
||||
if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) ||
|
||||
(subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) {
|
||||
if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) {
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateBack;
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
|
||||
} else {
|
||||
DOLPHIN_DEED(DolphinDeedSubGhzSend);
|
||||
// set callback end tx
|
||||
subghz_protocol_raw_file_encoder_worker_set_callback_end(
|
||||
(SubGhzProtocolEncoderRAW*)subghz_transmitter_get_protocol_instance(
|
||||
subghz->txrx->transmitter),
|
||||
subghz_scene_read_raw_callback_end_tx,
|
||||
subghz);
|
||||
subghz->state_notifications = SubGhzNotificationStateTx;
|
||||
}
|
||||
}
|
||||
}
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
case SubGhzCustomEventViewReadRAWSendStop:
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
|
||||
subghz_tx_stop(subghz);
|
||||
subghz_sleep(subghz);
|
||||
}
|
||||
subghz_read_raw_stop_send(subghz->subghz_read_raw);
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
case SubGhzCustomEventViewReadRAWIDLE:
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||
subghz_rx_end(subghz);
|
||||
subghz_sleep(subghz);
|
||||
};
|
||||
|
||||
size_t spl_count = subghz_protocol_raw_get_sample_write(
|
||||
(SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result);
|
||||
|
||||
subghz_protocol_raw_save_to_file_stop(
|
||||
(SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result);
|
||||
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
string_printf(
|
||||
temp_str, "%s/%s%s", SUBGHZ_RAW_FOLDER, RAW_FILE_NAME, SUBGHZ_APP_EXTENSION);
|
||||
subghz_protocol_raw_gen_fff_data(subghz->txrx->fff_data, string_get_cstr(temp_str));
|
||||
string_clear(temp_str);
|
||||
|
||||
if(spl_count > 0) {
|
||||
notification_message(subghz->notifications, &sequence_set_green_255);
|
||||
} else {
|
||||
notification_message(subghz->notifications, &sequence_reset_rgb);
|
||||
}
|
||||
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey;
|
||||
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
case SubGhzCustomEventViewReadRAWREC:
|
||||
if(subghz->txrx->rx_key_state != SubGhzRxKeyStateIDLE) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
|
||||
} else {
|
||||
//subghz_get_preset_name(subghz, subghz->error_str);
|
||||
if(subghz_protocol_raw_save_to_file_init(
|
||||
(SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result,
|
||||
RAW_FILE_NAME,
|
||||
subghz->txrx->preset)) {
|
||||
DOLPHIN_DEED(DolphinDeedSubGhzRawRec);
|
||||
if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) ||
|
||||
(subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) {
|
||||
subghz_begin(
|
||||
subghz,
|
||||
subghz_setting_get_preset_data_by_name(
|
||||
subghz->setting, string_get_cstr(subghz->txrx->preset->name)));
|
||||
subghz_rx(subghz, subghz->txrx->preset->frequency);
|
||||
}
|
||||
subghz->state_notifications = SubGhzNotificationStateRx;
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey;
|
||||
} else {
|
||||
string_set_str(subghz->error_str, "Function requires\nan SD card.");
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
|
||||
}
|
||||
}
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
case SubGhzCustomEventViewReadRAWSave:
|
||||
if(subghz_scene_read_raw_update_filename(subghz)) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSetRAW);
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateBack;
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
|
||||
}
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeTick) {
|
||||
switch(subghz->state_notifications) {
|
||||
case SubGhzNotificationStateRx:
|
||||
notification_message(subghz->notifications, &sequence_blink_cyan_10);
|
||||
subghz_read_raw_update_sample_write(
|
||||
subghz->subghz_read_raw,
|
||||
subghz_protocol_raw_get_sample_write(
|
||||
(SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result));
|
||||
subghz_read_raw_add_data_rssi(subghz->subghz_read_raw, furi_hal_subghz_get_rssi());
|
||||
break;
|
||||
case SubGhzNotificationStateTx:
|
||||
notification_message(subghz->notifications, &sequence_blink_magenta_10);
|
||||
subghz_read_raw_update_sin(subghz->subghz_read_raw);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void subghz_scene_read_raw_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
//Stop CC1101
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||
subghz_rx_end(subghz);
|
||||
subghz_sleep(subghz);
|
||||
};
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
notification_message(subghz->notifications, &sequence_reset_rgb);
|
||||
|
||||
//filter restoration
|
||||
subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable);
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../views/receiver.h"
|
||||
|
||||
static const NotificationSequence subghs_sequence_rx = {
|
||||
&message_green_255,
|
||||
|
||||
&message_vibro_on,
|
||||
&message_note_c6,
|
||||
&message_delay_50,
|
||||
&message_sound_off,
|
||||
&message_vibro_off,
|
||||
|
||||
&message_delay_50,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const NotificationSequence subghs_sequence_rx_locked = {
|
||||
&message_green_255,
|
||||
|
||||
&message_display_backlight_on,
|
||||
|
||||
&message_vibro_on,
|
||||
&message_note_c6,
|
||||
&message_delay_50,
|
||||
&message_sound_off,
|
||||
&message_vibro_off,
|
||||
|
||||
&message_delay_500,
|
||||
|
||||
&message_display_backlight_off,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static void subghz_scene_receiver_update_statusbar(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
string_t history_stat_str;
|
||||
string_init(history_stat_str);
|
||||
if(!subghz_history_get_text_space_left(subghz->txrx->history, history_stat_str)) {
|
||||
string_t frequency_str;
|
||||
string_t modulation_str;
|
||||
|
||||
string_init(frequency_str);
|
||||
string_init(modulation_str);
|
||||
|
||||
subghz_get_frequency_modulation(subghz, frequency_str, modulation_str);
|
||||
|
||||
subghz_view_receiver_add_data_statusbar(
|
||||
subghz->subghz_receiver,
|
||||
string_get_cstr(frequency_str),
|
||||
string_get_cstr(modulation_str),
|
||||
string_get_cstr(history_stat_str));
|
||||
|
||||
string_clear(frequency_str);
|
||||
string_clear(modulation_str);
|
||||
} else {
|
||||
subghz_view_receiver_add_data_statusbar(
|
||||
subghz->subghz_receiver, string_get_cstr(history_stat_str), "", "");
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
}
|
||||
string_clear(history_stat_str);
|
||||
}
|
||||
|
||||
void subghz_scene_receiver_callback(SubGhzCustomEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
|
||||
}
|
||||
|
||||
static void subghz_scene_add_to_history_callback(
|
||||
SubGhzReceiver* receiver,
|
||||
SubGhzProtocolDecoderBase* decoder_base,
|
||||
void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
string_t str_buff;
|
||||
string_init(str_buff);
|
||||
|
||||
if(subghz_history_add_to_history(subghz->txrx->history, decoder_base, subghz->txrx->preset)) {
|
||||
string_reset(str_buff);
|
||||
|
||||
subghz->state_notifications = SubGhzNotificationStateRxDone;
|
||||
|
||||
subghz_history_get_text_item_menu(
|
||||
subghz->txrx->history, str_buff, subghz_history_get_item(subghz->txrx->history) - 1);
|
||||
subghz_view_receiver_add_item_to_menu(
|
||||
subghz->subghz_receiver,
|
||||
string_get_cstr(str_buff),
|
||||
subghz_history_get_type_protocol(
|
||||
subghz->txrx->history, subghz_history_get_item(subghz->txrx->history) - 1));
|
||||
|
||||
subghz_scene_receiver_update_statusbar(subghz);
|
||||
}
|
||||
subghz_receiver_reset(receiver);
|
||||
string_clear(str_buff);
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey;
|
||||
}
|
||||
|
||||
void subghz_scene_receiver_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
string_t str_buff;
|
||||
string_init(str_buff);
|
||||
|
||||
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateIDLE) {
|
||||
subghz_preset_init(
|
||||
subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0);
|
||||
subghz_history_reset(subghz->txrx->history);
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateStart;
|
||||
}
|
||||
|
||||
subghz_view_receiver_set_lock(subghz->subghz_receiver, subghz->lock);
|
||||
|
||||
//Load history to receiver
|
||||
subghz_view_receiver_exit(subghz->subghz_receiver);
|
||||
for(uint8_t i = 0; i < subghz_history_get_item(subghz->txrx->history); i++) {
|
||||
string_reset(str_buff);
|
||||
subghz_history_get_text_item_menu(subghz->txrx->history, str_buff, i);
|
||||
subghz_view_receiver_add_item_to_menu(
|
||||
subghz->subghz_receiver,
|
||||
string_get_cstr(str_buff),
|
||||
subghz_history_get_type_protocol(subghz->txrx->history, i));
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey;
|
||||
}
|
||||
string_clear(str_buff);
|
||||
subghz_scene_receiver_update_statusbar(subghz);
|
||||
subghz_view_receiver_set_callback(
|
||||
subghz->subghz_receiver, subghz_scene_receiver_callback, subghz);
|
||||
subghz_receiver_set_rx_callback(
|
||||
subghz->txrx->receiver, subghz_scene_add_to_history_callback, subghz);
|
||||
|
||||
subghz->state_notifications = SubGhzNotificationStateRx;
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||
subghz_rx_end(subghz);
|
||||
};
|
||||
if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) ||
|
||||
(subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) {
|
||||
subghz_begin(
|
||||
subghz,
|
||||
subghz_setting_get_preset_data_by_name(
|
||||
subghz->setting, string_get_cstr(subghz->txrx->preset->name)));
|
||||
subghz_rx(subghz, subghz->txrx->preset->frequency);
|
||||
}
|
||||
subghz_view_receiver_set_idx_menu(subghz->subghz_receiver, subghz->txrx->idx_menu_chosen);
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdReceiver);
|
||||
}
|
||||
|
||||
bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
bool consumed = false;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case SubGhzCustomEventViewReceiverBack:
|
||||
// Stop CC1101 Rx
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||
subghz_rx_end(subghz);
|
||||
subghz_sleep(subghz);
|
||||
};
|
||||
subghz->txrx->hopper_state = SubGhzHopperStateOFF;
|
||||
subghz->txrx->idx_menu_chosen = 0;
|
||||
subghz_receiver_set_rx_callback(subghz->txrx->receiver, NULL, subghz);
|
||||
|
||||
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) {
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateExit;
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving);
|
||||
} else {
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
subghz_preset_init(
|
||||
subghz,
|
||||
"AM650",
|
||||
subghz_setting_get_default_frequency(subghz->setting),
|
||||
NULL,
|
||||
0);
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneStart);
|
||||
}
|
||||
consumed = true;
|
||||
break;
|
||||
case SubGhzCustomEventViewReceiverOK:
|
||||
subghz->txrx->idx_menu_chosen =
|
||||
subghz_view_receiver_get_idx_menu(subghz->subghz_receiver);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverInfo);
|
||||
consumed = true;
|
||||
break;
|
||||
case SubGhzCustomEventViewReceiverConfig:
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
subghz->txrx->idx_menu_chosen =
|
||||
subghz_view_receiver_get_idx_menu(subghz->subghz_receiver);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
|
||||
consumed = true;
|
||||
break;
|
||||
case SubGhzCustomEventViewReceiverOffDisplay:
|
||||
notification_message(subghz->notifications, &sequence_display_backlight_off);
|
||||
consumed = true;
|
||||
break;
|
||||
case SubGhzCustomEventViewReceiverUnlock:
|
||||
subghz->lock = SubGhzLockOff;
|
||||
consumed = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeTick) {
|
||||
if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
|
||||
subghz_hopper_update(subghz);
|
||||
subghz_scene_receiver_update_statusbar(subghz);
|
||||
}
|
||||
switch(subghz->state_notifications) {
|
||||
case SubGhzNotificationStateRx:
|
||||
notification_message(subghz->notifications, &sequence_blink_cyan_10);
|
||||
break;
|
||||
case SubGhzNotificationStateRxDone:
|
||||
if(subghz->lock != SubGhzLockOn) {
|
||||
notification_message(subghz->notifications, &subghs_sequence_rx);
|
||||
} else {
|
||||
notification_message(subghz->notifications, &subghs_sequence_rx_locked);
|
||||
}
|
||||
subghz->state_notifications = SubGhzNotificationStateRx;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void subghz_scene_receiver_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
#include "../subghz_i.h"
|
||||
|
||||
enum SubGhzSettingIndex {
|
||||
SubGhzSettingIndexFrequency,
|
||||
SubGhzSettingIndexHopping,
|
||||
SubGhzSettingIndexModulation,
|
||||
SubGhzSettingIndexLock,
|
||||
};
|
||||
|
||||
#define HOPPING_COUNT 2
|
||||
const char* const hopping_text[HOPPING_COUNT] = {
|
||||
"OFF",
|
||||
"ON",
|
||||
};
|
||||
const uint32_t hopping_value[HOPPING_COUNT] = {
|
||||
SubGhzHopperStateOFF,
|
||||
SubGhzHopperStateRunnig,
|
||||
};
|
||||
|
||||
uint8_t subghz_scene_receiver_config_next_frequency(const uint32_t value, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
uint8_t index = 0;
|
||||
for(uint8_t i = 0; i < subghz_setting_get_frequency_count(subghz->setting); i++) {
|
||||
if(value == subghz_setting_get_frequency(subghz->setting, i)) {
|
||||
index = i;
|
||||
break;
|
||||
} else {
|
||||
index = subghz_setting_get_frequency_default_index(subghz->setting);
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
uint8_t subghz_scene_receiver_config_next_preset(const char* preset_name, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
uint8_t index = 0;
|
||||
for(uint8_t i = 0; i < subghz_setting_get_preset_count(subghz->setting); i++) {
|
||||
if(!strcmp(subghz_setting_get_preset_name(subghz->setting, i), preset_name)) {
|
||||
index = i;
|
||||
break;
|
||||
} else {
|
||||
// index = subghz_setting_get_frequency_default_index(subghz->setting);
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
uint8_t subghz_scene_receiver_config_hopper_value_index(
|
||||
const uint32_t value,
|
||||
const uint32_t values[],
|
||||
uint8_t values_count,
|
||||
void* context) {
|
||||
furi_assert(context);
|
||||
UNUSED(values_count);
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(value == values[0]) {
|
||||
return 0;
|
||||
} else {
|
||||
variable_item_set_current_value_text(
|
||||
(VariableItem*)scene_manager_get_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
||||
" -----");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void subghz_scene_receiver_config_set_frequency(VariableItem* item) {
|
||||
SubGhz* subghz = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
if(subghz->txrx->hopper_state == SubGhzHopperStateOFF) {
|
||||
char text_buf[10] = {0};
|
||||
snprintf(
|
||||
text_buf,
|
||||
sizeof(text_buf),
|
||||
"%lu.%02lu",
|
||||
subghz_setting_get_frequency(subghz->setting, index) / 1000000,
|
||||
(subghz_setting_get_frequency(subghz->setting, index) % 1000000) / 10000);
|
||||
variable_item_set_current_value_text(item, text_buf);
|
||||
subghz->txrx->preset->frequency = subghz_setting_get_frequency(subghz->setting, index);
|
||||
} else {
|
||||
variable_item_set_current_value_index(
|
||||
item, subghz_setting_get_frequency_default_index(subghz->setting));
|
||||
}
|
||||
}
|
||||
|
||||
static void subghz_scene_receiver_config_set_preset(VariableItem* item) {
|
||||
SubGhz* subghz = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(
|
||||
item, subghz_setting_get_preset_name(subghz->setting, index));
|
||||
subghz_preset_init(
|
||||
subghz,
|
||||
subghz_setting_get_preset_name(subghz->setting, index),
|
||||
subghz->txrx->preset->frequency,
|
||||
subghz_setting_get_preset_data(subghz->setting, index),
|
||||
subghz_setting_get_preset_data_size(subghz->setting, index));
|
||||
}
|
||||
|
||||
static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) {
|
||||
SubGhz* subghz = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, hopping_text[index]);
|
||||
if(hopping_value[index] == SubGhzHopperStateOFF) {
|
||||
char text_buf[10] = {0};
|
||||
snprintf(
|
||||
text_buf,
|
||||
sizeof(text_buf),
|
||||
"%lu.%02lu",
|
||||
subghz_setting_get_default_frequency(subghz->setting) / 1000000,
|
||||
(subghz_setting_get_default_frequency(subghz->setting) % 1000000) / 10000);
|
||||
variable_item_set_current_value_text(
|
||||
(VariableItem*)scene_manager_get_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
||||
text_buf);
|
||||
subghz->txrx->preset->frequency = subghz_setting_get_default_frequency(subghz->setting);
|
||||
variable_item_set_current_value_index(
|
||||
(VariableItem*)scene_manager_get_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
||||
subghz_setting_get_frequency_default_index(subghz->setting));
|
||||
} else {
|
||||
variable_item_set_current_value_text(
|
||||
(VariableItem*)scene_manager_get_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
||||
" -----");
|
||||
variable_item_set_current_value_index(
|
||||
(VariableItem*)scene_manager_get_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReceiverConfig),
|
||||
subghz_setting_get_frequency_default_index(subghz->setting));
|
||||
}
|
||||
|
||||
subghz->txrx->hopper_state = hopping_value[index];
|
||||
}
|
||||
|
||||
static void subghz_scene_receiver_config_var_list_enter_callback(void* context, uint32_t index) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
if(index == SubGhzSettingIndexLock) {
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzCustomEventSceneSettingLock);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_scene_receiver_config_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
VariableItem* item;
|
||||
uint8_t value_index;
|
||||
|
||||
item = variable_item_list_add(
|
||||
subghz->variable_item_list,
|
||||
"Frequency:",
|
||||
subghz_setting_get_frequency_count(subghz->setting),
|
||||
subghz_scene_receiver_config_set_frequency,
|
||||
subghz);
|
||||
value_index =
|
||||
subghz_scene_receiver_config_next_frequency(subghz->txrx->preset->frequency, subghz);
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReceiverConfig, (uint32_t)item);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
char text_buf[10] = {0};
|
||||
snprintf(
|
||||
text_buf,
|
||||
sizeof(text_buf),
|
||||
"%lu.%02lu",
|
||||
subghz_setting_get_frequency(subghz->setting, value_index) / 1000000,
|
||||
(subghz_setting_get_frequency(subghz->setting, value_index) % 1000000) / 10000);
|
||||
variable_item_set_current_value_text(item, text_buf);
|
||||
|
||||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
|
||||
SubGhzCustomEventManagerSet) {
|
||||
item = variable_item_list_add(
|
||||
subghz->variable_item_list,
|
||||
"Hopping:",
|
||||
HOPPING_COUNT,
|
||||
subghz_scene_receiver_config_set_hopping_running,
|
||||
subghz);
|
||||
value_index = subghz_scene_receiver_config_hopper_value_index(
|
||||
subghz->txrx->hopper_state, hopping_value, HOPPING_COUNT, subghz);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, hopping_text[value_index]);
|
||||
}
|
||||
|
||||
item = variable_item_list_add(
|
||||
subghz->variable_item_list,
|
||||
"Modulation:",
|
||||
subghz_setting_get_preset_count(subghz->setting),
|
||||
subghz_scene_receiver_config_set_preset,
|
||||
subghz);
|
||||
value_index = subghz_scene_receiver_config_next_preset(
|
||||
string_get_cstr(subghz->txrx->preset->name), subghz);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(
|
||||
item, subghz_setting_get_preset_name(subghz->setting, value_index));
|
||||
|
||||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
|
||||
SubGhzCustomEventManagerSet) {
|
||||
variable_item_list_add(subghz->variable_item_list, "Lock Keyboard", 1, NULL, NULL);
|
||||
variable_item_list_set_enter_callback(
|
||||
subghz->variable_item_list,
|
||||
subghz_scene_receiver_config_var_list_enter_callback,
|
||||
subghz);
|
||||
}
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList);
|
||||
}
|
||||
|
||||
bool subghz_scene_receiver_config_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzCustomEventSceneSettingLock) {
|
||||
subghz->lock = SubGhzLockOn;
|
||||
scene_manager_previous_scene(subghz->scene_manager);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void subghz_scene_receiver_config_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
variable_item_list_reset(subghz->variable_item_list);
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet);
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if((result == GuiButtonTypeCenter) && (type == InputTypePress)) {
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzCustomEventSceneReceiverInfoTxStart);
|
||||
} else if((result == GuiButtonTypeCenter) && (type == InputTypeRelease)) {
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzCustomEventSceneReceiverInfoTxStop);
|
||||
} else if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzCustomEventSceneReceiverInfoSave);
|
||||
}
|
||||
}
|
||||
|
||||
static bool subghz_scene_receiver_info_update_parser(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
subghz->txrx->decoder_result = subghz_receiver_search_decoder_base_by_name(
|
||||
subghz->txrx->receiver,
|
||||
subghz_history_get_protocol_name(subghz->txrx->history, subghz->txrx->idx_menu_chosen));
|
||||
if(subghz->txrx->decoder_result) {
|
||||
subghz_protocol_decoder_base_deserialize(
|
||||
subghz->txrx->decoder_result,
|
||||
subghz_history_get_raw_data(subghz->txrx->history, subghz->txrx->idx_menu_chosen));
|
||||
|
||||
SubGhzPresetDefinition* preset =
|
||||
subghz_history_get_preset_def(subghz->txrx->history, subghz->txrx->idx_menu_chosen);
|
||||
subghz_preset_init(
|
||||
subghz,
|
||||
string_get_cstr(preset->name),
|
||||
preset->frequency,
|
||||
preset->data,
|
||||
preset->data_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_receiver_info_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
DOLPHIN_DEED(DolphinDeedSubGhzReceiverInfo);
|
||||
if(subghz_scene_receiver_info_update_parser(subghz)) {
|
||||
string_t frequency_str;
|
||||
string_t modulation_str;
|
||||
string_t text;
|
||||
|
||||
string_init(frequency_str);
|
||||
string_init(modulation_str);
|
||||
string_init(text);
|
||||
|
||||
subghz_get_frequency_modulation(subghz, frequency_str, modulation_str);
|
||||
widget_add_string_element(
|
||||
subghz->widget,
|
||||
78,
|
||||
0,
|
||||
AlignLeft,
|
||||
AlignTop,
|
||||
FontSecondary,
|
||||
string_get_cstr(frequency_str));
|
||||
|
||||
widget_add_string_element(
|
||||
subghz->widget,
|
||||
113,
|
||||
0,
|
||||
AlignLeft,
|
||||
AlignTop,
|
||||
FontSecondary,
|
||||
string_get_cstr(modulation_str));
|
||||
subghz_protocol_decoder_base_get_string(subghz->txrx->decoder_result, text);
|
||||
widget_add_string_multiline_element(
|
||||
subghz->widget, 0, 0, AlignLeft, AlignTop, FontSecondary, string_get_cstr(text));
|
||||
|
||||
string_clear(frequency_str);
|
||||
string_clear(modulation_str);
|
||||
string_clear(text);
|
||||
|
||||
if((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Save) ==
|
||||
SubGhzProtocolFlag_Save) {
|
||||
widget_add_button_element(
|
||||
subghz->widget,
|
||||
GuiButtonTypeRight,
|
||||
"Save",
|
||||
subghz_scene_receiver_info_callback,
|
||||
subghz);
|
||||
}
|
||||
if(((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) ==
|
||||
SubGhzProtocolFlag_Send) &&
|
||||
subghz->txrx->decoder_result->protocol->encoder->deserialize &&
|
||||
subghz->txrx->decoder_result->protocol->type == SubGhzProtocolTypeStatic) {
|
||||
widget_add_button_element(
|
||||
subghz->widget,
|
||||
GuiButtonTypeCenter,
|
||||
"Send",
|
||||
subghz_scene_receiver_info_callback,
|
||||
subghz);
|
||||
}
|
||||
} else {
|
||||
widget_add_icon_element(subghz->widget, 37, 15, &I_DolphinCommon_56x48);
|
||||
widget_add_string_element(
|
||||
subghz->widget, 13, 8, AlignLeft, AlignBottom, FontSecondary, "Error history parse.");
|
||||
}
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
|
||||
}
|
||||
|
||||
bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzCustomEventSceneReceiverInfoTxStart) {
|
||||
//CC1101 Stop RX -> Start TX
|
||||
if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
|
||||
subghz->txrx->hopper_state = SubGhzHopperStatePause;
|
||||
}
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||
subghz_rx_end(subghz);
|
||||
}
|
||||
if(!subghz_scene_receiver_info_update_parser(subghz)) {
|
||||
return false;
|
||||
}
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateIDLE ||
|
||||
subghz->txrx->txrx_state == SubGhzTxRxStateSleep) {
|
||||
if(!subghz_tx_start(
|
||||
subghz,
|
||||
subghz_history_get_raw_data(
|
||||
subghz->txrx->history, subghz->txrx->idx_menu_chosen))) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
|
||||
} else {
|
||||
subghz->state_notifications = SubGhzNotificationStateTx;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if(event.event == SubGhzCustomEventSceneReceiverInfoTxStop) {
|
||||
//CC1101 Stop Tx -> Start RX
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
|
||||
subghz_tx_stop(subghz);
|
||||
}
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) {
|
||||
subghz_begin(
|
||||
subghz,
|
||||
subghz_setting_get_preset_data_by_name(
|
||||
subghz->setting, string_get_cstr(subghz->txrx->preset->name)));
|
||||
subghz_rx(subghz, subghz->txrx->preset->frequency);
|
||||
}
|
||||
if(subghz->txrx->hopper_state == SubGhzHopperStatePause) {
|
||||
subghz->txrx->hopper_state = SubGhzHopperStateRunnig;
|
||||
}
|
||||
subghz->state_notifications = SubGhzNotificationStateRx;
|
||||
return true;
|
||||
} else if(event.event == SubGhzCustomEventSceneReceiverInfoSave) {
|
||||
//CC1101 Stop RX -> Save
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
|
||||
subghz->txrx->hopper_state = SubGhzHopperStateOFF;
|
||||
}
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||
subghz_rx_end(subghz);
|
||||
subghz_sleep(subghz);
|
||||
}
|
||||
if(!subghz_scene_receiver_info_update_parser(subghz)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Save) ==
|
||||
SubGhzProtocolFlag_Save) {
|
||||
subghz_file_name_clear(subghz);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeTick) {
|
||||
if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
|
||||
subghz_hopper_update(subghz);
|
||||
}
|
||||
switch(subghz->state_notifications) {
|
||||
case SubGhzNotificationStateTx:
|
||||
notification_message(subghz->notifications, &sequence_blink_magenta_10);
|
||||
break;
|
||||
case SubGhzNotificationStateRx:
|
||||
notification_message(subghz->notifications, &sequence_blink_cyan_10);
|
||||
break;
|
||||
case SubGhzNotificationStateRxDone:
|
||||
notification_message(subghz->notifications, &sequence_blink_green_100);
|
||||
subghz->state_notifications = SubGhzNotificationStateRx;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_receiver_info_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
widget_reset(subghz->widget);
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
#include "../subghz_i.h"
|
||||
|
||||
typedef enum {
|
||||
SubGhzRpcStateIdle,
|
||||
SubGhzRpcStateLoaded,
|
||||
} SubGhzRpcState;
|
||||
|
||||
void subghz_scene_rpc_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
Popup* popup = subghz->popup;
|
||||
|
||||
popup_set_header(popup, "Sub-GHz", 89, 42, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, "RPC mode", 89, 44, AlignCenter, AlignTop);
|
||||
|
||||
popup_set_icon(popup, 0, 12, &I_RFIDDolphinSend_97x61);
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdPopup);
|
||||
|
||||
scene_manager_set_scene_state(subghz->scene_manager, SubGhzSceneRpc, SubGhzRpcStateIdle);
|
||||
|
||||
notification_message(subghz->notifications, &sequence_display_backlight_on);
|
||||
}
|
||||
|
||||
bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
Popup* popup = subghz->popup;
|
||||
bool consumed = false;
|
||||
SubGhzRpcState state = scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneRpc);
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
if(event.event == SubGhzCustomEventSceneExit) {
|
||||
scene_manager_stop(subghz->scene_manager);
|
||||
view_dispatcher_stop(subghz->view_dispatcher);
|
||||
rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventAppExit, true);
|
||||
} else if(event.event == SubGhzCustomEventSceneRpcSessionClose) {
|
||||
scene_manager_stop(subghz->scene_manager);
|
||||
view_dispatcher_stop(subghz->view_dispatcher);
|
||||
} else if(event.event == SubGhzCustomEventSceneRpcButtonPress) {
|
||||
bool result = false;
|
||||
if((subghz->txrx->txrx_state == SubGhzTxRxStateSleep) &&
|
||||
(state == SubGhzRpcStateLoaded)) {
|
||||
subghz_blink_start(subghz);
|
||||
result = subghz_tx_start(subghz, subghz->txrx->fff_data);
|
||||
result = true;
|
||||
}
|
||||
rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventButtonPress, result);
|
||||
} else if(event.event == SubGhzCustomEventSceneRpcButtonRelease) {
|
||||
bool result = false;
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
|
||||
subghz_blink_stop(subghz);
|
||||
subghz_tx_stop(subghz);
|
||||
subghz_sleep(subghz);
|
||||
result = true;
|
||||
}
|
||||
rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventButtonRelease, result);
|
||||
} else if(event.event == SubGhzCustomEventSceneRpcLoad) {
|
||||
bool result = false;
|
||||
const char* arg = rpc_system_app_get_data(subghz->rpc_ctx);
|
||||
if(arg && (state == SubGhzRpcStateIdle)) {
|
||||
if(subghz_key_load(subghz, arg, false)) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneRpc, SubGhzRpcStateLoaded);
|
||||
string_set_str(subghz->file_path, arg);
|
||||
result = true;
|
||||
string_t file_name;
|
||||
string_init(file_name);
|
||||
path_extract_filename(subghz->file_path, file_name, true);
|
||||
|
||||
snprintf(
|
||||
subghz->file_name_tmp,
|
||||
SUBGHZ_MAX_LEN_NAME,
|
||||
"loaded\n%s",
|
||||
string_get_cstr(file_name));
|
||||
popup_set_text(popup, subghz->file_name_tmp, 89, 44, AlignCenter, AlignTop);
|
||||
|
||||
string_clear(file_name);
|
||||
}
|
||||
}
|
||||
rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventLoadFile, result);
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void subghz_scene_rpc_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
|
||||
subghz_tx_stop(subghz);
|
||||
subghz_sleep(subghz);
|
||||
subghz_blink_stop(subghz);
|
||||
}
|
||||
|
||||
Popup* popup = subghz->popup;
|
||||
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 0, NULL);
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "m-string.h"
|
||||
#include "subghz/types.h"
|
||||
#include <lib/toolbox/random_name.h>
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
#include <lib/subghz/protocols/raw.h>
|
||||
#include <gui/modules/validators.h>
|
||||
|
||||
#define MAX_TEXT_INPUT_LEN 22
|
||||
|
||||
void subghz_scene_save_name_text_input_callback(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneSaveName);
|
||||
}
|
||||
|
||||
void subghz_scene_save_name_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
// Setup view
|
||||
TextInput* text_input = subghz->text_input;
|
||||
bool dev_name_empty = false;
|
||||
|
||||
string_t file_name;
|
||||
string_t dir_name;
|
||||
string_init(file_name);
|
||||
string_init(dir_name);
|
||||
|
||||
if(!subghz_path_is_file(subghz->file_path)) {
|
||||
char file_name_buf[SUBGHZ_MAX_LEN_NAME] = {0};
|
||||
set_random_name(file_name_buf, SUBGHZ_MAX_LEN_NAME);
|
||||
string_set_str(file_name, file_name_buf);
|
||||
string_set_str(subghz->file_path, SUBGHZ_APP_FOLDER);
|
||||
//highlighting the entire filename by default
|
||||
dev_name_empty = true;
|
||||
} else {
|
||||
string_set(subghz->file_path_tmp, subghz->file_path);
|
||||
path_extract_dirname(string_get_cstr(subghz->file_path), dir_name);
|
||||
path_extract_filename(subghz->file_path, file_name, true);
|
||||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
|
||||
SubGhzCustomEventManagerNoSet) {
|
||||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) ==
|
||||
SubGhzCustomEventManagerSetRAW) {
|
||||
dev_name_empty = true;
|
||||
subghz_get_next_name_file(subghz, SUBGHZ_MAX_LEN_NAME);
|
||||
}
|
||||
path_extract_filename(subghz->file_path, file_name, true);
|
||||
}
|
||||
string_set(subghz->file_path, dir_name);
|
||||
}
|
||||
|
||||
strncpy(subghz->file_name_tmp, string_get_cstr(file_name), SUBGHZ_MAX_LEN_NAME);
|
||||
text_input_set_header_text(text_input, "Name signal");
|
||||
text_input_set_result_callback(
|
||||
text_input,
|
||||
subghz_scene_save_name_text_input_callback,
|
||||
subghz,
|
||||
subghz->file_name_tmp,
|
||||
MAX_TEXT_INPUT_LEN, // buffer size
|
||||
dev_name_empty);
|
||||
|
||||
ValidatorIsFile* validator_is_file =
|
||||
validator_is_file_alloc_init(string_get_cstr(subghz->file_path), SUBGHZ_APP_EXTENSION, "");
|
||||
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
||||
|
||||
string_clear(file_name);
|
||||
string_clear(dir_name);
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdTextInput);
|
||||
}
|
||||
|
||||
bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeBack) {
|
||||
if(!strcmp(subghz->file_name_tmp, "") ||
|
||||
scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
|
||||
SubGhzCustomEventManagerNoSet) {
|
||||
string_set(subghz->file_path, subghz->file_path_tmp);
|
||||
}
|
||||
scene_manager_previous_scene(subghz->scene_manager);
|
||||
return true;
|
||||
} else if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzCustomEventSceneSaveName) {
|
||||
if(strcmp(subghz->file_name_tmp, "")) {
|
||||
string_cat_printf(
|
||||
subghz->file_path, "/%s%s", subghz->file_name_tmp, SUBGHZ_APP_EXTENSION);
|
||||
if(subghz_path_is_file(subghz->file_path_tmp)) {
|
||||
if(!subghz_rename_file(subghz)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneSetType) !=
|
||||
SubGhzCustomEventManagerNoSet) {
|
||||
subghz_save_protocol_to_file(
|
||||
subghz, subghz->txrx->fff_data, string_get_cstr(subghz->file_path));
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager,
|
||||
SubGhzSceneSetType,
|
||||
SubGhzCustomEventManagerNoSet);
|
||||
} else {
|
||||
subghz_save_protocol_to_file(
|
||||
subghz,
|
||||
subghz_history_get_raw_data(
|
||||
subghz->txrx->history, subghz->txrx->idx_menu_chosen),
|
||||
string_get_cstr(subghz->file_path));
|
||||
}
|
||||
}
|
||||
|
||||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) !=
|
||||
SubGhzCustomEventManagerNoSet) {
|
||||
subghz_protocol_raw_gen_fff_data(
|
||||
subghz->txrx->fff_data, string_get_cstr(subghz->file_path));
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet);
|
||||
} else {
|
||||
subghz_file_name_clear(subghz);
|
||||
}
|
||||
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveSuccess);
|
||||
return true;
|
||||
} else {
|
||||
string_set_str(subghz->error_str, "No name file");
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_save_name_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
// Clear validator
|
||||
void* validator_context = text_input_get_validator_callback_context(subghz->text_input);
|
||||
text_input_set_validator(subghz->text_input, NULL, NULL);
|
||||
validator_is_file_free(validator_context);
|
||||
|
||||
// Clear view
|
||||
text_input_reset(subghz->text_input);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
#include <dolphin/helpers/dolphin_deed.h>
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
void subghz_scene_save_success_popup_callback(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneSaveSuccess);
|
||||
}
|
||||
|
||||
void subghz_scene_save_success_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
DOLPHIN_DEED(DolphinDeedSubGhzSave);
|
||||
|
||||
// Setup view
|
||||
Popup* popup = subghz->popup;
|
||||
popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59);
|
||||
popup_set_header(popup, "Saved!", 13, 22, AlignLeft, AlignBottom);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_set_context(popup, subghz);
|
||||
popup_set_callback(popup, subghz_scene_save_success_popup_callback);
|
||||
popup_enable_timeout(popup);
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdPopup);
|
||||
}
|
||||
|
||||
bool subghz_scene_save_success_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzCustomEventSceneSaveSuccess) {
|
||||
if(!scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneReceiver)) {
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWSave;
|
||||
if(!scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneReadRAW)) {
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
if(!scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneSaved)) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaved);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_save_success_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
// Clear view
|
||||
Popup* popup = subghz->popup;
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 0, NULL);
|
||||
popup_set_callback(popup, NULL);
|
||||
popup_set_context(popup, NULL);
|
||||
popup_set_timeout(popup, 0);
|
||||
popup_disable_timeout(popup);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "../subghz_i.h"
|
||||
|
||||
void subghz_scene_saved_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(subghz_load_protocol_from_file(subghz)) {
|
||||
if((!strcmp(subghz->txrx->decoder_result->protocol->name, "RAW"))) {
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad;
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW);
|
||||
} else {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSavedMenu);
|
||||
}
|
||||
} else {
|
||||
scene_manager_search_and_switch_to_previous_scene(subghz->scene_manager, SubGhzSceneStart);
|
||||
}
|
||||
}
|
||||
|
||||
bool subghz_scene_saved_on_event(void* context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
UNUSED(event);
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_saved_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#include "../subghz_i.h"
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexEmulate,
|
||||
SubmenuIndexEdit,
|
||||
SubmenuIndexDelete,
|
||||
};
|
||||
|
||||
void subghz_scene_saved_menu_submenu_callback(void* context, uint32_t index) {
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void subghz_scene_saved_menu_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Emulate",
|
||||
SubmenuIndexEmulate,
|
||||
subghz_scene_saved_menu_submenu_callback,
|
||||
subghz);
|
||||
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Rename",
|
||||
SubmenuIndexEdit,
|
||||
subghz_scene_saved_menu_submenu_callback,
|
||||
subghz);
|
||||
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Delete",
|
||||
SubmenuIndexDelete,
|
||||
subghz_scene_saved_menu_submenu_callback,
|
||||
subghz);
|
||||
|
||||
submenu_set_selected_item(
|
||||
subghz->submenu,
|
||||
scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneSavedMenu));
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdMenu);
|
||||
}
|
||||
|
||||
bool subghz_scene_saved_menu_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubmenuIndexEmulate) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneSavedMenu, SubmenuIndexEmulate);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTransmitter);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexDelete) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneSavedMenu, SubmenuIndexDelete);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneDelete);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexEdit) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneSavedMenu, SubmenuIndexEdit);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_saved_menu_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
submenu_reset(subghz->submenu);
|
||||
}
|
||||
@@ -0,0 +1,396 @@
|
||||
#include "../subghz_i.h"
|
||||
#include <lib/subghz/protocols/keeloq.h>
|
||||
#include <lib/subghz/protocols/secplus_v1.h>
|
||||
#include <lib/subghz/protocols/secplus_v2.h>
|
||||
#include <lib/subghz/blocks/math.h>
|
||||
#include <dolphin/dolphin.h>
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
#include <lib/toolbox/stream/stream.h>
|
||||
#include <lib/subghz/protocols/registry.h>
|
||||
|
||||
#define TAG "SubGhzSetType"
|
||||
|
||||
bool subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
void* context,
|
||||
const char* protocol_name,
|
||||
uint64_t key,
|
||||
uint32_t bit,
|
||||
uint32_t frequency,
|
||||
const char* preset_name) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
|
||||
bool res = false;
|
||||
|
||||
subghz_preset_init(subghz, preset_name, frequency, NULL, 0);
|
||||
subghz->txrx->decoder_result =
|
||||
subghz_receiver_search_decoder_base_by_name(subghz->txrx->receiver, protocol_name);
|
||||
|
||||
if(subghz->txrx->decoder_result == NULL) {
|
||||
string_set_str(subghz->error_str, "Protocol not\nfound!");
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub);
|
||||
return false;
|
||||
}
|
||||
|
||||
do {
|
||||
Stream* fff_data_stream = flipper_format_get_raw_stream(subghz->txrx->fff_data);
|
||||
stream_clean(fff_data_stream);
|
||||
if(!subghz_protocol_decoder_base_serialize(
|
||||
subghz->txrx->decoder_result, subghz->txrx->fff_data, subghz->txrx->preset)) {
|
||||
FURI_LOG_E(TAG, "Unable to serialize");
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_update_uint32(subghz->txrx->fff_data, "Bit", &bit, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable to update Bit");
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t key_data[sizeof(uint64_t)] = {0};
|
||||
for(size_t i = 0; i < sizeof(uint64_t); i++) {
|
||||
key_data[sizeof(uint64_t) - i - 1] = (key >> i * 8) & 0xFF;
|
||||
}
|
||||
if(!flipper_format_update_hex(subghz->txrx->fff_data, "Key", key_data, sizeof(uint64_t))) {
|
||||
FURI_LOG_E(TAG, "Unable to update Key");
|
||||
break;
|
||||
}
|
||||
res = true;
|
||||
} while(false);
|
||||
return res;
|
||||
}
|
||||
|
||||
void subghz_scene_set_type_submenu_callback(void* context, uint32_t index) {
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void subghz_scene_set_type_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Princeton_433",
|
||||
SubmenuIndexPricenton,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Nice Flo 12bit_433",
|
||||
SubmenuIndexNiceFlo12bit,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Nice Flo 24bit_433",
|
||||
SubmenuIndexNiceFlo24bit,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"CAME 12bit_433",
|
||||
SubmenuIndexCAME12bit,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"CAME 24bit_433",
|
||||
SubmenuIndexCAME24bit,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Linear_300",
|
||||
SubmenuIndexLinear_300_00,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"CAME TWEE",
|
||||
SubmenuIndexCAMETwee,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
// submenu_add_item(
|
||||
// subghz->submenu, "Nero Sketch", SubmenuIndexNeroSketch, subghz_scene_set_type_submenu_callback, subghz);
|
||||
// submenu_add_item(
|
||||
// subghz->submenu, "Nero Radio", SubmenuIndexNeroRadio, subghz_scene_set_type_submenu_callback, subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Gate TX_433",
|
||||
SubmenuIndexGateTX,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"DoorHan_315",
|
||||
SubmenuIndexDoorHan_315_00,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"DoorHan_433",
|
||||
SubmenuIndexDoorHan_433_92,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"LiftMaster_315",
|
||||
SubmenuIndexLiftMaster_315_00,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"LiftMaster_390",
|
||||
SubmenuIndexLiftMaster_390_00,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Security+2.0_310",
|
||||
SubmenuIndexSecPlus_v2_310_00,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Security+2.0_315",
|
||||
SubmenuIndexSecPlus_v2_315_00,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Security+2.0_390",
|
||||
SubmenuIndexSecPlus_v2_390_00,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
|
||||
submenu_set_selected_item(
|
||||
subghz->submenu, scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneSetType));
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdMenu);
|
||||
}
|
||||
|
||||
bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
bool generated_protocol = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
//ToDo Fix
|
||||
uint32_t key = subghz_random_serial();
|
||||
switch(event.event) {
|
||||
case SubmenuIndexPricenton:
|
||||
key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz, SUBGHZ_PROTOCOL_PRINCETON_NAME, key, 24, 433920000, "AM650")) {
|
||||
uint32_t te = 400;
|
||||
flipper_format_update_uint32(subghz->txrx->fff_data, "TE", (uint32_t*)&te, 1);
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexNiceFlo12bit:
|
||||
key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz, SUBGHZ_PROTOCOL_NICE_FLO_NAME, key, 12, 433920000, "AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexNiceFlo24bit:
|
||||
key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz, SUBGHZ_PROTOCOL_NICE_FLO_NAME, key, 24, 433920000, "AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexCAME12bit:
|
||||
key = (key & 0x0000FFF0) | 0x1; //btn 0x1, 0x2, 0x4
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz, SUBGHZ_PROTOCOL_CAME_NAME, key, 12, 433920000, "AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexCAME24bit:
|
||||
key = (key & 0x00FFFFF0) | 0x4; //btn 0x1, 0x2, 0x4, 0x8
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz, SUBGHZ_PROTOCOL_CAME_NAME, key, 24, 433920000, "AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexLinear_300_00:
|
||||
key = (key & 0x3FF);
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz, SUBGHZ_PROTOCOL_LINEAR_NAME, key, 10, 300000000, "AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexCAMETwee:
|
||||
key = (key & 0x0FFFFFF0);
|
||||
key = 0x003FFF7200000000 | (key ^ 0xE0E0E0EE);
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz, SUBGHZ_PROTOCOL_CAME_TWEE_NAME, key, 54, 433920000, "AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
// case SubmenuIndexNeroSketch:
|
||||
// /* code */
|
||||
// break;
|
||||
// case SubmenuIndexNeroRadio:
|
||||
// /* code */
|
||||
// break;
|
||||
case SubmenuIndexGateTX:
|
||||
key = (key & 0x00F0FF00) | 0xF << 16 | 0x40; //btn 0xF, 0xC, 0xA, 0x6 (?)
|
||||
uint64_t rev_key = subghz_protocol_blocks_reverse_key(key, 24);
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz, SUBGHZ_PROTOCOL_GATE_TX_NAME, rev_key, 24, 433920000, "AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexDoorHan_433_92:
|
||||
subghz->txrx->transmitter = subghz_transmitter_alloc_init(
|
||||
subghz->txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME);
|
||||
subghz_preset_init(
|
||||
subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0);
|
||||
if(subghz->txrx->transmitter) {
|
||||
subghz_protocol_keeloq_create_data(
|
||||
subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter),
|
||||
subghz->txrx->fff_data,
|
||||
key & 0x0FFFFFFF,
|
||||
0x2,
|
||||
0x0003,
|
||||
"DoorHan",
|
||||
subghz->txrx->preset);
|
||||
generated_protocol = true;
|
||||
} else {
|
||||
generated_protocol = false;
|
||||
}
|
||||
subghz_transmitter_free(subghz->txrx->transmitter);
|
||||
if(!generated_protocol) {
|
||||
string_set_str(
|
||||
subghz->error_str, "Function requires\nan SD card with\nfresh databases.");
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexDoorHan_315_00:
|
||||
subghz->txrx->transmitter = subghz_transmitter_alloc_init(
|
||||
subghz->txrx->environment, SUBGHZ_PROTOCOL_KEELOQ_NAME);
|
||||
subghz_preset_init(subghz, "AM650", 315000000, NULL, 0);
|
||||
if(subghz->txrx->transmitter) {
|
||||
subghz_protocol_keeloq_create_data(
|
||||
subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter),
|
||||
subghz->txrx->fff_data,
|
||||
key & 0x0FFFFFFF,
|
||||
0x2,
|
||||
0x0003,
|
||||
"DoorHan",
|
||||
subghz->txrx->preset);
|
||||
generated_protocol = true;
|
||||
} else {
|
||||
generated_protocol = false;
|
||||
}
|
||||
subghz_transmitter_free(subghz->txrx->transmitter);
|
||||
if(!generated_protocol) {
|
||||
string_set_str(
|
||||
subghz->error_str, "Function requires\nan SD card with\nfresh databases.");
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexLiftMaster_315_00:
|
||||
while(!subghz_protocol_secplus_v1_check_fixed(key)) {
|
||||
key = subghz_random_serial();
|
||||
}
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz,
|
||||
SUBGHZ_PROTOCOL_SECPLUS_V1_NAME,
|
||||
(uint64_t)key << 32 | 0xE6000000,
|
||||
42,
|
||||
315000000,
|
||||
"AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexLiftMaster_390_00:
|
||||
while(!subghz_protocol_secplus_v1_check_fixed(key)) {
|
||||
key = subghz_random_serial();
|
||||
}
|
||||
if(subghz_scene_set_type_submenu_gen_data_protocol(
|
||||
subghz,
|
||||
SUBGHZ_PROTOCOL_SECPLUS_V1_NAME,
|
||||
(uint64_t)key << 32 | 0xE6000000,
|
||||
42,
|
||||
390000000,
|
||||
"AM650")) {
|
||||
generated_protocol = true;
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexSecPlus_v2_310_00:
|
||||
subghz->txrx->transmitter = subghz_transmitter_alloc_init(
|
||||
subghz->txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME);
|
||||
subghz_preset_init(subghz, "AM650", 310000000, NULL, 0);
|
||||
if(subghz->txrx->transmitter) {
|
||||
subghz_protocol_secplus_v2_create_data(
|
||||
subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter),
|
||||
subghz->txrx->fff_data,
|
||||
key,
|
||||
0x68,
|
||||
0xE500000,
|
||||
subghz->txrx->preset);
|
||||
generated_protocol = true;
|
||||
} else {
|
||||
generated_protocol = false;
|
||||
}
|
||||
subghz_transmitter_free(subghz->txrx->transmitter);
|
||||
break;
|
||||
case SubmenuIndexSecPlus_v2_315_00:
|
||||
subghz->txrx->transmitter = subghz_transmitter_alloc_init(
|
||||
subghz->txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME);
|
||||
subghz_preset_init(subghz, "AM650", 315000000, NULL, 0);
|
||||
if(subghz->txrx->transmitter) {
|
||||
subghz_protocol_secplus_v2_create_data(
|
||||
subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter),
|
||||
subghz->txrx->fff_data,
|
||||
key,
|
||||
0x68,
|
||||
0xE500000,
|
||||
subghz->txrx->preset);
|
||||
generated_protocol = true;
|
||||
} else {
|
||||
generated_protocol = false;
|
||||
}
|
||||
subghz_transmitter_free(subghz->txrx->transmitter);
|
||||
break;
|
||||
case SubmenuIndexSecPlus_v2_390_00:
|
||||
subghz->txrx->transmitter = subghz_transmitter_alloc_init(
|
||||
subghz->txrx->environment, SUBGHZ_PROTOCOL_SECPLUS_V2_NAME);
|
||||
subghz_preset_init(subghz, "AM650", 390000000, NULL, 0);
|
||||
if(subghz->txrx->transmitter) {
|
||||
subghz_protocol_secplus_v2_create_data(
|
||||
subghz_transmitter_get_protocol_instance(subghz->txrx->transmitter),
|
||||
subghz->txrx->fff_data,
|
||||
key,
|
||||
0x68,
|
||||
0xE500000,
|
||||
subghz->txrx->preset);
|
||||
generated_protocol = true;
|
||||
} else {
|
||||
generated_protocol = false;
|
||||
}
|
||||
subghz_transmitter_free(subghz->txrx->transmitter);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
scene_manager_set_scene_state(subghz->scene_manager, SubGhzSceneSetType, event.event);
|
||||
|
||||
if(generated_protocol) {
|
||||
subghz_file_name_clear(subghz);
|
||||
DOLPHIN_DEED(DolphinDeedSubGhzAddManually);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_set_type_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
submenu_reset(subghz->submenu);
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
static const NotificationSequence subghs_sequence_sd_error = {
|
||||
&message_red_255,
|
||||
&message_green_255,
|
||||
&message_do_not_reset,
|
||||
NULL,
|
||||
};
|
||||
|
||||
void subghz_scene_show_error_callback(GuiButtonType result, InputType type, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzCustomEventSceneShowErrorOk);
|
||||
} else if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) {
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzCustomEventSceneShowErrorBack);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_scene_show_error_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
widget_add_icon_element(subghz->widget, 0, 0, &I_SDQuestion_35x43);
|
||||
|
||||
widget_add_string_multiline_element(
|
||||
subghz->widget,
|
||||
81,
|
||||
24,
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
FontSecondary,
|
||||
string_get_cstr(subghz->error_str));
|
||||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneShowError) ==
|
||||
SubGhzCustomEventManagerSet) {
|
||||
widget_add_button_element(
|
||||
subghz->widget, GuiButtonTypeRight, "OK", subghz_scene_show_error_callback, subghz);
|
||||
} else {
|
||||
notification_message(subghz->notifications, &subghs_sequence_sd_error);
|
||||
}
|
||||
|
||||
widget_add_button_element(
|
||||
subghz->widget, GuiButtonTypeLeft, "Back", subghz_scene_show_error_callback, subghz);
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
|
||||
}
|
||||
|
||||
bool subghz_scene_show_error_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeBack) {
|
||||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneShowError) ==
|
||||
SubGhzCustomEventManagerSet) {
|
||||
return false;
|
||||
} else {
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneStart);
|
||||
}
|
||||
return true;
|
||||
} else if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzCustomEventSceneShowErrorOk) {
|
||||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneShowError) ==
|
||||
SubGhzCustomEventManagerSet) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneStart);
|
||||
}
|
||||
return true;
|
||||
} else if(event.event == SubGhzCustomEventSceneShowErrorBack) {
|
||||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneShowError) ==
|
||||
SubGhzCustomEventManagerSet) {
|
||||
//exit app
|
||||
if(!scene_manager_previous_scene(subghz->scene_manager)) {
|
||||
scene_manager_stop(subghz->scene_manager);
|
||||
view_dispatcher_stop(subghz->view_dispatcher);
|
||||
}
|
||||
} else {
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneStart);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_show_error_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneShowError, SubGhzCustomEventManagerNoSet);
|
||||
widget_reset(subghz->widget);
|
||||
string_reset(subghz->error_str);
|
||||
notification_message(subghz->notifications, &sequence_reset_rgb);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
void subghz_scene_show_error_sub_popup_callback(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneShowErrorSub);
|
||||
}
|
||||
|
||||
void subghz_scene_show_error_sub_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
// Setup view
|
||||
Popup* popup = subghz->popup;
|
||||
popup_set_icon(popup, 72, 17, &I_DolphinCommon_56x48);
|
||||
popup_set_header(popup, string_get_cstr(subghz->error_str), 14, 15, AlignLeft, AlignTop);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_set_context(popup, subghz);
|
||||
popup_set_callback(popup, subghz_scene_show_error_sub_popup_callback);
|
||||
popup_enable_timeout(popup);
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdPopup);
|
||||
|
||||
notification_message(subghz->notifications, &sequence_set_red_255);
|
||||
}
|
||||
|
||||
bool subghz_scene_show_error_sub_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzCustomEventSceneShowErrorSub) {
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneStart);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_show_error_sub_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
// Clear view
|
||||
Popup* popup = subghz->popup;
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 0, NULL);
|
||||
popup_set_callback(popup, NULL);
|
||||
popup_set_context(popup, NULL);
|
||||
popup_set_timeout(popup, 0);
|
||||
popup_disable_timeout(popup);
|
||||
string_reset(subghz->error_str);
|
||||
|
||||
notification_message(subghz->notifications, &sequence_reset_rgb);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
void subghz_scene_show_only_rx_popup_callback(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneShowOnlyRX);
|
||||
}
|
||||
|
||||
void subghz_scene_show_only_rx_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
// Setup view
|
||||
Popup* popup = subghz->popup;
|
||||
|
||||
const char* header_text = "Transmission is blocked";
|
||||
const char* message_text = "Transmission on\nthis frequency is\nrestricted in\nyour region";
|
||||
if(!furi_hal_region_is_provisioned()) {
|
||||
header_text = "Firmware update needed";
|
||||
message_text = "Please update\nfirmware before\nusing this feature\nflipp.dev/upd";
|
||||
}
|
||||
|
||||
popup_set_header(popup, header_text, 63, 3, AlignCenter, AlignTop);
|
||||
popup_set_text(popup, message_text, 0, 17, AlignLeft, AlignTop);
|
||||
popup_set_icon(popup, 72, 17, &I_DolphinCommon_56x48);
|
||||
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_set_context(popup, subghz);
|
||||
popup_set_callback(popup, subghz_scene_show_only_rx_popup_callback);
|
||||
popup_enable_timeout(popup);
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdPopup);
|
||||
}
|
||||
|
||||
bool subghz_scene_show_only_rx_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzCustomEventSceneShowOnlyRX) {
|
||||
scene_manager_previous_scene(subghz->scene_manager);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_show_only_rx_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
// Clear view
|
||||
Popup* popup = subghz->popup;
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 0, NULL);
|
||||
popup_set_callback(popup, NULL);
|
||||
popup_set_context(popup, NULL);
|
||||
popup_set_timeout(popup, 0);
|
||||
popup_disable_timeout(popup);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
#include "../subghz_i.h"
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexRead = 10,
|
||||
SubmenuIndexSaved,
|
||||
SubmenuIndexTest,
|
||||
SubmenuIndexAddManualy,
|
||||
SubmenuIndexFrequencyAnalyzer,
|
||||
SubmenuIndexReadRAW,
|
||||
};
|
||||
|
||||
void subghz_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void subghz_scene_start_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
if(subghz->state_notifications == SubGhzNotificationStateStarting) {
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
}
|
||||
submenu_add_item(
|
||||
subghz->submenu, "Read", SubmenuIndexRead, subghz_scene_start_submenu_callback, subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Read RAW",
|
||||
SubmenuIndexReadRAW,
|
||||
subghz_scene_start_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu, "Saved", SubmenuIndexSaved, subghz_scene_start_submenu_callback, subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Add Manually",
|
||||
SubmenuIndexAddManualy,
|
||||
subghz_scene_start_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Frequency Analyzer",
|
||||
SubmenuIndexFrequencyAnalyzer,
|
||||
subghz_scene_start_submenu_callback,
|
||||
subghz);
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||
submenu_add_item(
|
||||
subghz->submenu, "Test", SubmenuIndexTest, subghz_scene_start_submenu_callback, subghz);
|
||||
}
|
||||
submenu_set_selected_item(
|
||||
subghz->submenu, scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneStart));
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdMenu);
|
||||
}
|
||||
|
||||
bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeBack) {
|
||||
//exit app
|
||||
scene_manager_stop(subghz->scene_manager);
|
||||
view_dispatcher_stop(subghz->view_dispatcher);
|
||||
return true;
|
||||
} else if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubmenuIndexReadRAW) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexReadRAW);
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexRead) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexRead);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiver);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexSaved) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexSaved);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaved);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexAddManualy) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexAddManualy);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSetType);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexFrequencyAnalyzer) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexFrequencyAnalyzer);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneFrequencyAnalyzer);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexTest) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneStart, SubmenuIndexTest);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTest);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_start_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
submenu_reset(subghz->submenu);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "../subghz_i.h"
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexCarrier,
|
||||
SubmenuIndexPacket,
|
||||
SubmenuIndexStatic,
|
||||
};
|
||||
|
||||
void subghz_scene_test_submenu_callback(void* context, uint32_t index) {
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void subghz_scene_test_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"Carrier",
|
||||
SubmenuIndexCarrier,
|
||||
subghz_scene_test_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu, "Packet", SubmenuIndexPacket, subghz_scene_test_submenu_callback, subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu, "Static", SubmenuIndexStatic, subghz_scene_test_submenu_callback, subghz);
|
||||
|
||||
submenu_set_selected_item(
|
||||
subghz->submenu, scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneTest));
|
||||
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdMenu);
|
||||
}
|
||||
|
||||
bool subghz_scene_test_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubmenuIndexCarrier) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneTest, SubmenuIndexCarrier);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTestCarrier);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexPacket) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneTest, SubmenuIndexPacket);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTestPacket);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexStatic) {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneTest, SubmenuIndexStatic);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTestStatic);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_test_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
submenu_reset(subghz->submenu);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../views/subghz_test_carrier.h"
|
||||
|
||||
void subghz_scene_test_carrier_callback(SubGhzTestCarrierEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void subghz_scene_test_carrier_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
subghz_test_carrier_set_callback(
|
||||
subghz->subghz_test_carrier, subghz_scene_test_carrier_callback, subghz);
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdTestCarrier);
|
||||
}
|
||||
|
||||
bool subghz_scene_test_carrier_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzTestCarrierEventOnlyRx) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_test_carrier_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../views/subghz_test_packet.h"
|
||||
|
||||
void subghz_scene_test_packet_callback(SubGhzTestPacketEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void subghz_scene_test_packet_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
subghz_test_packet_set_callback(
|
||||
subghz->subghz_test_packet, subghz_scene_test_packet_callback, subghz);
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdTestPacket);
|
||||
}
|
||||
|
||||
bool subghz_scene_test_packet_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzTestPacketEventOnlyRx) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_test_packet_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../views/subghz_test_static.h"
|
||||
|
||||
void subghz_scene_test_static_callback(SubGhzTestStaticEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void subghz_scene_test_static_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
subghz_test_static_set_callback(
|
||||
subghz->subghz_test_static, subghz_scene_test_static_callback, subghz);
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdStatic);
|
||||
}
|
||||
|
||||
bool subghz_scene_test_static_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzTestStaticEventOnlyRx) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_test_static_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
#include "../subghz_i.h"
|
||||
#include "../views/transmitter.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
void subghz_scene_transmitter_callback(SubGhzCustomEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
|
||||
}
|
||||
|
||||
bool subghz_scene_transmitter_update_data_show(void* context) {
|
||||
//ToDo Fix
|
||||
SubGhz* subghz = context;
|
||||
|
||||
if(subghz->txrx->decoder_result) {
|
||||
string_t key_str;
|
||||
string_t frequency_str;
|
||||
string_t modulation_str;
|
||||
|
||||
string_init(key_str);
|
||||
string_init(frequency_str);
|
||||
string_init(modulation_str);
|
||||
uint8_t show_button = 0;
|
||||
|
||||
subghz_protocol_decoder_base_deserialize(
|
||||
subghz->txrx->decoder_result, subghz->txrx->fff_data);
|
||||
subghz_protocol_decoder_base_get_string(subghz->txrx->decoder_result, key_str);
|
||||
|
||||
if((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) ==
|
||||
SubGhzProtocolFlag_Send) {
|
||||
show_button = 1;
|
||||
}
|
||||
|
||||
subghz_get_frequency_modulation(subghz, frequency_str, modulation_str);
|
||||
subghz_view_transmitter_add_data_to_show(
|
||||
subghz->subghz_transmitter,
|
||||
string_get_cstr(key_str),
|
||||
string_get_cstr(frequency_str),
|
||||
string_get_cstr(modulation_str),
|
||||
show_button);
|
||||
|
||||
string_clear(frequency_str);
|
||||
string_clear(modulation_str);
|
||||
string_clear(key_str);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_transmitter_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
DOLPHIN_DEED(DolphinDeedSubGhzSend);
|
||||
if(!subghz_scene_transmitter_update_data_show(subghz)) {
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzCustomEventViewTransmitterError);
|
||||
}
|
||||
|
||||
subghz_view_transmitter_set_callback(
|
||||
subghz->subghz_transmitter, subghz_scene_transmitter_callback, subghz);
|
||||
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdTransmitter);
|
||||
}
|
||||
|
||||
bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) {
|
||||
SubGhz* subghz = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubGhzCustomEventViewTransmitterSendStart) {
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||
subghz_rx_end(subghz);
|
||||
}
|
||||
if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) ||
|
||||
(subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) {
|
||||
if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
|
||||
} else {
|
||||
subghz->state_notifications = SubGhzNotificationStateTx;
|
||||
subghz_scene_transmitter_update_data_show(subghz);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if(event.event == SubGhzCustomEventViewTransmitterSendStop) {
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
|
||||
subghz_tx_stop(subghz);
|
||||
subghz_sleep(subghz);
|
||||
}
|
||||
return true;
|
||||
} else if(event.event == SubGhzCustomEventViewTransmitterBack) {
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
scene_manager_search_and_switch_to_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneStart);
|
||||
return true;
|
||||
} else if(event.event == SubGhzCustomEventViewTransmitterError) {
|
||||
string_set_str(subghz->error_str, "Protocol not\nfound!");
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub);
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeTick) {
|
||||
if(subghz->state_notifications == SubGhzNotificationStateTx) {
|
||||
notification_message(subghz->notifications, &sequence_blink_magenta_10);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_scene_transmitter_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
}
|
||||
@@ -0,0 +1,373 @@
|
||||
/* Abandon hope, all ye who enter here. */
|
||||
|
||||
#include "m-string.h"
|
||||
#include "subghz/types.h"
|
||||
#include "subghz_i.h"
|
||||
#include <lib/toolbox/path.h>
|
||||
|
||||
bool subghz_custom_event_callback(void* context, uint32_t event) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
return scene_manager_handle_custom_event(subghz->scene_manager, event);
|
||||
}
|
||||
|
||||
bool subghz_back_event_callback(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
return scene_manager_handle_back_event(subghz->scene_manager);
|
||||
}
|
||||
|
||||
void subghz_tick_event_callback(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
scene_manager_handle_tick_event(subghz->scene_manager);
|
||||
}
|
||||
|
||||
static void subghz_rpc_command_callback(RpcAppSystemEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
|
||||
furi_assert(subghz->rpc_ctx);
|
||||
|
||||
if(event == RpcAppEventSessionClose) {
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzCustomEventSceneRpcSessionClose);
|
||||
rpc_system_app_set_callback(subghz->rpc_ctx, NULL, NULL);
|
||||
subghz->rpc_ctx = NULL;
|
||||
} else if(event == RpcAppEventAppExit) {
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneExit);
|
||||
} else if(event == RpcAppEventLoadFile) {
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneRpcLoad);
|
||||
} else if(event == RpcAppEventButtonPress) {
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzCustomEventSceneRpcButtonPress);
|
||||
} else if(event == RpcAppEventButtonRelease) {
|
||||
view_dispatcher_send_custom_event(
|
||||
subghz->view_dispatcher, SubGhzCustomEventSceneRpcButtonRelease);
|
||||
} else {
|
||||
rpc_system_app_confirm(subghz->rpc_ctx, event, false);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_blink_start(SubGhz* instance) {
|
||||
furi_assert(instance);
|
||||
notification_message(instance->notifications, &sequence_blink_start_magenta);
|
||||
}
|
||||
|
||||
void subghz_blink_stop(SubGhz* instance) {
|
||||
furi_assert(instance);
|
||||
notification_message(instance->notifications, &sequence_blink_stop);
|
||||
}
|
||||
|
||||
SubGhz* subghz_alloc() {
|
||||
SubGhz* subghz = malloc(sizeof(SubGhz));
|
||||
|
||||
string_init(subghz->file_path);
|
||||
string_init(subghz->file_path_tmp);
|
||||
|
||||
// GUI
|
||||
subghz->gui = furi_record_open(RECORD_GUI);
|
||||
|
||||
// View Dispatcher
|
||||
subghz->view_dispatcher = view_dispatcher_alloc();
|
||||
view_dispatcher_enable_queue(subghz->view_dispatcher);
|
||||
|
||||
subghz->scene_manager = scene_manager_alloc(&subghz_scene_handlers, subghz);
|
||||
view_dispatcher_set_event_callback_context(subghz->view_dispatcher, subghz);
|
||||
view_dispatcher_set_custom_event_callback(
|
||||
subghz->view_dispatcher, subghz_custom_event_callback);
|
||||
view_dispatcher_set_navigation_event_callback(
|
||||
subghz->view_dispatcher, subghz_back_event_callback);
|
||||
view_dispatcher_set_tick_event_callback(
|
||||
subghz->view_dispatcher, subghz_tick_event_callback, 100);
|
||||
|
||||
// Open Notification record
|
||||
subghz->notifications = furi_record_open(RECORD_NOTIFICATION);
|
||||
|
||||
// SubMenu
|
||||
subghz->submenu = submenu_alloc();
|
||||
view_dispatcher_add_view(
|
||||
subghz->view_dispatcher, SubGhzViewIdMenu, submenu_get_view(subghz->submenu));
|
||||
|
||||
// Receiver
|
||||
subghz->subghz_receiver = subghz_view_receiver_alloc();
|
||||
view_dispatcher_add_view(
|
||||
subghz->view_dispatcher,
|
||||
SubGhzViewIdReceiver,
|
||||
subghz_view_receiver_get_view(subghz->subghz_receiver));
|
||||
|
||||
// Popup
|
||||
subghz->popup = popup_alloc();
|
||||
view_dispatcher_add_view(
|
||||
subghz->view_dispatcher, SubGhzViewIdPopup, popup_get_view(subghz->popup));
|
||||
|
||||
// Text Input
|
||||
subghz->text_input = text_input_alloc();
|
||||
view_dispatcher_add_view(
|
||||
subghz->view_dispatcher, SubGhzViewIdTextInput, text_input_get_view(subghz->text_input));
|
||||
|
||||
// Custom Widget
|
||||
subghz->widget = widget_alloc();
|
||||
view_dispatcher_add_view(
|
||||
subghz->view_dispatcher, SubGhzViewIdWidget, widget_get_view(subghz->widget));
|
||||
|
||||
//Dialog
|
||||
subghz->dialogs = furi_record_open(RECORD_DIALOGS);
|
||||
|
||||
// Transmitter
|
||||
subghz->subghz_transmitter = subghz_view_transmitter_alloc();
|
||||
view_dispatcher_add_view(
|
||||
subghz->view_dispatcher,
|
||||
SubGhzViewIdTransmitter,
|
||||
subghz_view_transmitter_get_view(subghz->subghz_transmitter));
|
||||
|
||||
// Variable Item List
|
||||
subghz->variable_item_list = variable_item_list_alloc();
|
||||
view_dispatcher_add_view(
|
||||
subghz->view_dispatcher,
|
||||
SubGhzViewIdVariableItemList,
|
||||
variable_item_list_get_view(subghz->variable_item_list));
|
||||
|
||||
// Frequency Analyzer
|
||||
subghz->subghz_frequency_analyzer = subghz_frequency_analyzer_alloc();
|
||||
view_dispatcher_add_view(
|
||||
subghz->view_dispatcher,
|
||||
SubGhzViewIdFrequencyAnalyzer,
|
||||
subghz_frequency_analyzer_get_view(subghz->subghz_frequency_analyzer));
|
||||
|
||||
// Read RAW
|
||||
subghz->subghz_read_raw = subghz_read_raw_alloc();
|
||||
view_dispatcher_add_view(
|
||||
subghz->view_dispatcher,
|
||||
SubGhzViewIdReadRAW,
|
||||
subghz_read_raw_get_view(subghz->subghz_read_raw));
|
||||
|
||||
// Carrier Test Module
|
||||
subghz->subghz_test_carrier = subghz_test_carrier_alloc();
|
||||
view_dispatcher_add_view(
|
||||
subghz->view_dispatcher,
|
||||
SubGhzViewIdTestCarrier,
|
||||
subghz_test_carrier_get_view(subghz->subghz_test_carrier));
|
||||
|
||||
// Packet Test
|
||||
subghz->subghz_test_packet = subghz_test_packet_alloc();
|
||||
view_dispatcher_add_view(
|
||||
subghz->view_dispatcher,
|
||||
SubGhzViewIdTestPacket,
|
||||
subghz_test_packet_get_view(subghz->subghz_test_packet));
|
||||
|
||||
// Static send
|
||||
subghz->subghz_test_static = subghz_test_static_alloc();
|
||||
view_dispatcher_add_view(
|
||||
subghz->view_dispatcher,
|
||||
SubGhzViewIdStatic,
|
||||
subghz_test_static_get_view(subghz->subghz_test_static));
|
||||
|
||||
//init setting
|
||||
subghz->setting = subghz_setting_alloc();
|
||||
subghz_setting_load(subghz->setting, EXT_PATH("subghz/assets/setting_user"));
|
||||
|
||||
//init Worker & Protocol & History & KeyBoard
|
||||
subghz->lock = SubGhzLockOff;
|
||||
subghz->txrx = malloc(sizeof(SubGhzTxRx));
|
||||
subghz->txrx->preset = malloc(sizeof(SubGhzPresetDefinition));
|
||||
string_init(subghz->txrx->preset->name);
|
||||
subghz_preset_init(
|
||||
subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0);
|
||||
|
||||
subghz->txrx->txrx_state = SubGhzTxRxStateSleep;
|
||||
subghz->txrx->hopper_state = SubGhzHopperStateOFF;
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
||||
subghz->txrx->history = subghz_history_alloc();
|
||||
subghz->txrx->worker = subghz_worker_alloc();
|
||||
subghz->txrx->fff_data = flipper_format_string_alloc();
|
||||
|
||||
subghz->txrx->environment = subghz_environment_alloc();
|
||||
subghz_environment_set_came_atomo_rainbow_table_file_name(
|
||||
subghz->txrx->environment, EXT_PATH("subghz/assets/came_atomo"));
|
||||
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||
subghz->txrx->environment, EXT_PATH("subghz/assets/nice_flor_s"));
|
||||
subghz->txrx->receiver = subghz_receiver_alloc_init(subghz->txrx->environment);
|
||||
subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable);
|
||||
|
||||
subghz_worker_set_overrun_callback(
|
||||
subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset);
|
||||
subghz_worker_set_pair_callback(
|
||||
subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode);
|
||||
subghz_worker_set_context(subghz->txrx->worker, subghz->txrx->receiver);
|
||||
|
||||
//Init Error_str
|
||||
string_init(subghz->error_str);
|
||||
|
||||
return subghz;
|
||||
}
|
||||
|
||||
void subghz_free(SubGhz* subghz) {
|
||||
furi_assert(subghz);
|
||||
|
||||
if(subghz->rpc_ctx) {
|
||||
rpc_system_app_set_callback(subghz->rpc_ctx, NULL, NULL);
|
||||
rpc_system_app_send_exited(subghz->rpc_ctx);
|
||||
subghz_blink_stop(subghz);
|
||||
subghz->rpc_ctx = NULL;
|
||||
}
|
||||
|
||||
// Packet Test
|
||||
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTestPacket);
|
||||
subghz_test_packet_free(subghz->subghz_test_packet);
|
||||
|
||||
// Carrier Test
|
||||
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTestCarrier);
|
||||
subghz_test_carrier_free(subghz->subghz_test_carrier);
|
||||
|
||||
// Static
|
||||
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdStatic);
|
||||
subghz_test_static_free(subghz->subghz_test_static);
|
||||
|
||||
// Receiver
|
||||
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdReceiver);
|
||||
subghz_view_receiver_free(subghz->subghz_receiver);
|
||||
|
||||
// TextInput
|
||||
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTextInput);
|
||||
text_input_free(subghz->text_input);
|
||||
|
||||
// Custom Widget
|
||||
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdWidget);
|
||||
widget_free(subghz->widget);
|
||||
|
||||
//Dialog
|
||||
furi_record_close(RECORD_DIALOGS);
|
||||
|
||||
// Transmitter
|
||||
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTransmitter);
|
||||
subghz_view_transmitter_free(subghz->subghz_transmitter);
|
||||
|
||||
// Variable Item List
|
||||
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList);
|
||||
variable_item_list_free(subghz->variable_item_list);
|
||||
|
||||
// Frequency Analyzer
|
||||
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdFrequencyAnalyzer);
|
||||
subghz_frequency_analyzer_free(subghz->subghz_frequency_analyzer);
|
||||
|
||||
// Read RAW
|
||||
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdReadRAW);
|
||||
subghz_read_raw_free(subghz->subghz_read_raw);
|
||||
|
||||
// Submenu
|
||||
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdMenu);
|
||||
submenu_free(subghz->submenu);
|
||||
|
||||
// Popup
|
||||
view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdPopup);
|
||||
popup_free(subghz->popup);
|
||||
|
||||
// Scene manager
|
||||
scene_manager_free(subghz->scene_manager);
|
||||
|
||||
// View Dispatcher
|
||||
view_dispatcher_free(subghz->view_dispatcher);
|
||||
|
||||
// GUI
|
||||
furi_record_close(RECORD_GUI);
|
||||
subghz->gui = NULL;
|
||||
|
||||
//setting
|
||||
subghz_setting_free(subghz->setting);
|
||||
|
||||
//Worker & Protocol & History
|
||||
subghz_receiver_free(subghz->txrx->receiver);
|
||||
subghz_environment_free(subghz->txrx->environment);
|
||||
subghz_worker_free(subghz->txrx->worker);
|
||||
flipper_format_free(subghz->txrx->fff_data);
|
||||
subghz_history_free(subghz->txrx->history);
|
||||
string_clear(subghz->txrx->preset->name);
|
||||
free(subghz->txrx->preset);
|
||||
free(subghz->txrx);
|
||||
|
||||
//Error string
|
||||
string_clear(subghz->error_str);
|
||||
|
||||
// Notifications
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
subghz->notifications = NULL;
|
||||
|
||||
// Path strings
|
||||
string_clear(subghz->file_path);
|
||||
string_clear(subghz->file_path_tmp);
|
||||
|
||||
// The rest
|
||||
free(subghz);
|
||||
}
|
||||
|
||||
int32_t subghz_app(void* p) {
|
||||
SubGhz* subghz = subghz_alloc();
|
||||
|
||||
if(!furi_hal_region_is_provisioned()) {
|
||||
subghz_dialog_message_show_only_rx(subghz);
|
||||
subghz_free(subghz);
|
||||
return 1;
|
||||
}
|
||||
|
||||
//Load database
|
||||
bool load_database = subghz_environment_load_keystore(
|
||||
subghz->txrx->environment, EXT_PATH("subghz/assets/keeloq_mfcodes"));
|
||||
subghz_environment_load_keystore(
|
||||
subghz->txrx->environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user"));
|
||||
// Check argument and run corresponding scene
|
||||
if(p && strlen(p)) {
|
||||
uint32_t rpc_ctx = 0;
|
||||
if(sscanf(p, "RPC %lX", &rpc_ctx) == 1) {
|
||||
subghz->rpc_ctx = (void*)rpc_ctx;
|
||||
rpc_system_app_set_callback(subghz->rpc_ctx, subghz_rpc_command_callback, subghz);
|
||||
rpc_system_app_send_started(subghz->rpc_ctx);
|
||||
view_dispatcher_attach_to_gui(
|
||||
subghz->view_dispatcher, subghz->gui, ViewDispatcherTypeDesktop);
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneRpc);
|
||||
} else {
|
||||
view_dispatcher_attach_to_gui(
|
||||
subghz->view_dispatcher, subghz->gui, ViewDispatcherTypeFullscreen);
|
||||
if(subghz_key_load(subghz, p, true)) {
|
||||
string_set_str(subghz->file_path, p);
|
||||
|
||||
if((!strcmp(subghz->txrx->decoder_result->protocol->name, "RAW"))) {
|
||||
//Load Raw TX
|
||||
subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad;
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReadRAW);
|
||||
} else {
|
||||
//Load transmitter TX
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTransmitter);
|
||||
}
|
||||
} else {
|
||||
//exit app
|
||||
scene_manager_stop(subghz->scene_manager);
|
||||
view_dispatcher_stop(subghz->view_dispatcher);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
view_dispatcher_attach_to_gui(
|
||||
subghz->view_dispatcher, subghz->gui, ViewDispatcherTypeFullscreen);
|
||||
string_set_str(subghz->file_path, SUBGHZ_APP_FOLDER);
|
||||
if(load_database) {
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneStart);
|
||||
} else {
|
||||
scene_manager_set_scene_state(
|
||||
subghz->scene_manager, SubGhzSceneShowError, SubGhzCustomEventManagerSet);
|
||||
string_set_str(
|
||||
subghz->error_str,
|
||||
"No SD card or\ndatabase found.\nSome app function\nmay be reduced.");
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
|
||||
}
|
||||
}
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
view_dispatcher_run(subghz->view_dispatcher);
|
||||
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
|
||||
subghz_free(subghz);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
typedef struct SubGhz SubGhz;
|
||||
@@ -0,0 +1,868 @@
|
||||
#include "subghz_cli.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <stream_buffer.h>
|
||||
|
||||
#include <lib/toolbox/args.h>
|
||||
#include <lib/subghz/subghz_keystore.h>
|
||||
|
||||
#include <lib/subghz/receiver.h>
|
||||
#include <lib/subghz/transmitter.h>
|
||||
#include <lib/subghz/subghz_file_encoder_worker.h>
|
||||
|
||||
#include "helpers/subghz_chat.h"
|
||||
|
||||
#include <notification/notification_messages.h>
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
|
||||
#include <flipper.pb.h>
|
||||
#include <pb_decode.h>
|
||||
|
||||
#define SUBGHZ_FREQUENCY_RANGE_STR \
|
||||
"299999755...348000000 or 386999938...464000000 or 778999847...928000000"
|
||||
|
||||
#define SUBGHZ_REGION_FILENAME "/int/.region_data"
|
||||
|
||||
void subghz_cli_command_tx_carrier(Cli* cli, string_t args, void* context) {
|
||||
UNUSED(context);
|
||||
uint32_t frequency = 433920000;
|
||||
|
||||
if(string_size(args)) {
|
||||
int ret = sscanf(string_get_cstr(args), "%lu", &frequency);
|
||||
if(ret != 1) {
|
||||
printf("sscanf returned %d, frequency: %lu\r\n", ret, frequency);
|
||||
cli_print_usage("subghz tx_carrier", "<Frequency: in Hz>", string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
frequency);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_write(&gpio_cc1101_g0, true);
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
if(furi_hal_subghz_tx()) {
|
||||
printf("Transmitting at frequency %lu Hz\r\n", frequency);
|
||||
printf("Press CTRL+C to stop\r\n");
|
||||
while(!cli_cmd_interrupt_received(cli)) {
|
||||
furi_delay_ms(250);
|
||||
}
|
||||
} else {
|
||||
printf("This frequency can only be used for RX in your region\r\n");
|
||||
}
|
||||
|
||||
furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate);
|
||||
furi_hal_subghz_sleep();
|
||||
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
}
|
||||
|
||||
void subghz_cli_command_rx_carrier(Cli* cli, string_t args, void* context) {
|
||||
UNUSED(context);
|
||||
uint32_t frequency = 433920000;
|
||||
|
||||
if(string_size(args)) {
|
||||
int ret = sscanf(string_get_cstr(args), "%lu", &frequency);
|
||||
if(ret != 1) {
|
||||
printf("sscanf returned %d, frequency: %lu\r\n", ret, frequency);
|
||||
cli_print_usage("subghz rx_carrier", "<Frequency: in Hz>", string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
frequency);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
printf("Receiving at frequency %lu Hz\r\n", frequency);
|
||||
printf("Press CTRL+C to stop\r\n");
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
furi_hal_subghz_rx();
|
||||
|
||||
while(!cli_cmd_interrupt_received(cli)) {
|
||||
furi_delay_ms(250);
|
||||
printf("RSSI: %03.1fdbm\r", (double)furi_hal_subghz_get_rssi());
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
|
||||
furi_hal_subghz_set_path(FuriHalSubGhzPathIsolate);
|
||||
furi_hal_subghz_sleep();
|
||||
}
|
||||
|
||||
void subghz_cli_command_tx(Cli* cli, string_t args, void* context) {
|
||||
UNUSED(context);
|
||||
uint32_t frequency = 433920000;
|
||||
uint32_t key = 0x0074BADE;
|
||||
uint32_t repeat = 10;
|
||||
uint32_t te = 403;
|
||||
|
||||
if(string_size(args)) {
|
||||
int ret = sscanf(string_get_cstr(args), "%lx %lu %lu %lu", &key, &frequency, &te, &repeat);
|
||||
if(ret != 4) {
|
||||
printf(
|
||||
"sscanf returned %d, key: %lx, frequency: %lu, te:%lu, repeat: %lu\r\n",
|
||||
ret,
|
||||
key,
|
||||
frequency,
|
||||
te,
|
||||
repeat);
|
||||
cli_print_usage(
|
||||
"subghz tx",
|
||||
"<3 Byte Key: in hex> <Frequency: in Hz> <Te us> <Repeat count>",
|
||||
string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
frequency);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
printf(
|
||||
"Transmitting at %lu, key %lx, te %lu, repeat %lu. Press CTRL+C to stop\r\n",
|
||||
frequency,
|
||||
key,
|
||||
te,
|
||||
repeat);
|
||||
|
||||
string_t flipper_format_string;
|
||||
string_init_printf(
|
||||
flipper_format_string,
|
||||
"Protocol: Princeton\n"
|
||||
"Bit: 24\n"
|
||||
"Key: 00 00 00 00 00 %02X %02X %02X\n"
|
||||
"TE: %d\n"
|
||||
"Repeat: %d\n",
|
||||
(uint8_t)((key >> 16) & 0xFF),
|
||||
(uint8_t)((key >> 8) & 0xFF),
|
||||
(uint8_t)(key & 0xFF),
|
||||
te,
|
||||
repeat);
|
||||
FlipperFormat* flipper_format = flipper_format_string_alloc();
|
||||
Stream* stream = flipper_format_get_raw_stream(flipper_format);
|
||||
stream_clean(stream);
|
||||
stream_write_cstring(stream, string_get_cstr(flipper_format_string));
|
||||
|
||||
SubGhzEnvironment* environment = subghz_environment_alloc();
|
||||
|
||||
SubGhzTransmitter* transmitter = subghz_transmitter_alloc_init(environment, "Princeton");
|
||||
subghz_transmitter_deserialize(transmitter, flipper_format);
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
furi_hal_subghz_start_async_tx(subghz_transmitter_yield, transmitter);
|
||||
|
||||
while(!(furi_hal_subghz_is_async_tx_complete() || cli_cmd_interrupt_received(cli))) {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
furi_delay_ms(333);
|
||||
}
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
furi_hal_subghz_sleep();
|
||||
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
|
||||
flipper_format_free(flipper_format);
|
||||
subghz_transmitter_free(transmitter);
|
||||
subghz_environment_free(environment);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
volatile bool overrun;
|
||||
StreamBufferHandle_t stream;
|
||||
size_t packet_count;
|
||||
} SubGhzCliCommandRx;
|
||||
|
||||
static void subghz_cli_command_rx_capture_callback(bool level, uint32_t duration, void* context) {
|
||||
SubGhzCliCommandRx* instance = context;
|
||||
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
LevelDuration level_duration = level_duration_make(level, duration);
|
||||
if(instance->overrun) {
|
||||
instance->overrun = false;
|
||||
level_duration = level_duration_reset();
|
||||
}
|
||||
size_t ret = xStreamBufferSendFromISR(
|
||||
instance->stream, &level_duration, sizeof(LevelDuration), &xHigherPriorityTaskWoken);
|
||||
if(sizeof(LevelDuration) != ret) instance->overrun = true;
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
static void subghz_cli_command_rx_callback(
|
||||
SubGhzReceiver* receiver,
|
||||
SubGhzProtocolDecoderBase* decoder_base,
|
||||
void* context) {
|
||||
SubGhzCliCommandRx* instance = context;
|
||||
instance->packet_count++;
|
||||
|
||||
string_t text;
|
||||
string_init(text);
|
||||
subghz_protocol_decoder_base_get_string(decoder_base, text);
|
||||
subghz_receiver_reset(receiver);
|
||||
printf("%s", string_get_cstr(text));
|
||||
string_clear(text);
|
||||
}
|
||||
|
||||
void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
|
||||
UNUSED(context);
|
||||
uint32_t frequency = 433920000;
|
||||
|
||||
if(string_size(args)) {
|
||||
int ret = sscanf(string_get_cstr(args), "%lu", &frequency);
|
||||
if(ret != 1) {
|
||||
printf("sscanf returned %d, frequency: %lu\r\n", ret, frequency);
|
||||
cli_print_usage("subghz rx", "<Frequency: in Hz>", string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
frequency);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Allocate context and buffers
|
||||
SubGhzCliCommandRx* instance = malloc(sizeof(SubGhzCliCommandRx));
|
||||
instance->stream = xStreamBufferCreate(sizeof(LevelDuration) * 1024, sizeof(LevelDuration));
|
||||
furi_check(instance->stream);
|
||||
|
||||
SubGhzEnvironment* environment = subghz_environment_alloc();
|
||||
subghz_environment_load_keystore(environment, EXT_PATH("subghz/assets/keeloq_mfcodes"));
|
||||
subghz_environment_load_keystore(environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user"));
|
||||
subghz_environment_set_came_atomo_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/came_atomo"));
|
||||
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/nice_flor_s"));
|
||||
|
||||
SubGhzReceiver* receiver = subghz_receiver_alloc_init(environment);
|
||||
subghz_receiver_set_filter(receiver, SubGhzProtocolFlag_Decodable);
|
||||
subghz_receiver_set_rx_callback(receiver, subghz_cli_command_rx_callback, instance);
|
||||
|
||||
// Configure radio
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
// Prepare and start RX
|
||||
furi_hal_subghz_start_async_rx(subghz_cli_command_rx_capture_callback, instance);
|
||||
|
||||
// Wait for packets to arrive
|
||||
printf("Listening at %lu. Press CTRL+C to stop\r\n", frequency);
|
||||
LevelDuration level_duration;
|
||||
while(!cli_cmd_interrupt_received(cli)) {
|
||||
int ret =
|
||||
xStreamBufferReceive(instance->stream, &level_duration, sizeof(LevelDuration), 10);
|
||||
if(ret == sizeof(LevelDuration)) {
|
||||
if(level_duration_is_reset(level_duration)) {
|
||||
printf(".");
|
||||
subghz_receiver_reset(receiver);
|
||||
} else {
|
||||
bool level = level_duration_get_level(level_duration);
|
||||
uint32_t duration = level_duration_get_duration(level_duration);
|
||||
subghz_receiver_decode(receiver, level, duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shutdown radio
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
furi_hal_subghz_sleep();
|
||||
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
|
||||
printf("\r\nPackets recieved %u\r\n", instance->packet_count);
|
||||
|
||||
// Cleanup
|
||||
subghz_receiver_free(receiver);
|
||||
subghz_environment_free(environment);
|
||||
vStreamBufferDelete(instance->stream);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
void subghz_cli_command_decode_raw(Cli* cli, string_t args, void* context) {
|
||||
UNUSED(context);
|
||||
string_t file_name;
|
||||
string_init(file_name);
|
||||
string_set_str(file_name, ANY_PATH("subghz/test.sub"));
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
uint32_t temp_data32;
|
||||
bool check_file = false;
|
||||
|
||||
do {
|
||||
if(string_size(args)) {
|
||||
if(!args_read_string_and_trim(args, file_name)) {
|
||||
cli_print_usage(
|
||||
"subghz decode_raw", "<file_name: path_RAW_file>", string_get_cstr(args));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!flipper_format_file_open_existing(fff_data_file, string_get_cstr(file_name))) {
|
||||
printf(
|
||||
"subghz decode_raw \033[0;31mError open file\033[0m %s\r\n",
|
||||
string_get_cstr(file_name));
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
|
||||
printf("subghz decode_raw \033[0;31mMissing or incorrect header\033[0m\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!strcmp(string_get_cstr(temp_str), SUBGHZ_RAW_FILE_TYPE) &&
|
||||
temp_data32 == SUBGHZ_KEY_FILE_VERSION) {
|
||||
} else {
|
||||
printf("subghz decode_raw \033[0;31mType or version mismatch\033[0m\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
check_file = true;
|
||||
} while(false);
|
||||
|
||||
string_clear(temp_str);
|
||||
flipper_format_free(fff_data_file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
if(check_file) {
|
||||
// Allocate context
|
||||
SubGhzCliCommandRx* instance = malloc(sizeof(SubGhzCliCommandRx));
|
||||
|
||||
SubGhzEnvironment* environment = subghz_environment_alloc();
|
||||
if(subghz_environment_load_keystore(
|
||||
environment, EXT_PATH("subghz/assets/keeloq_mfcodes"))) {
|
||||
printf("SubGhz decode_raw: Load_keystore keeloq_mfcodes \033[0;32mOK\033[0m\r\n");
|
||||
} else {
|
||||
printf("SubGhz decode_raw: Load_keystore keeloq_mfcodes \033[0;31mERROR\033[0m\r\n");
|
||||
}
|
||||
if(subghz_environment_load_keystore(
|
||||
environment, EXT_PATH("subghz/assets/keeloq_mfcodes_user"))) {
|
||||
printf("SubGhz decode_raw: Load_keystore keeloq_mfcodes_user \033[0;32mOK\033[0m\r\n");
|
||||
} else {
|
||||
printf(
|
||||
"SubGhz decode_raw: Load_keystore keeloq_mfcodes_user \033[0;31mERROR\033[0m\r\n");
|
||||
}
|
||||
subghz_environment_set_came_atomo_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/came_atomo"));
|
||||
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||
environment, EXT_PATH("subghz/assets/nice_flor_s"));
|
||||
|
||||
SubGhzReceiver* receiver = subghz_receiver_alloc_init(environment);
|
||||
subghz_receiver_set_filter(receiver, SubGhzProtocolFlag_Decodable);
|
||||
subghz_receiver_set_rx_callback(receiver, subghz_cli_command_rx_callback, instance);
|
||||
|
||||
SubGhzFileEncoderWorker* file_worker_encoder = subghz_file_encoder_worker_alloc();
|
||||
if(subghz_file_encoder_worker_start(file_worker_encoder, string_get_cstr(file_name))) {
|
||||
//the worker needs a file in order to open and read part of the file
|
||||
furi_delay_ms(100);
|
||||
}
|
||||
|
||||
printf(
|
||||
"Listening at \033[0;33m%s\033[0m.\r\n\r\nPress CTRL+C to stop\r\n\r\n",
|
||||
string_get_cstr(file_name));
|
||||
|
||||
LevelDuration level_duration;
|
||||
while(!cli_cmd_interrupt_received(cli)) {
|
||||
furi_delay_us(500); //you need to have time to read from the file from the SD card
|
||||
level_duration = subghz_file_encoder_worker_get_level_duration(file_worker_encoder);
|
||||
if(!level_duration_is_reset(level_duration)) {
|
||||
bool level = level_duration_get_level(level_duration);
|
||||
uint32_t duration = level_duration_get_duration(level_duration);
|
||||
subghz_receiver_decode(receiver, level, duration);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\r\nPackets recieved \033[0;32m%u\033[0m\r\n", instance->packet_count);
|
||||
|
||||
// Cleanup
|
||||
subghz_receiver_free(receiver);
|
||||
subghz_environment_free(environment);
|
||||
|
||||
if(subghz_file_encoder_worker_is_running(file_worker_encoder)) {
|
||||
subghz_file_encoder_worker_stop(file_worker_encoder);
|
||||
}
|
||||
subghz_file_encoder_worker_free(file_worker_encoder);
|
||||
free(instance);
|
||||
}
|
||||
string_clear(file_name);
|
||||
}
|
||||
|
||||
static void subghz_cli_command_print_usage() {
|
||||
printf("Usage:\r\n");
|
||||
printf("subghz <cmd> <args>\r\n");
|
||||
printf("Cmd list:\r\n");
|
||||
|
||||
printf("\tchat <frequency:in Hz>\t - Chat with other Flippers\r\n");
|
||||
printf(
|
||||
"\ttx <3 byte Key: in hex> <frequency: in Hz> <te: us> <repeat: count>\t - Transmitting key\r\n");
|
||||
printf("\trx <frequency:in Hz>\t - Reception key\r\n");
|
||||
printf("\tdecode_raw <file_name: path_RAW_file>\t - Testing\r\n");
|
||||
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||
printf("\r\n");
|
||||
printf(" debug cmd:\r\n");
|
||||
printf("\ttx_carrier <frequency:in Hz>\t - Transmit carrier\r\n");
|
||||
printf("\trx_carrier <frequency:in Hz>\t - Receiv carrier\r\n");
|
||||
printf(
|
||||
"\tencrypt_keeloq <path_decrypted_file> <path_encrypted_file> <IV:16 bytes in hex>\t - Encrypt keeloq manufacture keys\r\n");
|
||||
printf(
|
||||
"\tencrypt_raw <path_decrypted_file> <path_encrypted_file> <IV:16 bytes in hex>\t - Encrypt RAW data\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void subghz_cli_command_encrypt_keeloq(Cli* cli, string_t args) {
|
||||
UNUSED(cli);
|
||||
uint8_t iv[16];
|
||||
|
||||
string_t source;
|
||||
string_t destination;
|
||||
string_init(source);
|
||||
string_init(destination);
|
||||
|
||||
SubGhzKeystore* keystore = subghz_keystore_alloc();
|
||||
|
||||
do {
|
||||
if(!args_read_string_and_trim(args, source)) {
|
||||
subghz_cli_command_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(!args_read_string_and_trim(args, destination)) {
|
||||
subghz_cli_command_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(!args_read_hex_bytes(args, iv, 16)) {
|
||||
subghz_cli_command_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(!subghz_keystore_load(keystore, string_get_cstr(source))) {
|
||||
printf("Failed to load Keystore");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!subghz_keystore_save(keystore, string_get_cstr(destination), iv)) {
|
||||
printf("Failed to save Keystore");
|
||||
break;
|
||||
}
|
||||
} while(false);
|
||||
|
||||
subghz_keystore_free(keystore);
|
||||
string_clear(destination);
|
||||
string_clear(source);
|
||||
}
|
||||
|
||||
static void subghz_cli_command_encrypt_raw(Cli* cli, string_t args) {
|
||||
UNUSED(cli);
|
||||
uint8_t iv[16];
|
||||
|
||||
string_t source;
|
||||
string_t destination;
|
||||
string_init(source);
|
||||
string_init(destination);
|
||||
|
||||
do {
|
||||
if(!args_read_string_and_trim(args, source)) {
|
||||
subghz_cli_command_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(!args_read_string_and_trim(args, destination)) {
|
||||
subghz_cli_command_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(!args_read_hex_bytes(args, iv, 16)) {
|
||||
subghz_cli_command_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(!subghz_keystore_raw_encrypted_save(
|
||||
string_get_cstr(source), string_get_cstr(destination), iv)) {
|
||||
printf("Failed to save Keystore");
|
||||
break;
|
||||
}
|
||||
|
||||
} while(false);
|
||||
|
||||
string_clear(destination);
|
||||
string_clear(source);
|
||||
}
|
||||
|
||||
static void subghz_cli_command_chat(Cli* cli, string_t args) {
|
||||
uint32_t frequency = 433920000;
|
||||
|
||||
if(string_size(args)) {
|
||||
int ret = sscanf(string_get_cstr(args), "%lu", &frequency);
|
||||
if(ret != 1) {
|
||||
printf("sscanf returned %d, frequency: %lu\r\n", ret, frequency);
|
||||
cli_print_usage("subghz chat", "<Frequency: in Hz>", string_get_cstr(args));
|
||||
return;
|
||||
}
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
printf(
|
||||
"Frequency must be in " SUBGHZ_FREQUENCY_RANGE_STR " range, not %lu\r\n",
|
||||
frequency);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(!furi_hal_region_is_frequency_allowed(frequency)) {
|
||||
printf(
|
||||
"In your region, only reception on this frequency (%lu) is allowed,\r\n"
|
||||
"the actual operation of the application is not possible\r\n ",
|
||||
frequency);
|
||||
return;
|
||||
}
|
||||
|
||||
SubGhzChatWorker* subghz_chat = subghz_chat_worker_alloc(cli);
|
||||
if(!subghz_chat_worker_start(subghz_chat, frequency)) {
|
||||
printf("Startup error SubGhzChatWorker\r\n");
|
||||
|
||||
if(subghz_chat_worker_is_running(subghz_chat)) {
|
||||
subghz_chat_worker_stop(subghz_chat);
|
||||
subghz_chat_worker_free(subghz_chat);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Receiving at frequency %lu Hz\r\n", frequency);
|
||||
printf("Press CTRL+C to stop\r\n");
|
||||
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
size_t message_max_len = 64;
|
||||
uint8_t message[64] = {0};
|
||||
string_t input;
|
||||
string_init(input);
|
||||
string_t name;
|
||||
string_init(name);
|
||||
string_t output;
|
||||
string_init(output);
|
||||
string_t sysmsg;
|
||||
string_init(sysmsg);
|
||||
bool exit = false;
|
||||
SubGhzChatEvent chat_event;
|
||||
|
||||
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
|
||||
|
||||
string_printf(name, "\033[0;33m%s\033[0m: ", furi_hal_version_get_name_ptr());
|
||||
string_set(input, name);
|
||||
printf("%s", string_get_cstr(input));
|
||||
fflush(stdout);
|
||||
|
||||
while(!exit) {
|
||||
chat_event = subghz_chat_worker_get_event_chat(subghz_chat);
|
||||
switch(chat_event.event) {
|
||||
case SubGhzChatEventInputData:
|
||||
if(chat_event.c == CliSymbolAsciiETX) {
|
||||
printf("\r\n");
|
||||
chat_event.event = SubGhzChatEventUserExit;
|
||||
subghz_chat_worker_put_event_chat(subghz_chat, &chat_event);
|
||||
break;
|
||||
} else if(
|
||||
(chat_event.c == CliSymbolAsciiBackspace) || (chat_event.c == CliSymbolAsciiDel)) {
|
||||
size_t len = string_length_u(input);
|
||||
if(len > string_length_u(name)) {
|
||||
printf("%s", "\e[D\e[1P");
|
||||
fflush(stdout);
|
||||
//delete 1 char UTF
|
||||
const char* str = string_get_cstr(input);
|
||||
size_t size = 0;
|
||||
m_str1ng_utf8_state_e s = M_STRING_UTF8_STARTING;
|
||||
string_unicode_t u = 0;
|
||||
string_reset(sysmsg);
|
||||
while(*str) {
|
||||
m_str1ng_utf8_decode(*str, &s, &u);
|
||||
if((s == M_STRING_UTF8_ERROR) || s == M_STRING_UTF8_STARTING) {
|
||||
string_push_u(sysmsg, u);
|
||||
if(++size >= len - 1) break;
|
||||
s = M_STRING_UTF8_STARTING;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
string_set(input, sysmsg);
|
||||
}
|
||||
} else if(chat_event.c == CliSymbolAsciiCR) {
|
||||
printf("\r\n");
|
||||
string_push_back(input, '\r');
|
||||
string_push_back(input, '\n');
|
||||
while(!subghz_chat_worker_write(
|
||||
subghz_chat,
|
||||
(uint8_t*)string_get_cstr(input),
|
||||
strlen(string_get_cstr(input)))) {
|
||||
furi_delay_ms(10);
|
||||
}
|
||||
|
||||
string_printf(input, "%s", string_get_cstr(name));
|
||||
printf("%s", string_get_cstr(input));
|
||||
fflush(stdout);
|
||||
} else if(chat_event.c == CliSymbolAsciiLF) {
|
||||
//cut out the symbol \n
|
||||
} else {
|
||||
putc(chat_event.c, stdout);
|
||||
fflush(stdout);
|
||||
string_push_back(input, chat_event.c);
|
||||
break;
|
||||
case SubGhzChatEventRXData:
|
||||
do {
|
||||
memset(message, 0x00, message_max_len);
|
||||
size_t len = subghz_chat_worker_read(subghz_chat, message, message_max_len);
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
string_push_back(output, message[i]);
|
||||
if(message[i] == '\n') {
|
||||
printf("\r");
|
||||
for(uint8_t i = 0; i < 80; i++) {
|
||||
printf(" ");
|
||||
}
|
||||
printf("\r %s", string_get_cstr(output));
|
||||
printf("%s", string_get_cstr(input));
|
||||
fflush(stdout);
|
||||
string_reset(output);
|
||||
}
|
||||
}
|
||||
} while(subghz_chat_worker_available(subghz_chat));
|
||||
break;
|
||||
case SubGhzChatEventNewMessage:
|
||||
notification_message(notification, &sequence_single_vibro);
|
||||
break;
|
||||
case SubGhzChatEventUserEntrance:
|
||||
string_printf(
|
||||
sysmsg,
|
||||
"\033[0;34m%s joined chat.\033[0m\r\n",
|
||||
furi_hal_version_get_name_ptr());
|
||||
subghz_chat_worker_write(
|
||||
subghz_chat,
|
||||
(uint8_t*)string_get_cstr(sysmsg),
|
||||
strlen(string_get_cstr(sysmsg)));
|
||||
break;
|
||||
case SubGhzChatEventUserExit:
|
||||
string_printf(
|
||||
sysmsg, "\033[0;31m%s left chat.\033[0m\r\n", furi_hal_version_get_name_ptr());
|
||||
subghz_chat_worker_write(
|
||||
subghz_chat,
|
||||
(uint8_t*)string_get_cstr(sysmsg),
|
||||
strlen(string_get_cstr(sysmsg)));
|
||||
furi_delay_ms(10);
|
||||
exit = true;
|
||||
break;
|
||||
default:
|
||||
FURI_LOG_W("SubGhzChat", "Error event");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!cli_is_connected(cli)) {
|
||||
printf("\r\n");
|
||||
chat_event.event = SubGhzChatEventUserExit;
|
||||
subghz_chat_worker_put_event_chat(subghz_chat, &chat_event);
|
||||
}
|
||||
}
|
||||
|
||||
string_clear(input);
|
||||
string_clear(name);
|
||||
string_clear(output);
|
||||
string_clear(sysmsg);
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
|
||||
if(subghz_chat_worker_is_running(subghz_chat)) {
|
||||
subghz_chat_worker_stop(subghz_chat);
|
||||
subghz_chat_worker_free(subghz_chat);
|
||||
}
|
||||
printf("\r\nExit chat\r\n");
|
||||
}
|
||||
|
||||
static void subghz_cli_command(Cli* cli, string_t args, void* context) {
|
||||
string_t cmd;
|
||||
string_init(cmd);
|
||||
|
||||
do {
|
||||
if(!args_read_string_and_trim(args, cmd)) {
|
||||
subghz_cli_command_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "chat") == 0) {
|
||||
subghz_cli_command_chat(cli, args);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "tx") == 0) {
|
||||
subghz_cli_command_tx(cli, args, context);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "rx") == 0) {
|
||||
subghz_cli_command_rx(cli, args, context);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "decode_raw") == 0) {
|
||||
subghz_cli_command_decode_raw(cli, args, context);
|
||||
break;
|
||||
}
|
||||
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||
if(string_cmp_str(cmd, "encrypt_keeloq") == 0) {
|
||||
subghz_cli_command_encrypt_keeloq(cli, args);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "encrypt_raw") == 0) {
|
||||
subghz_cli_command_encrypt_raw(cli, args);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "tx_carrier") == 0) {
|
||||
subghz_cli_command_tx_carrier(cli, args, context);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "rx_carrier") == 0) {
|
||||
subghz_cli_command_rx_carrier(cli, args, context);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
subghz_cli_command_print_usage();
|
||||
} while(false);
|
||||
|
||||
string_clear(cmd);
|
||||
}
|
||||
|
||||
static bool
|
||||
subghz_on_system_start_istream_read(pb_istream_t* istream, pb_byte_t* buf, size_t count) {
|
||||
File* file = istream->state;
|
||||
uint16_t ret = storage_file_read(file, buf, count);
|
||||
return (count == ret);
|
||||
}
|
||||
|
||||
static bool subghz_on_system_start_istream_decode_band(
|
||||
pb_istream_t* stream,
|
||||
const pb_field_t* field,
|
||||
void** arg) {
|
||||
(void)field;
|
||||
FuriHalRegion* region = *arg;
|
||||
|
||||
PB_Region_Band band = {0};
|
||||
if(!pb_decode(stream, PB_Region_Band_fields, &band)) {
|
||||
FURI_LOG_E("SubGhzOnStart", "PB Region band decode error: %s", PB_GET_ERROR(stream));
|
||||
return false;
|
||||
}
|
||||
|
||||
region->bands_count += 1;
|
||||
region =
|
||||
realloc(region, sizeof(FuriHalRegion) + sizeof(FuriHalRegionBand) * region->bands_count);
|
||||
size_t pos = region->bands_count - 1;
|
||||
region->bands[pos].start = band.start;
|
||||
region->bands[pos].end = band.end;
|
||||
region->bands[pos].power_limit = band.power_limit;
|
||||
region->bands[pos].duty_cycle = band.duty_cycle;
|
||||
*arg = region;
|
||||
|
||||
FURI_LOG_I(
|
||||
"SubGhzOnStart",
|
||||
"Add allowed band: start %dHz, stop %dHz, power_limit %ddBm, duty_cycle %d%%",
|
||||
band.start,
|
||||
band.end,
|
||||
band.power_limit,
|
||||
band.duty_cycle);
|
||||
return true;
|
||||
}
|
||||
|
||||
void subghz_on_system_start() {
|
||||
#ifdef SRV_CLI
|
||||
Cli* cli = furi_record_open(RECORD_CLI);
|
||||
|
||||
cli_add_command(cli, "subghz", CliCommandFlagDefault, subghz_cli_command, NULL);
|
||||
|
||||
furi_record_close(RECORD_CLI);
|
||||
#else
|
||||
UNUSED(subghz_cli_command);
|
||||
#endif
|
||||
|
||||
#ifdef SRV_STORAGE
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(storage);
|
||||
FileInfo fileinfo = {0};
|
||||
PB_Region pb_region = {0};
|
||||
pb_region.bands.funcs.decode = subghz_on_system_start_istream_decode_band;
|
||||
|
||||
do {
|
||||
if(storage_common_stat(storage, SUBGHZ_REGION_FILENAME, &fileinfo) != FSE_OK ||
|
||||
fileinfo.size == 0) {
|
||||
FURI_LOG_W("SubGhzOnStart", "Region data is missing or empty");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!storage_file_open(file, SUBGHZ_REGION_FILENAME, FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
FURI_LOG_E("SubGhzOnStart", "Unable to open region data");
|
||||
break;
|
||||
}
|
||||
|
||||
pb_istream_t istream = {
|
||||
.callback = subghz_on_system_start_istream_read,
|
||||
.state = file,
|
||||
.errmsg = NULL,
|
||||
.bytes_left = fileinfo.size,
|
||||
};
|
||||
|
||||
pb_region.bands.arg = malloc(sizeof(FuriHalRegion));
|
||||
if(!pb_decode(&istream, PB_Region_fields, &pb_region)) {
|
||||
FURI_LOG_E("SubGhzOnStart", "Invalid region data");
|
||||
free(pb_region.bands.arg);
|
||||
break;
|
||||
}
|
||||
|
||||
FuriHalRegion* region = pb_region.bands.arg;
|
||||
memcpy(
|
||||
region->country_code,
|
||||
pb_region.country_code->bytes,
|
||||
pb_region.country_code->size < 4 ? pb_region.country_code->size : 3);
|
||||
furi_hal_region_set(region);
|
||||
} while(0);
|
||||
|
||||
pb_release(PB_Region_fields, &pb_region);
|
||||
storage_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
#else
|
||||
UNUSED(subghz_cli_command);
|
||||
UNUSED(subghz_on_system_start_istream_decode_band);
|
||||
UNUSED(subghz_on_system_start_istream_read);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <cli/cli.h>
|
||||
|
||||
void subghz_on_system_start();
|
||||
@@ -0,0 +1,230 @@
|
||||
#include "subghz_history.h"
|
||||
#include <lib/subghz/receiver.h>
|
||||
#include <lib/subghz/protocols/came.h>
|
||||
|
||||
#include <furi.h>
|
||||
#include <m-string.h>
|
||||
|
||||
#define SUBGHZ_HISTORY_MAX 50
|
||||
#define TAG "SubGhzHistory"
|
||||
|
||||
typedef struct {
|
||||
string_t item_str;
|
||||
FlipperFormat* flipper_string;
|
||||
uint8_t type;
|
||||
SubGhzPresetDefinition* preset;
|
||||
} SubGhzHistoryItem;
|
||||
|
||||
ARRAY_DEF(SubGhzHistoryItemArray, SubGhzHistoryItem, M_POD_OPLIST)
|
||||
|
||||
#define M_OPL_SubGhzHistoryItemArray_t() ARRAY_OPLIST(SubGhzHistoryItemArray, M_POD_OPLIST)
|
||||
|
||||
typedef struct {
|
||||
SubGhzHistoryItemArray_t data;
|
||||
} SubGhzHistoryStruct;
|
||||
|
||||
struct SubGhzHistory {
|
||||
uint32_t last_update_timestamp;
|
||||
uint16_t last_index_write;
|
||||
uint8_t code_last_hash_data;
|
||||
string_t tmp_string;
|
||||
SubGhzHistoryStruct* history;
|
||||
};
|
||||
|
||||
SubGhzHistory* subghz_history_alloc(void) {
|
||||
SubGhzHistory* instance = malloc(sizeof(SubGhzHistory));
|
||||
string_init(instance->tmp_string);
|
||||
instance->history = malloc(sizeof(SubGhzHistoryStruct));
|
||||
SubGhzHistoryItemArray_init(instance->history->data);
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_history_free(SubGhzHistory* instance) {
|
||||
furi_assert(instance);
|
||||
string_clear(instance->tmp_string);
|
||||
for
|
||||
M_EACH(item, instance->history->data, SubGhzHistoryItemArray_t) {
|
||||
string_clear(item->item_str);
|
||||
string_clear(item->preset->name);
|
||||
free(item->preset);
|
||||
flipper_format_free(item->flipper_string);
|
||||
item->type = 0;
|
||||
}
|
||||
SubGhzHistoryItemArray_clear(instance->history->data);
|
||||
free(instance->history);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
uint32_t subghz_history_get_frequency(SubGhzHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
|
||||
return item->preset->frequency;
|
||||
}
|
||||
|
||||
SubGhzPresetDefinition* subghz_history_get_preset_def(SubGhzHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
|
||||
return item->preset;
|
||||
}
|
||||
|
||||
const char* subghz_history_get_preset(SubGhzHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
|
||||
return string_get_cstr(item->preset->name);
|
||||
}
|
||||
|
||||
void subghz_history_reset(SubGhzHistory* instance) {
|
||||
furi_assert(instance);
|
||||
string_reset(instance->tmp_string);
|
||||
for
|
||||
M_EACH(item, instance->history->data, SubGhzHistoryItemArray_t) {
|
||||
string_clear(item->item_str);
|
||||
string_clear(item->preset->name);
|
||||
free(item->preset);
|
||||
flipper_format_free(item->flipper_string);
|
||||
item->type = 0;
|
||||
}
|
||||
SubGhzHistoryItemArray_reset(instance->history->data);
|
||||
instance->last_index_write = 0;
|
||||
instance->code_last_hash_data = 0;
|
||||
}
|
||||
|
||||
uint16_t subghz_history_get_item(SubGhzHistory* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->last_index_write;
|
||||
}
|
||||
|
||||
uint8_t subghz_history_get_type_protocol(SubGhzHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
|
||||
return item->type;
|
||||
}
|
||||
|
||||
const char* subghz_history_get_protocol_name(SubGhzHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
|
||||
flipper_format_rewind(item->flipper_string);
|
||||
if(!flipper_format_read_string(item->flipper_string, "Protocol", instance->tmp_string)) {
|
||||
FURI_LOG_E(TAG, "Missing Protocol");
|
||||
string_reset(instance->tmp_string);
|
||||
}
|
||||
return string_get_cstr(instance->tmp_string);
|
||||
}
|
||||
|
||||
FlipperFormat* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
|
||||
if(item->flipper_string) {
|
||||
return item->flipper_string;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
bool subghz_history_get_text_space_left(SubGhzHistory* instance, string_t output) {
|
||||
furi_assert(instance);
|
||||
if(instance->last_index_write == SUBGHZ_HISTORY_MAX) {
|
||||
if(output != NULL) string_printf(output, "Memory is FULL");
|
||||
return true;
|
||||
}
|
||||
if(output != NULL)
|
||||
string_printf(output, "%02u/%02u", instance->last_index_write, SUBGHZ_HISTORY_MAX);
|
||||
return false;
|
||||
}
|
||||
|
||||
void subghz_history_get_text_item_menu(SubGhzHistory* instance, string_t output, uint16_t idx) {
|
||||
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
|
||||
string_set(output, item->item_str);
|
||||
}
|
||||
|
||||
bool subghz_history_add_to_history(
|
||||
SubGhzHistory* instance,
|
||||
void* context,
|
||||
SubGhzPresetDefinition* preset) {
|
||||
furi_assert(instance);
|
||||
furi_assert(context);
|
||||
|
||||
if(instance->last_index_write >= SUBGHZ_HISTORY_MAX) return false;
|
||||
|
||||
SubGhzProtocolDecoderBase* decoder_base = context;
|
||||
if((instance->code_last_hash_data ==
|
||||
subghz_protocol_decoder_base_get_hash_data(decoder_base)) &&
|
||||
((furi_get_tick() - instance->last_update_timestamp) < 500)) {
|
||||
instance->last_update_timestamp = furi_get_tick();
|
||||
return false;
|
||||
}
|
||||
|
||||
instance->code_last_hash_data = subghz_protocol_decoder_base_get_hash_data(decoder_base);
|
||||
instance->last_update_timestamp = furi_get_tick();
|
||||
|
||||
string_t text;
|
||||
string_init(text);
|
||||
SubGhzHistoryItem* item = SubGhzHistoryItemArray_push_raw(instance->history->data);
|
||||
item->preset = malloc(sizeof(SubGhzPresetDefinition));
|
||||
item->type = decoder_base->protocol->type;
|
||||
item->preset->frequency = preset->frequency;
|
||||
string_init(item->preset->name);
|
||||
string_set(item->preset->name, preset->name);
|
||||
item->preset->data = preset->data;
|
||||
item->preset->data_size = preset->data_size;
|
||||
|
||||
string_init(item->item_str);
|
||||
item->flipper_string = flipper_format_string_alloc();
|
||||
subghz_protocol_decoder_base_serialize(decoder_base, item->flipper_string, preset);
|
||||
|
||||
do {
|
||||
if(!flipper_format_rewind(item->flipper_string)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_read_string(item->flipper_string, "Protocol", instance->tmp_string)) {
|
||||
FURI_LOG_E(TAG, "Missing Protocol");
|
||||
break;
|
||||
}
|
||||
if(!strcmp(string_get_cstr(instance->tmp_string), "KeeLoq")) {
|
||||
string_set_str(instance->tmp_string, "KL ");
|
||||
if(!flipper_format_read_string(item->flipper_string, "Manufacture", text)) {
|
||||
FURI_LOG_E(TAG, "Missing Protocol");
|
||||
break;
|
||||
}
|
||||
string_cat(instance->tmp_string, text);
|
||||
} else if(!strcmp(string_get_cstr(instance->tmp_string), "Star Line")) {
|
||||
string_set_str(instance->tmp_string, "SL ");
|
||||
if(!flipper_format_read_string(item->flipper_string, "Manufacture", text)) {
|
||||
FURI_LOG_E(TAG, "Missing Protocol");
|
||||
break;
|
||||
}
|
||||
string_cat(instance->tmp_string, text);
|
||||
}
|
||||
if(!flipper_format_rewind(item->flipper_string)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
uint8_t key_data[sizeof(uint64_t)] = {0};
|
||||
if(!flipper_format_read_hex(item->flipper_string, "Key", key_data, sizeof(uint64_t))) {
|
||||
FURI_LOG_E(TAG, "Missing Key");
|
||||
break;
|
||||
}
|
||||
uint64_t data = 0;
|
||||
for(uint8_t i = 0; i < sizeof(uint64_t); i++) {
|
||||
data = (data << 8) | key_data[i];
|
||||
}
|
||||
if(!(uint32_t)(data >> 32)) {
|
||||
string_printf(
|
||||
item->item_str,
|
||||
"%s %lX",
|
||||
string_get_cstr(instance->tmp_string),
|
||||
(uint32_t)(data & 0xFFFFFFFF));
|
||||
} else {
|
||||
string_printf(
|
||||
item->item_str,
|
||||
"%s %lX%08lX",
|
||||
string_get_cstr(instance->tmp_string),
|
||||
(uint32_t)(data >> 32),
|
||||
(uint32_t)(data & 0xFFFFFFFF));
|
||||
}
|
||||
} while(false);
|
||||
|
||||
string_clear(text);
|
||||
instance->last_index_write++;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <math.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
#include "helpers/subghz_types.h"
|
||||
|
||||
typedef struct SubGhzHistory SubGhzHistory;
|
||||
|
||||
/** Allocate SubGhzHistory
|
||||
*
|
||||
* @return SubGhzHistory*
|
||||
*/
|
||||
SubGhzHistory* subghz_history_alloc(void);
|
||||
|
||||
/** Free SubGhzHistory
|
||||
*
|
||||
* @param instance - SubGhzHistory instance
|
||||
*/
|
||||
void subghz_history_free(SubGhzHistory* instance);
|
||||
|
||||
/** Clear history
|
||||
*
|
||||
* @param instance - SubGhzHistory instance
|
||||
*/
|
||||
void subghz_history_reset(SubGhzHistory* instance);
|
||||
|
||||
/** Get frequency to history[idx]
|
||||
*
|
||||
* @param instance - SubGhzHistory instance
|
||||
* @param idx - record index
|
||||
* @return frequency - frequency Hz
|
||||
*/
|
||||
uint32_t subghz_history_get_frequency(SubGhzHistory* instance, uint16_t idx);
|
||||
|
||||
SubGhzPresetDefinition* subghz_history_get_preset_def(SubGhzHistory* instance, uint16_t idx);
|
||||
|
||||
/** Get preset to history[idx]
|
||||
*
|
||||
* @param instance - SubGhzHistory instance
|
||||
* @param idx - record index
|
||||
* @return preset - preset name
|
||||
*/
|
||||
const char* subghz_history_get_preset(SubGhzHistory* instance, uint16_t idx);
|
||||
|
||||
/** Get history index write
|
||||
*
|
||||
* @param instance - SubGhzHistory instance
|
||||
* @return idx - current record index
|
||||
*/
|
||||
uint16_t subghz_history_get_item(SubGhzHistory* instance);
|
||||
|
||||
/** Get type protocol to history[idx]
|
||||
*
|
||||
* @param instance - SubGhzHistory instance
|
||||
* @param idx - record index
|
||||
* @return type - type protocol
|
||||
*/
|
||||
uint8_t subghz_history_get_type_protocol(SubGhzHistory* instance, uint16_t idx);
|
||||
|
||||
/** Get name protocol to history[idx]
|
||||
*
|
||||
* @param instance - SubGhzHistory instance
|
||||
* @param idx - record index
|
||||
* @return name - const char* name protocol
|
||||
*/
|
||||
const char* subghz_history_get_protocol_name(SubGhzHistory* instance, uint16_t idx);
|
||||
|
||||
/** Get string item menu to history[idx]
|
||||
*
|
||||
* @param instance - SubGhzHistory instance
|
||||
* @param output - string_t output
|
||||
* @param idx - record index
|
||||
*/
|
||||
void subghz_history_get_text_item_menu(SubGhzHistory* instance, string_t output, uint16_t idx);
|
||||
|
||||
/** Get string the remaining number of records to history
|
||||
*
|
||||
* @param instance - SubGhzHistory instance
|
||||
* @param output - string_t output
|
||||
* @return bool - is FUUL
|
||||
*/
|
||||
bool subghz_history_get_text_space_left(SubGhzHistory* instance, string_t output);
|
||||
|
||||
/** Add protocol to history
|
||||
*
|
||||
* @param instance - SubGhzHistory instance
|
||||
* @param context - SubGhzProtocolCommon context
|
||||
* @param preset - SubGhzPresetDefinition preset
|
||||
* @return bool;
|
||||
*/
|
||||
bool subghz_history_add_to_history(
|
||||
SubGhzHistory* instance,
|
||||
void* context,
|
||||
SubGhzPresetDefinition* preset);
|
||||
|
||||
/** Get SubGhzProtocolCommonLoad to load into the protocol decoder bin data
|
||||
*
|
||||
* @param instance - SubGhzHistory instance
|
||||
* @param idx - record index
|
||||
* @return SubGhzProtocolCommonLoad*
|
||||
*/
|
||||
FlipperFormat* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx);
|
||||
@@ -0,0 +1,582 @@
|
||||
#include "subghz_i.h"
|
||||
|
||||
#include "assets_icons.h"
|
||||
#include "subghz/types.h"
|
||||
#include <math.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <input/input.h>
|
||||
#include <gui/elements.h>
|
||||
#include <notification/notification.h>
|
||||
#include <notification/notification_messages.h>
|
||||
#include <flipper_format/flipper_format.h>
|
||||
#include "views/receiver.h"
|
||||
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
#include <lib/toolbox/stream/stream.h>
|
||||
#include <lib/subghz/protocols/raw.h>
|
||||
|
||||
#define TAG "SubGhz"
|
||||
|
||||
void subghz_preset_init(
|
||||
void* context,
|
||||
const char* preset_name,
|
||||
uint32_t frequency,
|
||||
uint8_t* preset_data,
|
||||
size_t preset_data_size) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
string_set(subghz->txrx->preset->name, preset_name);
|
||||
subghz->txrx->preset->frequency = frequency;
|
||||
subghz->txrx->preset->data = preset_data;
|
||||
subghz->txrx->preset->data_size = preset_data_size;
|
||||
}
|
||||
|
||||
bool subghz_set_preset(SubGhz* subghz, const char* preset) {
|
||||
if(!strcmp(preset, "FuriHalSubGhzPresetOok270Async")) {
|
||||
string_set(subghz->txrx->preset->name, "AM270");
|
||||
} else if(!strcmp(preset, "FuriHalSubGhzPresetOok650Async")) {
|
||||
string_set(subghz->txrx->preset->name, "AM650");
|
||||
} else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev238Async")) {
|
||||
string_set(subghz->txrx->preset->name, "FM238");
|
||||
} else if(!strcmp(preset, "FuriHalSubGhzPreset2FSKDev476Async")) {
|
||||
string_set(subghz->txrx->preset->name, "FM476");
|
||||
} else if(!strcmp(preset, "FuriHalSubGhzPresetCustom")) {
|
||||
string_set(subghz->txrx->preset->name, "CUSTOM");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Unknown preset");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void subghz_get_frequency_modulation(SubGhz* subghz, string_t frequency, string_t modulation) {
|
||||
furi_assert(subghz);
|
||||
if(frequency != NULL) {
|
||||
string_printf(
|
||||
frequency,
|
||||
"%03ld.%02ld",
|
||||
subghz->txrx->preset->frequency / 1000000 % 1000,
|
||||
subghz->txrx->preset->frequency / 10000 % 100);
|
||||
}
|
||||
if(modulation != NULL) {
|
||||
string_printf(modulation, "%0.2s", string_get_cstr(subghz->txrx->preset->name));
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_begin(SubGhz* subghz, uint8_t* preset_data) {
|
||||
furi_assert(subghz);
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_load_custom_preset(preset_data);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
subghz->txrx->txrx_state = SubGhzTxRxStateIDLE;
|
||||
}
|
||||
|
||||
uint32_t subghz_rx(SubGhz* subghz, uint32_t frequency) {
|
||||
furi_assert(subghz);
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
furi_crash("SubGhz: Incorrect RX frequency.");
|
||||
}
|
||||
furi_assert(
|
||||
subghz->txrx->txrx_state != SubGhzTxRxStateRx &&
|
||||
subghz->txrx->txrx_state != SubGhzTxRxStateSleep);
|
||||
|
||||
furi_hal_subghz_idle();
|
||||
uint32_t value = furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_subghz_flush_rx();
|
||||
furi_hal_subghz_rx();
|
||||
|
||||
furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, subghz->txrx->worker);
|
||||
subghz_worker_start(subghz->txrx->worker);
|
||||
subghz->txrx->txrx_state = SubGhzTxRxStateRx;
|
||||
return value;
|
||||
}
|
||||
|
||||
static bool subghz_tx(SubGhz* subghz, uint32_t frequency) {
|
||||
furi_assert(subghz);
|
||||
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
|
||||
furi_crash("SubGhz: Incorrect TX frequency.");
|
||||
}
|
||||
furi_assert(subghz->txrx->txrx_state != SubGhzTxRxStateSleep);
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_set_frequency_and_path(frequency);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_write(&gpio_cc1101_g0, true);
|
||||
bool ret = furi_hal_subghz_tx();
|
||||
subghz->txrx->txrx_state = SubGhzTxRxStateTx;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void subghz_idle(SubGhz* subghz) {
|
||||
furi_assert(subghz);
|
||||
furi_assert(subghz->txrx->txrx_state != SubGhzTxRxStateSleep);
|
||||
furi_hal_subghz_idle();
|
||||
subghz->txrx->txrx_state = SubGhzTxRxStateIDLE;
|
||||
}
|
||||
|
||||
void subghz_rx_end(SubGhz* subghz) {
|
||||
furi_assert(subghz);
|
||||
furi_assert(subghz->txrx->txrx_state == SubGhzTxRxStateRx);
|
||||
if(subghz_worker_is_running(subghz->txrx->worker)) {
|
||||
subghz_worker_stop(subghz->txrx->worker);
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
}
|
||||
furi_hal_subghz_idle();
|
||||
subghz->txrx->txrx_state = SubGhzTxRxStateIDLE;
|
||||
}
|
||||
|
||||
void subghz_sleep(SubGhz* subghz) {
|
||||
furi_assert(subghz);
|
||||
furi_hal_subghz_sleep();
|
||||
subghz->txrx->txrx_state = SubGhzTxRxStateSleep;
|
||||
}
|
||||
|
||||
bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format) {
|
||||
furi_assert(subghz);
|
||||
|
||||
bool ret = false;
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
uint32_t repeat = 200;
|
||||
do {
|
||||
if(!flipper_format_rewind(flipper_format)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
if(!flipper_format_read_string(flipper_format, "Protocol", temp_str)) {
|
||||
FURI_LOG_E(TAG, "Missing Protocol");
|
||||
break;
|
||||
}
|
||||
//ToDo FIX
|
||||
if(!flipper_format_insert_or_update_uint32(flipper_format, "Repeat", &repeat, 1)) {
|
||||
FURI_LOG_E(TAG, "Unable Repeat");
|
||||
break;
|
||||
}
|
||||
|
||||
subghz->txrx->transmitter =
|
||||
subghz_transmitter_alloc_init(subghz->txrx->environment, string_get_cstr(temp_str));
|
||||
|
||||
if(subghz->txrx->transmitter) {
|
||||
if(subghz_transmitter_deserialize(subghz->txrx->transmitter, flipper_format)) {
|
||||
if(strcmp(string_get_cstr(subghz->txrx->preset->name), "")) {
|
||||
subghz_begin(
|
||||
subghz,
|
||||
subghz_setting_get_preset_data_by_name(
|
||||
subghz->setting, string_get_cstr(subghz->txrx->preset->name)));
|
||||
} else {
|
||||
FURI_LOG_E(
|
||||
TAG,
|
||||
"Unknown name preset \" %s \"",
|
||||
string_get_cstr(subghz->txrx->preset->name));
|
||||
subghz_begin(
|
||||
subghz, subghz_setting_get_preset_data_by_name(subghz->setting, "AM650"));
|
||||
}
|
||||
if(subghz->txrx->preset->frequency) {
|
||||
ret = subghz_tx(subghz, subghz->txrx->preset->frequency);
|
||||
} else {
|
||||
ret = subghz_tx(subghz, 433920000);
|
||||
}
|
||||
if(ret) {
|
||||
//Start TX
|
||||
furi_hal_subghz_start_async_tx(
|
||||
subghz_transmitter_yield, subghz->txrx->transmitter);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!ret) {
|
||||
subghz_transmitter_free(subghz->txrx->transmitter);
|
||||
if(subghz->txrx->txrx_state != SubGhzTxRxStateSleep) {
|
||||
subghz_idle(subghz);
|
||||
}
|
||||
}
|
||||
|
||||
} while(false);
|
||||
string_clear(temp_str);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void subghz_tx_stop(SubGhz* subghz) {
|
||||
furi_assert(subghz);
|
||||
furi_assert(subghz->txrx->txrx_state == SubGhzTxRxStateTx);
|
||||
//Stop TX
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
subghz_transmitter_stop(subghz->txrx->transmitter);
|
||||
subghz_transmitter_free(subghz->txrx->transmitter);
|
||||
|
||||
//if protocol dynamic then we save the last upload
|
||||
if((subghz->txrx->decoder_result->protocol->type == SubGhzProtocolTypeDynamic) &&
|
||||
(subghz_path_is_file(subghz->file_path))) {
|
||||
subghz_save_protocol_to_file(
|
||||
subghz, subghz->txrx->fff_data, string_get_cstr(subghz->file_path));
|
||||
}
|
||||
subghz_idle(subghz);
|
||||
notification_message(subghz->notifications, &sequence_reset_red);
|
||||
}
|
||||
|
||||
void subghz_dialog_message_show_only_rx(SubGhz* subghz) {
|
||||
DialogsApp* dialogs = subghz->dialogs;
|
||||
DialogMessage* message = dialog_message_alloc();
|
||||
|
||||
const char* header_text = "Transmission is blocked";
|
||||
const char* message_text = "Transmission on\nthis frequency is\nrestricted in\nyour region";
|
||||
if(!furi_hal_region_is_provisioned()) {
|
||||
header_text = "Firmware update needed";
|
||||
message_text = "Please update\nfirmware before\nusing this feature\nflipp.dev/upd";
|
||||
}
|
||||
|
||||
dialog_message_set_header(message, header_text, 63, 3, AlignCenter, AlignTop);
|
||||
dialog_message_set_text(message, message_text, 0, 17, AlignLeft, AlignTop);
|
||||
|
||||
dialog_message_set_icon(message, &I_DolphinCommon_56x48, 72, 17);
|
||||
|
||||
dialog_message_show(dialogs, message);
|
||||
dialog_message_free(message);
|
||||
}
|
||||
|
||||
bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) {
|
||||
furi_assert(subghz);
|
||||
furi_assert(file_path);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
|
||||
Stream* fff_data_stream = flipper_format_get_raw_stream(subghz->txrx->fff_data);
|
||||
|
||||
SubGhzLoadKeyState load_key_state = SubGhzLoadKeyStateParseErr;
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
uint32_t temp_data32;
|
||||
|
||||
do {
|
||||
stream_clean(fff_data_stream);
|
||||
if(!flipper_format_file_open_existing(fff_data_file, file_path)) {
|
||||
FURI_LOG_E(TAG, "Error open file %s", file_path);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
|
||||
FURI_LOG_E(TAG, "Missing or incorrect header");
|
||||
break;
|
||||
}
|
||||
|
||||
if(((!strcmp(string_get_cstr(temp_str), SUBGHZ_KEY_FILE_TYPE)) ||
|
||||
(!strcmp(string_get_cstr(temp_str), SUBGHZ_RAW_FILE_TYPE))) &&
|
||||
temp_data32 == SUBGHZ_KEY_FILE_VERSION) {
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Type or version mismatch");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_format_read_uint32(fff_data_file, "Frequency", &temp_data32, 1)) {
|
||||
FURI_LOG_E(TAG, "Missing Frequency");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!furi_hal_subghz_is_frequency_valid(temp_data32)) {
|
||||
FURI_LOG_E(TAG, "Frequency not supported");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!furi_hal_region_is_frequency_allowed(temp_data32)) {
|
||||
FURI_LOG_E(TAG, "This frequency can only be used for RX in your region");
|
||||
load_key_state = SubGhzLoadKeyStateOnlyRx;
|
||||
break;
|
||||
}
|
||||
subghz->txrx->preset->frequency = temp_data32;
|
||||
|
||||
if(!flipper_format_read_string(fff_data_file, "Preset", temp_str)) {
|
||||
FURI_LOG_E(TAG, "Missing Preset");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!subghz_set_preset(subghz, string_get_cstr(temp_str))) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(!strcmp(string_get_cstr(temp_str), "FuriHalSubGhzPresetCustom")) {
|
||||
//Todo add Custom_preset_module
|
||||
//delete preset if it already exists
|
||||
subghz_setting_delete_custom_preset(
|
||||
subghz->setting, string_get_cstr(subghz->txrx->preset->name));
|
||||
//load custom preset from file
|
||||
if(!subghz_setting_load_custom_preset(
|
||||
subghz->setting, string_get_cstr(subghz->txrx->preset->name), fff_data_file)) {
|
||||
FURI_LOG_E(TAG, "Missing Custom preset");
|
||||
break;
|
||||
}
|
||||
}
|
||||
size_t preset_index = subghz_setting_get_inx_preset_by_name(
|
||||
subghz->setting, string_get_cstr(subghz->txrx->preset->name));
|
||||
subghz_preset_init(
|
||||
subghz,
|
||||
string_get_cstr(subghz->txrx->preset->name),
|
||||
subghz->txrx->preset->frequency,
|
||||
subghz_setting_get_preset_data(subghz->setting, preset_index),
|
||||
subghz_setting_get_preset_data_size(subghz->setting, preset_index));
|
||||
|
||||
if(!flipper_format_read_string(fff_data_file, "Protocol", temp_str)) {
|
||||
FURI_LOG_E(TAG, "Missing Protocol");
|
||||
break;
|
||||
}
|
||||
if(!strcmp(string_get_cstr(temp_str), "RAW")) {
|
||||
//if RAW
|
||||
subghz_protocol_raw_gen_fff_data(subghz->txrx->fff_data, file_path);
|
||||
} else {
|
||||
stream_copy_full(
|
||||
flipper_format_get_raw_stream(fff_data_file),
|
||||
flipper_format_get_raw_stream(subghz->txrx->fff_data));
|
||||
}
|
||||
|
||||
subghz->txrx->decoder_result = subghz_receiver_search_decoder_base_by_name(
|
||||
subghz->txrx->receiver, string_get_cstr(temp_str));
|
||||
if(subghz->txrx->decoder_result) {
|
||||
if(!subghz_protocol_decoder_base_deserialize(
|
||||
subghz->txrx->decoder_result, subghz->txrx->fff_data)) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Protocol not found");
|
||||
break;
|
||||
}
|
||||
|
||||
load_key_state = SubGhzLoadKeyStateOK;
|
||||
} while(0);
|
||||
|
||||
string_clear(temp_str);
|
||||
flipper_format_free(fff_data_file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
switch(load_key_state) {
|
||||
case SubGhzLoadKeyStateParseErr:
|
||||
if(show_dialog) {
|
||||
dialog_message_show_storage_error(subghz->dialogs, "Cannot parse\nfile");
|
||||
}
|
||||
return false;
|
||||
|
||||
case SubGhzLoadKeyStateOnlyRx:
|
||||
if(show_dialog) {
|
||||
subghz_dialog_message_show_only_rx(subghz);
|
||||
}
|
||||
return false;
|
||||
|
||||
case SubGhzLoadKeyStateOK:
|
||||
return true;
|
||||
|
||||
default:
|
||||
furi_crash("SubGhz: Unknown load_key_state.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool subghz_get_next_name_file(SubGhz* subghz, uint8_t max_len) {
|
||||
furi_assert(subghz);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
string_t temp_str;
|
||||
string_t file_name;
|
||||
string_t file_path;
|
||||
|
||||
string_init(temp_str);
|
||||
string_init(file_name);
|
||||
string_init(file_path);
|
||||
|
||||
bool res = false;
|
||||
|
||||
if(subghz_path_is_file(subghz->file_path)) {
|
||||
//get the name of the next free file
|
||||
path_extract_filename(subghz->file_path, file_name, true);
|
||||
path_extract_dirname(string_get_cstr(subghz->file_path), file_path);
|
||||
|
||||
storage_get_next_filename(
|
||||
storage,
|
||||
string_get_cstr(file_path),
|
||||
string_get_cstr(file_name),
|
||||
SUBGHZ_APP_EXTENSION,
|
||||
file_name,
|
||||
max_len);
|
||||
|
||||
string_printf(
|
||||
temp_str,
|
||||
"%s/%s%s",
|
||||
string_get_cstr(file_path),
|
||||
string_get_cstr(file_name),
|
||||
SUBGHZ_APP_EXTENSION);
|
||||
string_set(subghz->file_path, temp_str);
|
||||
res = true;
|
||||
}
|
||||
|
||||
string_clear(temp_str);
|
||||
string_clear(file_path);
|
||||
string_clear(file_name);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool subghz_save_protocol_to_file(
|
||||
SubGhz* subghz,
|
||||
FlipperFormat* flipper_format,
|
||||
const char* dev_file_name) {
|
||||
furi_assert(subghz);
|
||||
furi_assert(flipper_format);
|
||||
furi_assert(dev_file_name);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
Stream* flipper_format_stream = flipper_format_get_raw_stream(flipper_format);
|
||||
|
||||
bool saved = false;
|
||||
string_t file_dir;
|
||||
string_init(file_dir);
|
||||
|
||||
path_extract_dirname(dev_file_name, file_dir);
|
||||
do {
|
||||
//removing additional fields
|
||||
flipper_format_delete_key(flipper_format, "Repeat");
|
||||
flipper_format_delete_key(flipper_format, "Manufacture");
|
||||
|
||||
// Create subghz folder directory if necessary
|
||||
if(!storage_simply_mkdir(storage, string_get_cstr(file_dir))) {
|
||||
dialog_message_show_storage_error(subghz->dialogs, "Cannot create\nfolder");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!storage_simply_remove(storage, dev_file_name)) {
|
||||
break;
|
||||
}
|
||||
//ToDo check Write
|
||||
stream_seek(flipper_format_stream, 0, StreamOffsetFromStart);
|
||||
stream_save_to_file(flipper_format_stream, storage, dev_file_name, FSOM_CREATE_ALWAYS);
|
||||
|
||||
saved = true;
|
||||
} while(0);
|
||||
string_clear(file_dir);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
return saved;
|
||||
}
|
||||
|
||||
bool subghz_load_protocol_from_file(SubGhz* subghz) {
|
||||
furi_assert(subghz);
|
||||
|
||||
string_t file_path;
|
||||
string_init(file_path);
|
||||
|
||||
DialogsFileBrowserOptions browser_options;
|
||||
dialog_file_browser_set_basic_options(&browser_options, SUBGHZ_APP_EXTENSION, &I_sub1_10px);
|
||||
|
||||
// Input events and views are managed by file_select
|
||||
bool res = dialog_file_browser_show(
|
||||
subghz->dialogs, subghz->file_path, subghz->file_path, &browser_options);
|
||||
|
||||
if(res) {
|
||||
res = subghz_key_load(subghz, string_get_cstr(subghz->file_path), true);
|
||||
}
|
||||
|
||||
string_clear(file_path);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool subghz_rename_file(SubGhz* subghz) {
|
||||
furi_assert(subghz);
|
||||
bool ret = true;
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
if(string_cmp(subghz->file_path_tmp, subghz->file_path)) {
|
||||
FS_Error fs_result = storage_common_rename(
|
||||
storage, string_get_cstr(subghz->file_path_tmp), string_get_cstr(subghz->file_path));
|
||||
|
||||
if(fs_result != FSE_OK) {
|
||||
dialog_message_show_storage_error(subghz->dialogs, "Cannot rename\n file/directory");
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool subghz_delete_file(SubGhz* subghz) {
|
||||
furi_assert(subghz);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
bool result = storage_simply_remove(storage, string_get_cstr(subghz->file_path_tmp));
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
subghz_file_name_clear(subghz);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void subghz_file_name_clear(SubGhz* subghz) {
|
||||
furi_assert(subghz);
|
||||
string_set_str(subghz->file_path, SUBGHZ_APP_FOLDER);
|
||||
string_reset(subghz->file_path_tmp);
|
||||
}
|
||||
|
||||
bool subghz_path_is_file(string_t path) {
|
||||
return string_end_with_str_p(path, SUBGHZ_APP_EXTENSION);
|
||||
}
|
||||
|
||||
uint32_t subghz_random_serial(void) {
|
||||
static bool rand_generator_inited = false;
|
||||
|
||||
if(!rand_generator_inited) {
|
||||
srand(DWT->CYCCNT);
|
||||
rand_generator_inited = true;
|
||||
}
|
||||
return (uint32_t)rand();
|
||||
}
|
||||
|
||||
void subghz_hopper_update(SubGhz* subghz) {
|
||||
furi_assert(subghz);
|
||||
|
||||
switch(subghz->txrx->hopper_state) {
|
||||
case SubGhzHopperStateOFF:
|
||||
return;
|
||||
break;
|
||||
case SubGhzHopperStatePause:
|
||||
return;
|
||||
break;
|
||||
case SubGhzHopperStateRSSITimeOut:
|
||||
if(subghz->txrx->hopper_timeout != 0) {
|
||||
subghz->txrx->hopper_timeout--;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
float rssi = -127.0f;
|
||||
if(subghz->txrx->hopper_state != SubGhzHopperStateRSSITimeOut) {
|
||||
// See RSSI Calculation timings in CC1101 17.3 RSSI
|
||||
rssi = furi_hal_subghz_get_rssi();
|
||||
|
||||
// Stay if RSSI is high enough
|
||||
if(rssi > -90.0f) {
|
||||
subghz->txrx->hopper_timeout = 10;
|
||||
subghz->txrx->hopper_state = SubGhzHopperStateRSSITimeOut;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
subghz->txrx->hopper_state = SubGhzHopperStateRunnig;
|
||||
}
|
||||
// Select next frequency
|
||||
if(subghz->txrx->hopper_idx_frequency <
|
||||
subghz_setting_get_hopper_frequency_count(subghz->setting) - 1) {
|
||||
subghz->txrx->hopper_idx_frequency++;
|
||||
} else {
|
||||
subghz->txrx->hopper_idx_frequency = 0;
|
||||
}
|
||||
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||
subghz_rx_end(subghz);
|
||||
};
|
||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) {
|
||||
subghz_receiver_reset(subghz->txrx->receiver);
|
||||
subghz->txrx->preset->frequency = subghz_setting_get_hopper_frequency(
|
||||
subghz->setting, subghz->txrx->hopper_idx_frequency);
|
||||
subghz_rx(subghz, subghz->txrx->preset->frequency);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
#pragma once
|
||||
|
||||
#include "helpers/subghz_types.h"
|
||||
#include "subghz.h"
|
||||
#include "views/receiver.h"
|
||||
#include "views/transmitter.h"
|
||||
#include "views/subghz_frequency_analyzer.h"
|
||||
#include "views/subghz_read_raw.h"
|
||||
|
||||
#include "views/subghz_test_static.h"
|
||||
#include "views/subghz_test_carrier.h"
|
||||
#include "views/subghz_test_packet.h"
|
||||
|
||||
// #include <furi.h>
|
||||
// #include <furi_hal.h>
|
||||
#include <gui/gui.h>
|
||||
#include <dialogs/dialogs.h>
|
||||
#include <gui/scene_manager.h>
|
||||
#include <notification/notification_messages.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/modules/submenu.h>
|
||||
#include <gui/modules/popup.h>
|
||||
#include <gui/modules/text_input.h>
|
||||
#include <gui/modules/widget.h>
|
||||
|
||||
#include <subghz/scenes/subghz_scene.h>
|
||||
|
||||
#include <lib/subghz/subghz_worker.h>
|
||||
|
||||
#include <lib/subghz/receiver.h>
|
||||
#include <lib/subghz/transmitter.h>
|
||||
|
||||
#include "subghz_history.h"
|
||||
#include "subghz_setting.h"
|
||||
|
||||
#include <gui/modules/variable_item_list.h>
|
||||
#include <lib/toolbox/path.h>
|
||||
|
||||
#include "rpc/rpc_app.h"
|
||||
|
||||
#define SUBGHZ_MAX_LEN_NAME 64
|
||||
|
||||
struct SubGhzTxRx {
|
||||
SubGhzWorker* worker;
|
||||
|
||||
SubGhzEnvironment* environment;
|
||||
SubGhzReceiver* receiver;
|
||||
SubGhzTransmitter* transmitter;
|
||||
SubGhzProtocolDecoderBase* decoder_result;
|
||||
FlipperFormat* fff_data;
|
||||
|
||||
SubGhzPresetDefinition* preset;
|
||||
SubGhzHistory* history;
|
||||
uint16_t idx_menu_chosen;
|
||||
SubGhzTxRxState txrx_state;
|
||||
SubGhzHopperState hopper_state;
|
||||
uint8_t hopper_timeout;
|
||||
uint8_t hopper_idx_frequency;
|
||||
SubGhzRxKeyState rx_key_state;
|
||||
};
|
||||
|
||||
typedef struct SubGhzTxRx SubGhzTxRx;
|
||||
|
||||
struct SubGhz {
|
||||
Gui* gui;
|
||||
NotificationApp* notifications;
|
||||
|
||||
SubGhzTxRx* txrx;
|
||||
|
||||
SceneManager* scene_manager;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
|
||||
Submenu* submenu;
|
||||
Popup* popup;
|
||||
TextInput* text_input;
|
||||
Widget* widget;
|
||||
DialogsApp* dialogs;
|
||||
string_t file_path;
|
||||
string_t file_path_tmp;
|
||||
char file_name_tmp[SUBGHZ_MAX_LEN_NAME];
|
||||
SubGhzNotificationState state_notifications;
|
||||
|
||||
SubGhzViewReceiver* subghz_receiver;
|
||||
SubGhzViewTransmitter* subghz_transmitter;
|
||||
VariableItemList* variable_item_list;
|
||||
|
||||
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer;
|
||||
SubGhzReadRAW* subghz_read_raw;
|
||||
SubGhzTestStatic* subghz_test_static;
|
||||
SubGhzTestCarrier* subghz_test_carrier;
|
||||
SubGhzTestPacket* subghz_test_packet;
|
||||
string_t error_str;
|
||||
SubGhzSetting* setting;
|
||||
SubGhzLock lock;
|
||||
|
||||
void* rpc_ctx;
|
||||
};
|
||||
|
||||
void subghz_preset_init(
|
||||
void* context,
|
||||
const char* preset_name,
|
||||
uint32_t frequency,
|
||||
uint8_t* preset_data,
|
||||
size_t preset_data_size);
|
||||
bool subghz_set_preset(SubGhz* subghz, const char* preset);
|
||||
void subghz_get_frequency_modulation(SubGhz* subghz, string_t frequency, string_t modulation);
|
||||
void subghz_begin(SubGhz* subghz, uint8_t* preset_data);
|
||||
uint32_t subghz_rx(SubGhz* subghz, uint32_t frequency);
|
||||
void subghz_rx_end(SubGhz* subghz);
|
||||
void subghz_sleep(SubGhz* subghz);
|
||||
|
||||
void subghz_blink_start(SubGhz* instance);
|
||||
void subghz_blink_stop(SubGhz* instance);
|
||||
|
||||
bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format);
|
||||
void subghz_tx_stop(SubGhz* subghz);
|
||||
void subghz_dialog_message_show_only_rx(SubGhz* subghz);
|
||||
bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog);
|
||||
bool subghz_get_next_name_file(SubGhz* subghz, uint8_t max_len);
|
||||
bool subghz_save_protocol_to_file(
|
||||
SubGhz* subghz,
|
||||
FlipperFormat* flipper_format,
|
||||
const char* dev_file_name);
|
||||
bool subghz_load_protocol_from_file(SubGhz* subghz);
|
||||
bool subghz_rename_file(SubGhz* subghz);
|
||||
bool subghz_delete_file(SubGhz* subghz);
|
||||
void subghz_file_name_clear(SubGhz* subghz);
|
||||
bool subghz_path_is_file(string_t path);
|
||||
uint32_t subghz_random_serial(void);
|
||||
void subghz_hopper_update(SubGhz* subghz);
|
||||
@@ -0,0 +1,567 @@
|
||||
#include "subghz_setting.h"
|
||||
#include "subghz_i.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <m-list.h>
|
||||
#include "furi_hal_subghz_configs.h"
|
||||
|
||||
#define TAG "SubGhzSetting"
|
||||
|
||||
#define SUBGHZ_SETTING_FILE_TYPE "Flipper SubGhz Setting File"
|
||||
#define SUBGHZ_SETTING_FILE_VERSION 1
|
||||
|
||||
#define FREQUENCY_FLAG_DEFAULT (1 << 31)
|
||||
#define FREQUENCY_MASK (0xFFFFFFFF ^ FREQUENCY_FLAG_DEFAULT)
|
||||
|
||||
/* Default */
|
||||
static const uint32_t subghz_frequency_list[] = {
|
||||
/* 300 - 348 */
|
||||
300000000,
|
||||
303875000,
|
||||
304250000,
|
||||
310000000,
|
||||
315000000,
|
||||
318000000,
|
||||
|
||||
/* 387 - 464 */
|
||||
390000000,
|
||||
418000000,
|
||||
433075000, /* LPD433 first */
|
||||
433420000,
|
||||
433920000 | FREQUENCY_FLAG_DEFAULT, /* LPD433 mid */
|
||||
434420000,
|
||||
434775000, /* LPD433 last channels */
|
||||
438900000,
|
||||
|
||||
/* 779 - 928 */
|
||||
868350000,
|
||||
915000000,
|
||||
925000000,
|
||||
0,
|
||||
};
|
||||
|
||||
static const uint32_t subghz_hopper_frequency_list[] = {
|
||||
310000000,
|
||||
315000000,
|
||||
318000000,
|
||||
390000000,
|
||||
433920000,
|
||||
868350000,
|
||||
0,
|
||||
};
|
||||
|
||||
/* Europe and Russia */
|
||||
static const uint32_t subghz_frequency_list_region_eu_ru[] = {
|
||||
/* 300 - 348 */
|
||||
300000000,
|
||||
303875000,
|
||||
304250000,
|
||||
310000000,
|
||||
315000000,
|
||||
318000000,
|
||||
|
||||
/* 387 - 464 */
|
||||
390000000,
|
||||
418000000,
|
||||
433075000, /* LPD433 first */
|
||||
433420000,
|
||||
433920000 | FREQUENCY_FLAG_DEFAULT, /* LPD433 mid */
|
||||
434420000,
|
||||
434775000, /* LPD433 last channels */
|
||||
438900000,
|
||||
|
||||
/* 779 - 928 */
|
||||
868350000,
|
||||
915000000,
|
||||
925000000,
|
||||
0,
|
||||
};
|
||||
static const uint32_t subghz_hopper_frequency_list_region_eu_ru[] = {
|
||||
310000000,
|
||||
315000000,
|
||||
318000000,
|
||||
390000000,
|
||||
433920000,
|
||||
868350000,
|
||||
0,
|
||||
};
|
||||
|
||||
/* Region 0 */
|
||||
static const uint32_t subghz_frequency_list_region_us_ca_au[] = {
|
||||
/* 300 - 348 */
|
||||
300000000,
|
||||
303875000,
|
||||
304250000,
|
||||
310000000,
|
||||
315000000,
|
||||
318000000,
|
||||
|
||||
/* 387 - 464 */
|
||||
390000000,
|
||||
418000000,
|
||||
433075000, /* LPD433 first */
|
||||
433420000,
|
||||
433920000 | FREQUENCY_FLAG_DEFAULT, /* LPD433 mid */
|
||||
434420000,
|
||||
434775000, /* LPD433 last channels */
|
||||
438900000,
|
||||
|
||||
/* 779 - 928 */
|
||||
868350000,
|
||||
915000000,
|
||||
925000000,
|
||||
0,
|
||||
};
|
||||
static const uint32_t subghz_hopper_frequency_list_region_us_ca_au[] = {
|
||||
310000000,
|
||||
315000000,
|
||||
318000000,
|
||||
390000000,
|
||||
433920000,
|
||||
868350000,
|
||||
0,
|
||||
};
|
||||
|
||||
static const uint32_t subghz_frequency_list_region_jp[] = {
|
||||
/* 300 - 348 */
|
||||
300000000,
|
||||
303875000,
|
||||
304250000,
|
||||
310000000,
|
||||
315000000,
|
||||
318000000,
|
||||
|
||||
/* 387 - 464 */
|
||||
390000000,
|
||||
418000000,
|
||||
433075000, /* LPD433 first */
|
||||
433420000,
|
||||
433920000 | FREQUENCY_FLAG_DEFAULT, /* LPD433 mid */
|
||||
434420000,
|
||||
434775000, /* LPD433 last channels */
|
||||
438900000,
|
||||
|
||||
/* 779 - 928 */
|
||||
868350000,
|
||||
915000000,
|
||||
925000000,
|
||||
0,
|
||||
};
|
||||
static const uint32_t subghz_hopper_frequency_list_region_jp[] = {
|
||||
310000000,
|
||||
315000000,
|
||||
318000000,
|
||||
390000000,
|
||||
433920000,
|
||||
868350000,
|
||||
0,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
string_t custom_preset_name;
|
||||
uint8_t* custom_preset_data;
|
||||
size_t custom_preset_data_size;
|
||||
} SubGhzSettingCustomPresetItem;
|
||||
|
||||
ARRAY_DEF(SubGhzSettingCustomPresetItemArray, SubGhzSettingCustomPresetItem, M_POD_OPLIST)
|
||||
|
||||
#define M_OPL_SubGhzSettingCustomPresetItemArray_t() \
|
||||
ARRAY_OPLIST(SubGhzSettingCustomPresetItemArray, M_POD_OPLIST)
|
||||
|
||||
LIST_DEF(FrequencyList, uint32_t)
|
||||
|
||||
#define M_OPL_FrequencyList_t() LIST_OPLIST(FrequencyList)
|
||||
|
||||
typedef struct {
|
||||
SubGhzSettingCustomPresetItemArray_t data;
|
||||
} SubGhzSettingCustomPresetStruct;
|
||||
|
||||
struct SubGhzSetting {
|
||||
FrequencyList_t frequencies;
|
||||
FrequencyList_t hopper_frequencies;
|
||||
SubGhzSettingCustomPresetStruct* preset;
|
||||
};
|
||||
|
||||
SubGhzSetting* subghz_setting_alloc(void) {
|
||||
SubGhzSetting* instance = malloc(sizeof(SubGhzSetting));
|
||||
FrequencyList_init(instance->frequencies);
|
||||
FrequencyList_init(instance->hopper_frequencies);
|
||||
instance->preset = malloc(sizeof(SubGhzSettingCustomPresetStruct));
|
||||
SubGhzSettingCustomPresetItemArray_init(instance->preset->data);
|
||||
return instance;
|
||||
}
|
||||
|
||||
static void subghz_setting_preset_reset(SubGhzSetting* instance) {
|
||||
for
|
||||
M_EACH(item, instance->preset->data, SubGhzSettingCustomPresetItemArray_t) {
|
||||
string_clear(item->custom_preset_name);
|
||||
free(item->custom_preset_data);
|
||||
}
|
||||
SubGhzSettingCustomPresetItemArray_reset(instance->preset->data);
|
||||
}
|
||||
|
||||
void subghz_setting_free(SubGhzSetting* instance) {
|
||||
furi_assert(instance);
|
||||
FrequencyList_clear(instance->frequencies);
|
||||
FrequencyList_clear(instance->hopper_frequencies);
|
||||
for
|
||||
M_EACH(item, instance->preset->data, SubGhzSettingCustomPresetItemArray_t) {
|
||||
string_clear(item->custom_preset_name);
|
||||
free(item->custom_preset_data);
|
||||
}
|
||||
SubGhzSettingCustomPresetItemArray_clear(instance->preset->data);
|
||||
free(instance->preset);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
static void subghz_setting_load_default_preset(
|
||||
SubGhzSetting* instance,
|
||||
const char* preset_name,
|
||||
const uint8_t* preset_data,
|
||||
const uint8_t preset_pa_table[8]) {
|
||||
furi_assert(instance);
|
||||
furi_assert(preset_data);
|
||||
uint32_t preset_data_count = 0;
|
||||
SubGhzSettingCustomPresetItem* item =
|
||||
SubGhzSettingCustomPresetItemArray_push_raw(instance->preset->data);
|
||||
|
||||
string_init(item->custom_preset_name);
|
||||
string_set(item->custom_preset_name, preset_name);
|
||||
|
||||
while(preset_data[preset_data_count]) {
|
||||
preset_data_count += 2;
|
||||
}
|
||||
preset_data_count += 2;
|
||||
item->custom_preset_data_size = sizeof(uint8_t) * preset_data_count + sizeof(uint8_t) * 8;
|
||||
item->custom_preset_data = malloc(item->custom_preset_data_size);
|
||||
//load preset register
|
||||
memcpy(&item->custom_preset_data[0], &preset_data[0], preset_data_count);
|
||||
//load pa table
|
||||
memcpy(&item->custom_preset_data[preset_data_count], &preset_pa_table[0], 8);
|
||||
}
|
||||
|
||||
static void subghz_setting_load_default_region(
|
||||
SubGhzSetting* instance,
|
||||
const uint32_t frequencies[],
|
||||
const uint32_t hopper_frequencies[]) {
|
||||
furi_assert(instance);
|
||||
|
||||
FrequencyList_reset(instance->frequencies);
|
||||
FrequencyList_reset(instance->hopper_frequencies);
|
||||
subghz_setting_preset_reset(instance);
|
||||
|
||||
while(*frequencies) {
|
||||
FrequencyList_push_back(instance->frequencies, *frequencies);
|
||||
frequencies++;
|
||||
}
|
||||
|
||||
while(*hopper_frequencies) {
|
||||
FrequencyList_push_back(instance->hopper_frequencies, *hopper_frequencies);
|
||||
hopper_frequencies++;
|
||||
}
|
||||
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"AM270",
|
||||
(uint8_t*)furi_hal_subghz_preset_ook_270khz_async_regs,
|
||||
furi_hal_subghz_preset_ook_async_patable);
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"AM650",
|
||||
(uint8_t*)furi_hal_subghz_preset_ook_650khz_async_regs,
|
||||
furi_hal_subghz_preset_ook_async_patable);
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"FM238",
|
||||
(uint8_t*)furi_hal_subghz_preset_2fsk_dev2_38khz_async_regs,
|
||||
furi_hal_subghz_preset_2fsk_async_patable);
|
||||
subghz_setting_load_default_preset(
|
||||
instance,
|
||||
"FM476",
|
||||
(uint8_t*)furi_hal_subghz_preset_2fsk_dev47_6khz_async_regs,
|
||||
furi_hal_subghz_preset_2fsk_async_patable);
|
||||
}
|
||||
|
||||
void subghz_setting_load_default(SubGhzSetting* instance) {
|
||||
switch(furi_hal_version_get_hw_region()) {
|
||||
case FuriHalVersionRegionEuRu:
|
||||
subghz_setting_load_default_region(
|
||||
instance,
|
||||
subghz_frequency_list_region_eu_ru,
|
||||
subghz_hopper_frequency_list_region_eu_ru);
|
||||
break;
|
||||
case FuriHalVersionRegionUsCaAu:
|
||||
subghz_setting_load_default_region(
|
||||
instance,
|
||||
subghz_frequency_list_region_us_ca_au,
|
||||
subghz_hopper_frequency_list_region_us_ca_au);
|
||||
break;
|
||||
case FuriHalVersionRegionJp:
|
||||
subghz_setting_load_default_region(
|
||||
instance, subghz_frequency_list_region_jp, subghz_hopper_frequency_list_region_jp);
|
||||
break;
|
||||
|
||||
default:
|
||||
subghz_setting_load_default_region(
|
||||
instance, subghz_frequency_list, subghz_hopper_frequency_list);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_setting_load(SubGhzSetting* instance, const char* file_path) {
|
||||
furi_assert(instance);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
|
||||
|
||||
string_t temp_str;
|
||||
string_init(temp_str);
|
||||
uint32_t temp_data32;
|
||||
bool temp_bool;
|
||||
|
||||
subghz_setting_load_default(instance);
|
||||
|
||||
if(file_path) {
|
||||
do {
|
||||
if(!flipper_format_file_open_existing(fff_data_file, file_path)) {
|
||||
FURI_LOG_E(TAG, "Error open file %s", file_path);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
|
||||
FURI_LOG_E(TAG, "Missing or incorrect header");
|
||||
break;
|
||||
}
|
||||
|
||||
if((!strcmp(string_get_cstr(temp_str), SUBGHZ_SETTING_FILE_TYPE)) &&
|
||||
temp_data32 == SUBGHZ_SETTING_FILE_VERSION) {
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Type or version mismatch");
|
||||
break;
|
||||
}
|
||||
|
||||
// Standard frequencies (optional)
|
||||
temp_bool = true;
|
||||
flipper_format_read_bool(fff_data_file, "Add_standard_frequencies", &temp_bool, 1);
|
||||
if(!temp_bool) {
|
||||
FURI_LOG_I(TAG, "Removing standard frequencies");
|
||||
FrequencyList_reset(instance->frequencies);
|
||||
FrequencyList_reset(instance->hopper_frequencies);
|
||||
} else {
|
||||
FURI_LOG_I(TAG, "Keeping standard frequencies");
|
||||
}
|
||||
|
||||
// Load frequencies
|
||||
if(!flipper_format_rewind(fff_data_file)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
while(flipper_format_read_uint32(
|
||||
fff_data_file, "Frequency", (uint32_t*)&temp_data32, 1)) {
|
||||
if(furi_hal_subghz_is_frequency_valid(temp_data32)) {
|
||||
FURI_LOG_I(TAG, "Frequency loaded %lu", temp_data32);
|
||||
FrequencyList_push_back(instance->frequencies, temp_data32);
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Frequency not supported %lu", temp_data32);
|
||||
}
|
||||
}
|
||||
|
||||
// Load hopper frequencies
|
||||
if(!flipper_format_rewind(fff_data_file)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
while(flipper_format_read_uint32(
|
||||
fff_data_file, "Hopper_frequency", (uint32_t*)&temp_data32, 1)) {
|
||||
if(furi_hal_subghz_is_frequency_valid(temp_data32)) {
|
||||
FURI_LOG_I(TAG, "Hopper frequency loaded %lu", temp_data32);
|
||||
FrequencyList_push_back(instance->hopper_frequencies, temp_data32);
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Hopper frequency not supported %lu", temp_data32);
|
||||
}
|
||||
}
|
||||
|
||||
// Default frequency (optional)
|
||||
if(!flipper_format_rewind(fff_data_file)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
if(flipper_format_read_uint32(fff_data_file, "Default_frequency", &temp_data32, 1)) {
|
||||
for
|
||||
M_EACH(frequency, instance->frequencies, FrequencyList_t) {
|
||||
*frequency &= FREQUENCY_MASK;
|
||||
if(*frequency == temp_data32) {
|
||||
*frequency |= FREQUENCY_FLAG_DEFAULT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// custom preset (optional)
|
||||
if(!flipper_format_rewind(fff_data_file)) {
|
||||
FURI_LOG_E(TAG, "Rewind error");
|
||||
break;
|
||||
}
|
||||
while(flipper_format_read_string(fff_data_file, "Custom_preset_name", temp_str)) {
|
||||
FURI_LOG_I(TAG, "Custom preset loaded %s", string_get_cstr(temp_str));
|
||||
subghz_setting_load_custom_preset(
|
||||
instance, string_get_cstr(temp_str), fff_data_file);
|
||||
}
|
||||
|
||||
} while(false);
|
||||
}
|
||||
|
||||
string_clear(temp_str);
|
||||
flipper_format_free(fff_data_file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
if(!FrequencyList_size(instance->frequencies) ||
|
||||
!FrequencyList_size(instance->hopper_frequencies)) {
|
||||
FURI_LOG_E(TAG, "Error loading user settings, loading default settings");
|
||||
subghz_setting_load_default(instance);
|
||||
}
|
||||
}
|
||||
|
||||
size_t subghz_setting_get_frequency_count(SubGhzSetting* instance) {
|
||||
furi_assert(instance);
|
||||
return FrequencyList_size(instance->frequencies);
|
||||
}
|
||||
|
||||
size_t subghz_setting_get_hopper_frequency_count(SubGhzSetting* instance) {
|
||||
furi_assert(instance);
|
||||
return FrequencyList_size(instance->hopper_frequencies);
|
||||
}
|
||||
|
||||
size_t subghz_setting_get_preset_count(SubGhzSetting* instance) {
|
||||
furi_assert(instance);
|
||||
return SubGhzSettingCustomPresetItemArray_size(instance->preset->data);
|
||||
}
|
||||
|
||||
const char* subghz_setting_get_preset_name(SubGhzSetting* instance, size_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzSettingCustomPresetItem* item =
|
||||
SubGhzSettingCustomPresetItemArray_get(instance->preset->data, idx);
|
||||
return string_get_cstr(item->custom_preset_name);
|
||||
}
|
||||
|
||||
int subghz_setting_get_inx_preset_by_name(SubGhzSetting* instance, const char* preset_name) {
|
||||
furi_assert(instance);
|
||||
size_t idx = 0;
|
||||
for
|
||||
M_EACH(item, instance->preset->data, SubGhzSettingCustomPresetItemArray_t) {
|
||||
if(strcmp(string_get_cstr(item->custom_preset_name), preset_name) == 0) {
|
||||
return idx;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
furi_crash("SubGhz: No name preset.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool subghz_setting_load_custom_preset(
|
||||
SubGhzSetting* instance,
|
||||
const char* preset_name,
|
||||
FlipperFormat* fff_data_file) {
|
||||
furi_assert(instance);
|
||||
furi_assert(preset_name);
|
||||
uint32_t temp_data32;
|
||||
SubGhzSettingCustomPresetItem* item =
|
||||
SubGhzSettingCustomPresetItemArray_push_raw(instance->preset->data);
|
||||
string_init(item->custom_preset_name);
|
||||
string_set(item->custom_preset_name, preset_name);
|
||||
do {
|
||||
if(!flipper_format_get_value_count(fff_data_file, "Custom_preset_data", &temp_data32))
|
||||
break;
|
||||
if(!temp_data32 || (temp_data32 % 2)) {
|
||||
FURI_LOG_E(TAG, "Integrity error Custom_preset_data");
|
||||
break;
|
||||
}
|
||||
item->custom_preset_data_size = sizeof(uint8_t) * temp_data32;
|
||||
item->custom_preset_data = malloc(item->custom_preset_data_size);
|
||||
if(!flipper_format_read_hex(
|
||||
fff_data_file,
|
||||
"Custom_preset_data",
|
||||
item->custom_preset_data,
|
||||
item->custom_preset_data_size)) {
|
||||
FURI_LOG_E(TAG, "Missing Custom_preset_data");
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
} while(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool subghz_setting_delete_custom_preset(SubGhzSetting* instance, const char* preset_name) {
|
||||
furi_assert(instance);
|
||||
furi_assert(preset_name);
|
||||
SubGhzSettingCustomPresetItemArray_it_t it;
|
||||
SubGhzSettingCustomPresetItemArray_it_last(it, instance->preset->data);
|
||||
while(!SubGhzSettingCustomPresetItemArray_end_p(it)) {
|
||||
SubGhzSettingCustomPresetItem* item = SubGhzSettingCustomPresetItemArray_ref(it);
|
||||
if(strcmp(string_get_cstr(item->custom_preset_name), preset_name) == 0) {
|
||||
string_clear(item->custom_preset_name);
|
||||
free(item->custom_preset_data);
|
||||
SubGhzSettingCustomPresetItemArray_remove(instance->preset->data, it);
|
||||
return true;
|
||||
}
|
||||
SubGhzSettingCustomPresetItemArray_previous(it);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t* subghz_setting_get_preset_data(SubGhzSetting* instance, size_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzSettingCustomPresetItem* item =
|
||||
SubGhzSettingCustomPresetItemArray_get(instance->preset->data, idx);
|
||||
return item->custom_preset_data;
|
||||
}
|
||||
|
||||
size_t subghz_setting_get_preset_data_size(SubGhzSetting* instance, size_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzSettingCustomPresetItem* item =
|
||||
SubGhzSettingCustomPresetItemArray_get(instance->preset->data, idx);
|
||||
return item->custom_preset_data_size;
|
||||
}
|
||||
|
||||
uint8_t* subghz_setting_get_preset_data_by_name(SubGhzSetting* instance, const char* preset_name) {
|
||||
furi_assert(instance);
|
||||
SubGhzSettingCustomPresetItem* item = SubGhzSettingCustomPresetItemArray_get(
|
||||
instance->preset->data, subghz_setting_get_inx_preset_by_name(instance, preset_name));
|
||||
return item->custom_preset_data;
|
||||
}
|
||||
|
||||
uint32_t subghz_setting_get_frequency(SubGhzSetting* instance, size_t idx) {
|
||||
furi_assert(instance);
|
||||
uint32_t* ret = FrequencyList_get(instance->frequencies, idx);
|
||||
if(ret) {
|
||||
return (*ret) & FREQUENCY_MASK;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t subghz_setting_get_hopper_frequency(SubGhzSetting* instance, size_t idx) {
|
||||
furi_assert(instance);
|
||||
uint32_t* ret = FrequencyList_get(instance->hopper_frequencies, idx);
|
||||
if(ret) {
|
||||
return *ret;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t subghz_setting_get_frequency_default_index(SubGhzSetting* instance) {
|
||||
furi_assert(instance);
|
||||
for(size_t i = 0; i < FrequencyList_size(instance->frequencies); i++) {
|
||||
uint32_t frequency = *FrequencyList_get(instance->frequencies, i);
|
||||
if(frequency & FREQUENCY_FLAG_DEFAULT) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t subghz_setting_get_default_frequency(SubGhzSetting* instance) {
|
||||
furi_assert(instance);
|
||||
return subghz_setting_get_frequency(
|
||||
instance, subghz_setting_get_frequency_default_index(instance));
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <math.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <lib/flipper_format/flipper_format.h>
|
||||
|
||||
#define SUBGHZ_SETTING_DEFAULT_PRESET_COUNT 4
|
||||
|
||||
typedef struct SubGhzSetting SubGhzSetting;
|
||||
|
||||
SubGhzSetting* subghz_setting_alloc(void);
|
||||
|
||||
void subghz_setting_free(SubGhzSetting* instance);
|
||||
|
||||
void subghz_setting_load(SubGhzSetting* instance, const char* file_path);
|
||||
|
||||
size_t subghz_setting_get_frequency_count(SubGhzSetting* instance);
|
||||
|
||||
size_t subghz_setting_get_hopper_frequency_count(SubGhzSetting* instance);
|
||||
|
||||
size_t subghz_setting_get_preset_count(SubGhzSetting* instance);
|
||||
|
||||
const char* subghz_setting_get_preset_name(SubGhzSetting* instance, size_t idx);
|
||||
|
||||
int subghz_setting_get_inx_preset_by_name(SubGhzSetting* instance, const char* preset_name);
|
||||
|
||||
uint8_t* subghz_setting_get_preset_data(SubGhzSetting* instance, size_t idx);
|
||||
|
||||
size_t subghz_setting_get_preset_data_size(SubGhzSetting* instance, size_t idx);
|
||||
|
||||
uint8_t* subghz_setting_get_preset_data_by_name(SubGhzSetting* instance, const char* preset_name);
|
||||
|
||||
bool subghz_setting_load_custom_preset(
|
||||
SubGhzSetting* instance,
|
||||
const char* preset_name,
|
||||
FlipperFormat* fff_data_file);
|
||||
|
||||
bool subghz_setting_delete_custom_preset(SubGhzSetting* instance, const char* preset_name);
|
||||
|
||||
uint32_t subghz_setting_get_frequency(SubGhzSetting* instance, size_t idx);
|
||||
|
||||
uint32_t subghz_setting_get_hopper_frequency(SubGhzSetting* instance, size_t idx);
|
||||
|
||||
uint32_t subghz_setting_get_frequency_default_index(SubGhzSetting* instance);
|
||||
|
||||
uint32_t subghz_setting_get_default_frequency(SubGhzSetting* instance);
|
||||
@@ -0,0 +1,429 @@
|
||||
#include "receiver.h"
|
||||
#include "../subghz_i.h"
|
||||
#include <math.h>
|
||||
|
||||
#include <input/input.h>
|
||||
#include <gui/elements.h>
|
||||
#include <assets_icons.h>
|
||||
#include <m-string.h>
|
||||
#include <m-array.h>
|
||||
|
||||
#define FRAME_HEIGHT 12
|
||||
#define MAX_LEN_PX 100
|
||||
#define MENU_ITEMS 4u
|
||||
#define UNLOCK_CNT 3
|
||||
|
||||
typedef struct {
|
||||
string_t item_str;
|
||||
uint8_t type;
|
||||
} SubGhzReceiverMenuItem;
|
||||
|
||||
ARRAY_DEF(SubGhzReceiverMenuItemArray, SubGhzReceiverMenuItem, M_POD_OPLIST)
|
||||
|
||||
#define M_OPL_SubGhzReceiverMenuItemArray_t() \
|
||||
ARRAY_OPLIST(SubGhzReceiverMenuItemArray, M_POD_OPLIST)
|
||||
|
||||
struct SubGhzReceiverHistory {
|
||||
SubGhzReceiverMenuItemArray_t data;
|
||||
};
|
||||
|
||||
typedef struct SubGhzReceiverHistory SubGhzReceiverHistory;
|
||||
|
||||
static const Icon* ReceiverItemIcons[] = {
|
||||
[SubGhzProtocolTypeUnknown] = &I_Quest_7x8,
|
||||
[SubGhzProtocolTypeStatic] = &I_Unlock_7x8,
|
||||
[SubGhzProtocolTypeDynamic] = &I_Lock_7x8,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
SubGhzViewReceiverBarShowDefault,
|
||||
SubGhzViewReceiverBarShowLock,
|
||||
SubGhzViewReceiverBarShowToUnlockPress,
|
||||
SubGhzViewReceiverBarShowUnlock,
|
||||
} SubGhzViewReceiverBarShow;
|
||||
|
||||
struct SubGhzViewReceiver {
|
||||
SubGhzLock lock;
|
||||
uint8_t lock_count;
|
||||
FuriTimer* timer;
|
||||
View* view;
|
||||
SubGhzViewReceiverCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
string_t frequency_str;
|
||||
string_t preset_str;
|
||||
string_t history_stat_str;
|
||||
SubGhzReceiverHistory* history;
|
||||
uint16_t idx;
|
||||
uint16_t list_offset;
|
||||
uint16_t history_item;
|
||||
SubGhzViewReceiverBarShow bar_show;
|
||||
} SubGhzViewReceiverModel;
|
||||
|
||||
void subghz_view_receiver_set_lock(SubGhzViewReceiver* subghz_receiver, SubGhzLock lock) {
|
||||
furi_assert(subghz_receiver);
|
||||
subghz_receiver->lock_count = 0;
|
||||
if(lock == SubGhzLockOn) {
|
||||
subghz_receiver->lock = lock;
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
model->bar_show = SubGhzViewReceiverBarShowLock;
|
||||
return true;
|
||||
});
|
||||
furi_timer_start(subghz_receiver->timer, pdMS_TO_TICKS(1000));
|
||||
} else {
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
model->bar_show = SubGhzViewReceiverBarShowDefault;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_view_receiver_set_callback(
|
||||
SubGhzViewReceiver* subghz_receiver,
|
||||
SubGhzViewReceiverCallback callback,
|
||||
void* context) {
|
||||
furi_assert(subghz_receiver);
|
||||
furi_assert(callback);
|
||||
subghz_receiver->callback = callback;
|
||||
subghz_receiver->context = context;
|
||||
}
|
||||
|
||||
static void subghz_view_receiver_update_offset(SubGhzViewReceiver* subghz_receiver) {
|
||||
furi_assert(subghz_receiver);
|
||||
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
size_t history_item = model->history_item;
|
||||
uint16_t bounds = history_item > 3 ? 2 : history_item;
|
||||
|
||||
if(history_item > 3 && model->idx >= (int16_t)(history_item - 1)) {
|
||||
model->list_offset = model->idx - 3;
|
||||
} else if(model->list_offset < model->idx - bounds) {
|
||||
model->list_offset =
|
||||
CLAMP(model->list_offset + 1, (int16_t)(history_item - bounds), 0);
|
||||
} else if(model->list_offset > model->idx - bounds) {
|
||||
model->list_offset = CLAMP(model->idx - 1, (int16_t)(history_item - bounds), 0);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void subghz_view_receiver_add_item_to_menu(
|
||||
SubGhzViewReceiver* subghz_receiver,
|
||||
const char* name,
|
||||
uint8_t type) {
|
||||
furi_assert(subghz_receiver);
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
SubGhzReceiverMenuItem* item_menu =
|
||||
SubGhzReceiverMenuItemArray_push_raw(model->history->data);
|
||||
string_init_set_str(item_menu->item_str, name);
|
||||
item_menu->type = type;
|
||||
if((model->idx == model->history_item - 1)) {
|
||||
model->history_item++;
|
||||
model->idx++;
|
||||
} else {
|
||||
model->history_item++;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
subghz_view_receiver_update_offset(subghz_receiver);
|
||||
}
|
||||
|
||||
void subghz_view_receiver_add_data_statusbar(
|
||||
SubGhzViewReceiver* subghz_receiver,
|
||||
const char* frequency_str,
|
||||
const char* preset_str,
|
||||
const char* history_stat_str) {
|
||||
furi_assert(subghz_receiver);
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
string_set_str(model->frequency_str, frequency_str);
|
||||
string_set_str(model->preset_str, preset_str);
|
||||
string_set_str(model->history_stat_str, history_stat_str);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
static void subghz_view_receiver_draw_frame(Canvas* canvas, uint16_t idx, bool scrollbar) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_box(canvas, 0, 0 + idx * FRAME_HEIGHT, scrollbar ? 122 : 127, FRAME_HEIGHT);
|
||||
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
canvas_draw_dot(canvas, 0, 0 + idx * FRAME_HEIGHT);
|
||||
canvas_draw_dot(canvas, 1, 0 + idx * FRAME_HEIGHT);
|
||||
canvas_draw_dot(canvas, 0, (0 + idx * FRAME_HEIGHT) + 1);
|
||||
|
||||
canvas_draw_dot(canvas, 0, (0 + idx * FRAME_HEIGHT) + 11);
|
||||
canvas_draw_dot(canvas, scrollbar ? 121 : 126, 0 + idx * FRAME_HEIGHT);
|
||||
canvas_draw_dot(canvas, scrollbar ? 121 : 126, (0 + idx * FRAME_HEIGHT) + 11);
|
||||
}
|
||||
|
||||
void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) {
|
||||
canvas_clear(canvas);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
|
||||
elements_button_left(canvas, "Config");
|
||||
canvas_draw_line(canvas, 46, 51, 125, 51);
|
||||
|
||||
bool scrollbar = model->history_item > 4;
|
||||
string_t str_buff;
|
||||
string_init(str_buff);
|
||||
|
||||
SubGhzReceiverMenuItem* item_menu;
|
||||
|
||||
for(size_t i = 0; i < MIN(model->history_item, MENU_ITEMS); ++i) {
|
||||
size_t idx = CLAMP((uint16_t)(i + model->list_offset), model->history_item, 0);
|
||||
item_menu = SubGhzReceiverMenuItemArray_get(model->history->data, idx);
|
||||
string_set(str_buff, item_menu->item_str);
|
||||
elements_string_fit_width(canvas, str_buff, scrollbar ? MAX_LEN_PX - 6 : MAX_LEN_PX);
|
||||
if(model->idx == idx) {
|
||||
subghz_view_receiver_draw_frame(canvas, i, scrollbar);
|
||||
} else {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
}
|
||||
canvas_draw_icon(canvas, 1, 2 + i * FRAME_HEIGHT, ReceiverItemIcons[item_menu->type]);
|
||||
canvas_draw_str(canvas, 15, 9 + i * FRAME_HEIGHT, string_get_cstr(str_buff));
|
||||
string_reset(str_buff);
|
||||
}
|
||||
if(scrollbar) {
|
||||
elements_scrollbar_pos(canvas, 128, 0, 49, model->idx, model->history_item);
|
||||
}
|
||||
string_clear(str_buff);
|
||||
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
if(model->history_item == 0) {
|
||||
canvas_draw_icon(canvas, 0, 0, &I_Scanning_123x52);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 63, 46, "Scanning...");
|
||||
canvas_draw_line(canvas, 46, 51, 125, 51);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
}
|
||||
|
||||
switch(model->bar_show) {
|
||||
case SubGhzViewReceiverBarShowLock:
|
||||
canvas_draw_icon(canvas, 64, 55, &I_Lock_7x8);
|
||||
canvas_draw_str(canvas, 74, 62, "Locked");
|
||||
break;
|
||||
case SubGhzViewReceiverBarShowToUnlockPress:
|
||||
canvas_draw_str(canvas, 44, 62, string_get_cstr(model->frequency_str));
|
||||
canvas_draw_str(canvas, 79, 62, string_get_cstr(model->preset_str));
|
||||
canvas_draw_str(canvas, 96, 62, string_get_cstr(model->history_stat_str));
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
elements_bold_rounded_frame(canvas, 14, 8, 99, 48);
|
||||
elements_multiline_text(canvas, 65, 26, "To unlock\npress:");
|
||||
canvas_draw_icon(canvas, 65, 42, &I_Pin_back_arrow_10x8);
|
||||
canvas_draw_icon(canvas, 80, 42, &I_Pin_back_arrow_10x8);
|
||||
canvas_draw_icon(canvas, 95, 42, &I_Pin_back_arrow_10x8);
|
||||
canvas_draw_icon(canvas, 16, 13, &I_WarningDolphin_45x42);
|
||||
canvas_draw_dot(canvas, 17, 61);
|
||||
break;
|
||||
case SubGhzViewReceiverBarShowUnlock:
|
||||
canvas_draw_icon(canvas, 64, 55, &I_Unlock_7x8);
|
||||
canvas_draw_str(canvas, 74, 62, "Unlocked");
|
||||
break;
|
||||
default:
|
||||
canvas_draw_str(canvas, 44, 62, string_get_cstr(model->frequency_str));
|
||||
canvas_draw_str(canvas, 79, 62, string_get_cstr(model->preset_str));
|
||||
canvas_draw_str(canvas, 96, 62, string_get_cstr(model->history_stat_str));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void subghz_view_receiver_timer_callback(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzViewReceiver* subghz_receiver = context;
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
model->bar_show = SubGhzViewReceiverBarShowDefault;
|
||||
return true;
|
||||
});
|
||||
if(subghz_receiver->lock_count < UNLOCK_CNT) {
|
||||
subghz_receiver->callback(
|
||||
SubGhzCustomEventViewReceiverOffDisplay, subghz_receiver->context);
|
||||
} else {
|
||||
subghz_receiver->lock = SubGhzLockOff;
|
||||
subghz_receiver->callback(SubGhzCustomEventViewReceiverUnlock, subghz_receiver->context);
|
||||
}
|
||||
subghz_receiver->lock_count = 0;
|
||||
}
|
||||
|
||||
bool subghz_view_receiver_input(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzViewReceiver* subghz_receiver = context;
|
||||
|
||||
if(subghz_receiver->lock == SubGhzLockOn) {
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
model->bar_show = SubGhzViewReceiverBarShowToUnlockPress;
|
||||
return true;
|
||||
});
|
||||
if(subghz_receiver->lock_count == 0) {
|
||||
furi_timer_start(subghz_receiver->timer, pdMS_TO_TICKS(1000));
|
||||
}
|
||||
if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
||||
subghz_receiver->lock_count++;
|
||||
}
|
||||
if(subghz_receiver->lock_count >= UNLOCK_CNT) {
|
||||
// subghz_receiver->callback(
|
||||
// SubGhzCustomEventViewReceiverUnlock, subghz_receiver->context);
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
model->bar_show = SubGhzViewReceiverBarShowUnlock;
|
||||
return true;
|
||||
});
|
||||
//subghz_receiver->lock = SubGhzLockOff;
|
||||
furi_timer_start(subghz_receiver->timer, pdMS_TO_TICKS(650));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
||||
subghz_receiver->callback(SubGhzCustomEventViewReceiverBack, subghz_receiver->context);
|
||||
} else if(
|
||||
event->key == InputKeyUp &&
|
||||
(event->type == InputTypeShort || event->type == InputTypeRepeat)) {
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
if(model->idx != 0) model->idx--;
|
||||
return true;
|
||||
});
|
||||
} else if(
|
||||
event->key == InputKeyDown &&
|
||||
(event->type == InputTypeShort || event->type == InputTypeRepeat)) {
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
if(model->idx != model->history_item - 1) model->idx++;
|
||||
return true;
|
||||
});
|
||||
} else if(event->key == InputKeyLeft && event->type == InputTypeShort) {
|
||||
subghz_receiver->callback(SubGhzCustomEventViewReceiverConfig, subghz_receiver->context);
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
if(model->history_item != 0) {
|
||||
subghz_receiver->callback(
|
||||
SubGhzCustomEventViewReceiverOK, subghz_receiver->context);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
subghz_view_receiver_update_offset(subghz_receiver);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void subghz_view_receiver_enter(void* context) {
|
||||
furi_assert(context);
|
||||
}
|
||||
|
||||
void subghz_view_receiver_exit(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzViewReceiver* subghz_receiver = context;
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
string_reset(model->frequency_str);
|
||||
string_reset(model->preset_str);
|
||||
string_reset(model->history_stat_str);
|
||||
for
|
||||
M_EACH(item_menu, model->history->data, SubGhzReceiverMenuItemArray_t) {
|
||||
string_clear(item_menu->item_str);
|
||||
item_menu->type = 0;
|
||||
}
|
||||
SubGhzReceiverMenuItemArray_reset(model->history->data);
|
||||
model->idx = 0;
|
||||
model->list_offset = 0;
|
||||
model->history_item = 0;
|
||||
return false;
|
||||
});
|
||||
furi_timer_stop(subghz_receiver->timer);
|
||||
}
|
||||
|
||||
SubGhzViewReceiver* subghz_view_receiver_alloc() {
|
||||
SubGhzViewReceiver* subghz_receiver = malloc(sizeof(SubGhzViewReceiver));
|
||||
|
||||
// View allocation and configuration
|
||||
subghz_receiver->view = view_alloc();
|
||||
|
||||
subghz_receiver->lock = SubGhzLockOff;
|
||||
subghz_receiver->lock_count = 0;
|
||||
view_allocate_model(
|
||||
subghz_receiver->view, ViewModelTypeLocking, sizeof(SubGhzViewReceiverModel));
|
||||
view_set_context(subghz_receiver->view, subghz_receiver);
|
||||
view_set_draw_callback(subghz_receiver->view, (ViewDrawCallback)subghz_view_receiver_draw);
|
||||
view_set_input_callback(subghz_receiver->view, subghz_view_receiver_input);
|
||||
view_set_enter_callback(subghz_receiver->view, subghz_view_receiver_enter);
|
||||
view_set_exit_callback(subghz_receiver->view, subghz_view_receiver_exit);
|
||||
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
string_init(model->frequency_str);
|
||||
string_init(model->preset_str);
|
||||
string_init(model->history_stat_str);
|
||||
model->bar_show = SubGhzViewReceiverBarShowDefault;
|
||||
model->history = malloc(sizeof(SubGhzReceiverHistory));
|
||||
SubGhzReceiverMenuItemArray_init(model->history->data);
|
||||
return true;
|
||||
});
|
||||
subghz_receiver->timer =
|
||||
furi_timer_alloc(subghz_view_receiver_timer_callback, FuriTimerTypeOnce, subghz_receiver);
|
||||
return subghz_receiver;
|
||||
}
|
||||
|
||||
void subghz_view_receiver_free(SubGhzViewReceiver* subghz_receiver) {
|
||||
furi_assert(subghz_receiver);
|
||||
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
string_clear(model->frequency_str);
|
||||
string_clear(model->preset_str);
|
||||
string_clear(model->history_stat_str);
|
||||
for
|
||||
M_EACH(item_menu, model->history->data, SubGhzReceiverMenuItemArray_t) {
|
||||
string_clear(item_menu->item_str);
|
||||
item_menu->type = 0;
|
||||
}
|
||||
SubGhzReceiverMenuItemArray_clear(model->history->data);
|
||||
free(model->history);
|
||||
return false;
|
||||
});
|
||||
furi_timer_free(subghz_receiver->timer);
|
||||
view_free(subghz_receiver->view);
|
||||
free(subghz_receiver);
|
||||
}
|
||||
|
||||
View* subghz_view_receiver_get_view(SubGhzViewReceiver* subghz_receiver) {
|
||||
furi_assert(subghz_receiver);
|
||||
return subghz_receiver->view;
|
||||
}
|
||||
|
||||
uint16_t subghz_view_receiver_get_idx_menu(SubGhzViewReceiver* subghz_receiver) {
|
||||
furi_assert(subghz_receiver);
|
||||
uint32_t idx = 0;
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
idx = model->idx;
|
||||
return false;
|
||||
});
|
||||
return idx;
|
||||
}
|
||||
|
||||
void subghz_view_receiver_set_idx_menu(SubGhzViewReceiver* subghz_receiver, uint16_t idx) {
|
||||
furi_assert(subghz_receiver);
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
model->idx = idx;
|
||||
if(model->idx > 2) model->list_offset = idx - 2;
|
||||
return true;
|
||||
});
|
||||
subghz_view_receiver_update_offset(subghz_receiver);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../helpers/subghz_types.h"
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
typedef struct SubGhzViewReceiver SubGhzViewReceiver;
|
||||
|
||||
typedef void (*SubGhzViewReceiverCallback)(SubGhzCustomEvent event, void* context);
|
||||
|
||||
void subghz_view_receiver_set_lock(SubGhzViewReceiver* subghz_receiver, SubGhzLock keyboard);
|
||||
|
||||
void subghz_view_receiver_set_callback(
|
||||
SubGhzViewReceiver* subghz_receiver,
|
||||
SubGhzViewReceiverCallback callback,
|
||||
void* context);
|
||||
|
||||
SubGhzViewReceiver* subghz_view_receiver_alloc();
|
||||
|
||||
void subghz_view_receiver_free(SubGhzViewReceiver* subghz_receiver);
|
||||
|
||||
View* subghz_view_receiver_get_view(SubGhzViewReceiver* subghz_receiver);
|
||||
|
||||
void subghz_view_receiver_add_data_statusbar(
|
||||
SubGhzViewReceiver* subghz_receiver,
|
||||
const char* frequency_str,
|
||||
const char* preset_str,
|
||||
const char* history_stat_str);
|
||||
|
||||
void subghz_view_receiver_add_item_to_menu(
|
||||
SubGhzViewReceiver* subghz_receiver,
|
||||
const char* name,
|
||||
uint8_t type);
|
||||
|
||||
uint16_t subghz_view_receiver_get_idx_menu(SubGhzViewReceiver* subghz_receiver);
|
||||
|
||||
void subghz_view_receiver_set_idx_menu(SubGhzViewReceiver* subghz_receiver, uint16_t idx);
|
||||
|
||||
void subghz_view_receiver_exit(void* context);
|
||||
@@ -0,0 +1,180 @@
|
||||
#include "subghz_frequency_analyzer.h"
|
||||
#include "../subghz_i.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <input/input.h>
|
||||
#include <notification/notification_messages.h>
|
||||
#include "../helpers/subghz_frequency_analyzer_worker.h"
|
||||
|
||||
#include <assets_icons.h>
|
||||
|
||||
typedef enum {
|
||||
SubGhzFrequencyAnalyzerStatusIDLE,
|
||||
} SubGhzFrequencyAnalyzerStatus;
|
||||
|
||||
struct SubGhzFrequencyAnalyzer {
|
||||
View* view;
|
||||
SubGhzFrequencyAnalyzerWorker* worker;
|
||||
SubGhzFrequencyAnalyzerCallback callback;
|
||||
void* context;
|
||||
bool locked;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t frequency;
|
||||
float rssi;
|
||||
} SubGhzFrequencyAnalyzerModel;
|
||||
|
||||
void subghz_frequency_analyzer_set_callback(
|
||||
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer,
|
||||
SubGhzFrequencyAnalyzerCallback callback,
|
||||
void* context) {
|
||||
furi_assert(subghz_frequency_analyzer);
|
||||
furi_assert(callback);
|
||||
subghz_frequency_analyzer->callback = callback;
|
||||
subghz_frequency_analyzer->context = context;
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_draw_rssi(Canvas* canvas, float rssi) {
|
||||
uint8_t x = 48;
|
||||
uint8_t y = 56;
|
||||
uint8_t column_number = 0;
|
||||
if(rssi) {
|
||||
rssi = (rssi + 90) / 3;
|
||||
for(size_t i = 1; i < (uint8_t)rssi; i++) {
|
||||
if(i > 20) break;
|
||||
if(i % 4) {
|
||||
column_number++;
|
||||
canvas_draw_box(canvas, x + 2 * i, y - column_number, 2, 4 + column_number);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_draw(Canvas* canvas, SubGhzFrequencyAnalyzerModel* model) {
|
||||
char buffer[64];
|
||||
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 20, 8, "Frequency Analyzer");
|
||||
|
||||
canvas_draw_str(canvas, 28, 60, "RSSI");
|
||||
subghz_frequency_analyzer_draw_rssi(canvas, model->rssi);
|
||||
|
||||
//Frequency
|
||||
canvas_set_font(canvas, FontBigNumbers);
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"%03ld.%03ld",
|
||||
model->frequency / 1000000 % 1000,
|
||||
model->frequency / 1000 % 1000);
|
||||
canvas_draw_str(canvas, 8, 35, buffer);
|
||||
canvas_draw_icon(canvas, 96, 24, &I_MHz_25x11);
|
||||
}
|
||||
|
||||
bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
if(event->key == InputKeyBack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_pair_callback(void* context, uint32_t frequency, float rssi) {
|
||||
SubGhzFrequencyAnalyzer* instance = context;
|
||||
if((rssi == 0.f) && (instance->locked)) {
|
||||
if(instance->callback) {
|
||||
instance->callback(SubGhzCustomEventSceneAnalyzerUnlock, instance->context);
|
||||
}
|
||||
} else if((rssi != 0.f) && (!instance->locked)) {
|
||||
if(instance->callback) {
|
||||
instance->callback(SubGhzCustomEventSceneAnalyzerLock, instance->context);
|
||||
}
|
||||
}
|
||||
|
||||
instance->locked = (rssi != 0.f);
|
||||
with_view_model(
|
||||
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
|
||||
model->rssi = rssi;
|
||||
model->frequency = frequency;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_enter(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzFrequencyAnalyzer* instance = context;
|
||||
|
||||
//Start worker
|
||||
instance->worker = subghz_frequency_analyzer_worker_alloc(instance->context);
|
||||
|
||||
subghz_frequency_analyzer_worker_set_pair_callback(
|
||||
instance->worker,
|
||||
(SubGhzFrequencyAnalyzerWorkerPairCallback)subghz_frequency_analyzer_pair_callback,
|
||||
instance);
|
||||
|
||||
subghz_frequency_analyzer_worker_start(instance->worker);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
|
||||
model->rssi = 0;
|
||||
model->frequency = 0;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_exit(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzFrequencyAnalyzer* instance = context;
|
||||
|
||||
//Stop worker
|
||||
if(subghz_frequency_analyzer_worker_is_running(instance->worker)) {
|
||||
subghz_frequency_analyzer_worker_stop(instance->worker);
|
||||
}
|
||||
subghz_frequency_analyzer_worker_free(instance->worker);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
|
||||
model->rssi = 0;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc() {
|
||||
SubGhzFrequencyAnalyzer* instance = malloc(sizeof(SubGhzFrequencyAnalyzer));
|
||||
|
||||
// View allocation and configuration
|
||||
instance->view = view_alloc();
|
||||
view_allocate_model(
|
||||
instance->view, ViewModelTypeLocking, sizeof(SubGhzFrequencyAnalyzerModel));
|
||||
view_set_context(instance->view, instance);
|
||||
view_set_draw_callback(instance->view, (ViewDrawCallback)subghz_frequency_analyzer_draw);
|
||||
view_set_input_callback(instance->view, subghz_frequency_analyzer_input);
|
||||
view_set_enter_callback(instance->view, subghz_frequency_analyzer_enter);
|
||||
view_set_exit_callback(instance->view, subghz_frequency_analyzer_exit);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
|
||||
model->rssi = 0;
|
||||
return true;
|
||||
});
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_free(SubGhzFrequencyAnalyzer* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
view_free(instance->view);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
View* subghz_frequency_analyzer_get_view(SubGhzFrequencyAnalyzer* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->view;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
typedef struct SubGhzFrequencyAnalyzer SubGhzFrequencyAnalyzer;
|
||||
|
||||
typedef void (*SubGhzFrequencyAnalyzerCallback)(SubGhzCustomEvent event, void* context);
|
||||
|
||||
void subghz_frequency_analyzer_set_callback(
|
||||
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer,
|
||||
SubGhzFrequencyAnalyzerCallback callback,
|
||||
void* context);
|
||||
|
||||
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc();
|
||||
|
||||
void subghz_frequency_analyzer_free(SubGhzFrequencyAnalyzer* subghz_static);
|
||||
|
||||
View* subghz_frequency_analyzer_get_view(SubGhzFrequencyAnalyzer* subghz_static);
|
||||
@@ -0,0 +1,534 @@
|
||||
#include "subghz_read_raw.h"
|
||||
#include "../subghz_i.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <input/input.h>
|
||||
#include <gui/elements.h>
|
||||
|
||||
#include <assets_icons.h>
|
||||
#define SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE 100
|
||||
#define TAG "SubGhzReadRAW"
|
||||
|
||||
struct SubGhzReadRAW {
|
||||
View* view;
|
||||
SubGhzReadRAWCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
string_t frequency_str;
|
||||
string_t preset_str;
|
||||
string_t sample_write;
|
||||
string_t file_name;
|
||||
uint8_t* rssi_history;
|
||||
bool rssi_history_end;
|
||||
uint8_t ind_write;
|
||||
uint8_t ind_sin;
|
||||
SubGhzReadRAWStatus status;
|
||||
} SubGhzReadRAWModel;
|
||||
|
||||
void subghz_read_raw_set_callback(
|
||||
SubGhzReadRAW* subghz_read_raw,
|
||||
SubGhzReadRAWCallback callback,
|
||||
void* context) {
|
||||
furi_assert(subghz_read_raw);
|
||||
furi_assert(callback);
|
||||
subghz_read_raw->callback = callback;
|
||||
subghz_read_raw->context = context;
|
||||
}
|
||||
|
||||
void subghz_read_raw_add_data_statusbar(
|
||||
SubGhzReadRAW* instance,
|
||||
const char* frequency_str,
|
||||
const char* preset_str) {
|
||||
furi_assert(instance);
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
string_set_str(model->frequency_str, frequency_str);
|
||||
string_set_str(model->preset_str, preset_str);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void subghz_read_raw_add_data_rssi(SubGhzReadRAW* instance, float rssi) {
|
||||
furi_assert(instance);
|
||||
uint8_t u_rssi = 0;
|
||||
|
||||
if(rssi < -90) {
|
||||
u_rssi = 0;
|
||||
} else {
|
||||
u_rssi = (uint8_t)((rssi + 90) / 2.7);
|
||||
}
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
model->rssi_history[model->ind_write++] = u_rssi;
|
||||
if(model->ind_write > SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE) {
|
||||
model->rssi_history_end = true;
|
||||
model->ind_write = 0;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void subghz_read_raw_update_sample_write(SubGhzReadRAW* instance, size_t sample) {
|
||||
furi_assert(instance);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
string_printf(model->sample_write, "%d spl.", sample);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void subghz_read_raw_stop_send(SubGhzReadRAW* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
switch(model->status) {
|
||||
case SubGhzReadRAWStatusTXRepeat:
|
||||
case SubGhzReadRAWStatusLoadKeyTXRepeat:
|
||||
instance->callback(SubGhzCustomEventViewReadRAWSendStart, instance->context);
|
||||
break;
|
||||
case SubGhzReadRAWStatusTX:
|
||||
model->status = SubGhzReadRAWStatusIDLE;
|
||||
break;
|
||||
case SubGhzReadRAWStatusLoadKeyTX:
|
||||
model->status = SubGhzReadRAWStatusLoadKeyIDLE;
|
||||
break;
|
||||
|
||||
default:
|
||||
FURI_LOG_W(TAG, "unknown status");
|
||||
model->status = SubGhzReadRAWStatusIDLE;
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void subghz_read_raw_update_sin(SubGhzReadRAW* instance) {
|
||||
furi_assert(instance);
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
if(model->ind_sin++ > 62) {
|
||||
model->ind_sin = 0;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
static int8_t subghz_read_raw_tab_sin(uint8_t x) {
|
||||
const uint8_t tab_sin[64] = {0, 3, 6, 9, 12, 16, 19, 22, 25, 28, 31, 34, 37,
|
||||
40, 43, 46, 49, 51, 54, 57, 60, 63, 65, 68, 71, 73,
|
||||
76, 78, 81, 83, 85, 88, 90, 92, 94, 96, 98, 100, 102,
|
||||
104, 106, 107, 109, 111, 112, 113, 115, 116, 117, 118, 120, 121,
|
||||
122, 122, 123, 124, 125, 125, 126, 126, 126, 127, 127, 127};
|
||||
|
||||
int8_t r = tab_sin[((x & 0x40) ? -x - 1 : x) & 0x3f];
|
||||
if(x & 0x80) return -r;
|
||||
return r;
|
||||
}
|
||||
|
||||
void subghz_read_raw_draw_sin(Canvas* canvas, SubGhzReadRAWModel* model) {
|
||||
#define SUBGHZ_RAW_SIN_AMPLITUDE 11
|
||||
for(int i = 113; i > 0; i--) {
|
||||
canvas_draw_line(
|
||||
canvas,
|
||||
i,
|
||||
32 - subghz_read_raw_tab_sin(i + model->ind_sin * 16) / SUBGHZ_RAW_SIN_AMPLITUDE,
|
||||
i + 1,
|
||||
32 + subghz_read_raw_tab_sin((i + model->ind_sin * 16 + 1) * 2) /
|
||||
SUBGHZ_RAW_SIN_AMPLITUDE);
|
||||
canvas_draw_line(
|
||||
canvas,
|
||||
i + 1,
|
||||
32 - subghz_read_raw_tab_sin((i + model->ind_sin * 16)) / SUBGHZ_RAW_SIN_AMPLITUDE,
|
||||
i + 2,
|
||||
32 + subghz_read_raw_tab_sin((i + model->ind_sin * 16 + 1) * 2) /
|
||||
SUBGHZ_RAW_SIN_AMPLITUDE);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_read_raw_draw_scale(Canvas* canvas, SubGhzReadRAWModel* model) {
|
||||
#define SUBGHZ_RAW_TOP_SCALE 14
|
||||
#define SUBGHZ_RAW_END_SCALE 115
|
||||
|
||||
if(model->rssi_history_end == false) {
|
||||
for(int i = SUBGHZ_RAW_END_SCALE; i > 0; i -= 15) {
|
||||
canvas_draw_line(canvas, i, SUBGHZ_RAW_TOP_SCALE, i, SUBGHZ_RAW_TOP_SCALE + 4);
|
||||
canvas_draw_line(canvas, i - 5, SUBGHZ_RAW_TOP_SCALE, i - 5, SUBGHZ_RAW_TOP_SCALE + 2);
|
||||
canvas_draw_line(
|
||||
canvas, i - 10, SUBGHZ_RAW_TOP_SCALE, i - 10, SUBGHZ_RAW_TOP_SCALE + 2);
|
||||
}
|
||||
} else {
|
||||
for(int i = SUBGHZ_RAW_END_SCALE - model->ind_write % 15; i > -15; i -= 15) {
|
||||
canvas_draw_line(canvas, i, SUBGHZ_RAW_TOP_SCALE, i, SUBGHZ_RAW_TOP_SCALE + 4);
|
||||
if(SUBGHZ_RAW_END_SCALE > i + 5)
|
||||
canvas_draw_line(
|
||||
canvas, i + 5, SUBGHZ_RAW_TOP_SCALE, i + 5, SUBGHZ_RAW_TOP_SCALE + 2);
|
||||
if(SUBGHZ_RAW_END_SCALE > i + 10)
|
||||
canvas_draw_line(
|
||||
canvas, i + 10, SUBGHZ_RAW_TOP_SCALE, i + 10, SUBGHZ_RAW_TOP_SCALE + 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_read_raw_draw_rssi(Canvas* canvas, SubGhzReadRAWModel* model) {
|
||||
int ind = 0;
|
||||
int base = 0;
|
||||
if(model->rssi_history_end == false) {
|
||||
for(int i = model->ind_write; i >= 0; i--) {
|
||||
canvas_draw_line(canvas, i, 47, i, 47 - model->rssi_history[i]);
|
||||
}
|
||||
if(model->ind_write > 3) {
|
||||
canvas_draw_line(canvas, model->ind_write, 47, model->ind_write, 13);
|
||||
canvas_draw_line(canvas, model->ind_write - 2, 12, model->ind_write + 2, 12);
|
||||
canvas_draw_line(canvas, model->ind_write - 1, 13, model->ind_write + 1, 13);
|
||||
}
|
||||
} else {
|
||||
base = SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE - model->ind_write;
|
||||
for(int i = SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE; i >= 0; i--) {
|
||||
ind = i - base;
|
||||
if(ind < 0) ind += SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE;
|
||||
canvas_draw_line(canvas, i, 47, i, 47 - model->rssi_history[ind]);
|
||||
}
|
||||
canvas_draw_line(
|
||||
canvas, SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE, 47, SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE, 13);
|
||||
canvas_draw_line(
|
||||
canvas,
|
||||
SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE - 2,
|
||||
12,
|
||||
SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE + 2,
|
||||
12);
|
||||
canvas_draw_line(
|
||||
canvas,
|
||||
SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE - 1,
|
||||
13,
|
||||
SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE + 1,
|
||||
13);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_read_raw_draw(Canvas* canvas, SubGhzReadRAWModel* model) {
|
||||
uint8_t graphics_mode = 1;
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, 5, 7, string_get_cstr(model->frequency_str));
|
||||
canvas_draw_str(canvas, 40, 7, string_get_cstr(model->preset_str));
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 126, 0, AlignRight, AlignTop, string_get_cstr(model->sample_write));
|
||||
|
||||
canvas_draw_line(canvas, 0, 14, 115, 14);
|
||||
canvas_draw_line(canvas, 0, 48, 115, 48);
|
||||
canvas_draw_line(canvas, 115, 14, 115, 48);
|
||||
|
||||
switch(model->status) {
|
||||
case SubGhzReadRAWStatusIDLE:
|
||||
elements_button_left(canvas, "Erase");
|
||||
elements_button_center(canvas, "Send");
|
||||
elements_button_right(canvas, "Save");
|
||||
break;
|
||||
case SubGhzReadRAWStatusLoadKeyIDLE:
|
||||
elements_button_left(canvas, "New");
|
||||
elements_button_center(canvas, "Send");
|
||||
elements_button_right(canvas, "More");
|
||||
elements_text_box(
|
||||
canvas,
|
||||
4,
|
||||
20,
|
||||
110,
|
||||
30,
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
string_get_cstr(model->file_name),
|
||||
true);
|
||||
break;
|
||||
|
||||
case SubGhzReadRAWStatusTX:
|
||||
case SubGhzReadRAWStatusTXRepeat:
|
||||
case SubGhzReadRAWStatusLoadKeyTX:
|
||||
case SubGhzReadRAWStatusLoadKeyTXRepeat:
|
||||
graphics_mode = 0;
|
||||
elements_button_center(canvas, "Send");
|
||||
break;
|
||||
|
||||
case SubGhzReadRAWStatusStart:
|
||||
elements_button_left(canvas, "Config");
|
||||
elements_button_center(canvas, "REC");
|
||||
break;
|
||||
|
||||
default:
|
||||
elements_button_center(canvas, "Stop");
|
||||
break;
|
||||
}
|
||||
|
||||
if(graphics_mode == 0) {
|
||||
subghz_read_raw_draw_sin(canvas, model);
|
||||
} else {
|
||||
subghz_read_raw_draw_rssi(canvas, model);
|
||||
subghz_read_raw_draw_scale(canvas, model);
|
||||
canvas_set_font_direction(canvas, CanvasDirectionBottomToTop);
|
||||
canvas_draw_str(canvas, 126, 40, "RSSI");
|
||||
canvas_set_font_direction(canvas, CanvasDirectionLeftToRight);
|
||||
}
|
||||
}
|
||||
|
||||
bool subghz_read_raw_input(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzReadRAW* instance = context;
|
||||
|
||||
if((event->key == InputKeyOk) &&
|
||||
(event->type == InputTypeLong || event->type == InputTypeRepeat)) {
|
||||
//we check that if we hold the transfer button,
|
||||
//further check of events is not needed, we exit
|
||||
return false;
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypePress) {
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
uint8_t ret = false;
|
||||
switch(model->status) {
|
||||
case SubGhzReadRAWStatusIDLE:
|
||||
// Start TX
|
||||
instance->callback(SubGhzCustomEventViewReadRAWSendStart, instance->context);
|
||||
model->status = SubGhzReadRAWStatusTXRepeat;
|
||||
ret = true;
|
||||
break;
|
||||
case SubGhzReadRAWStatusTX:
|
||||
// Start TXRepeat
|
||||
model->status = SubGhzReadRAWStatusTXRepeat;
|
||||
break;
|
||||
case SubGhzReadRAWStatusLoadKeyIDLE:
|
||||
// Start Load Key TX
|
||||
instance->callback(SubGhzCustomEventViewReadRAWSendStart, instance->context);
|
||||
model->status = SubGhzReadRAWStatusLoadKeyTXRepeat;
|
||||
ret = true;
|
||||
break;
|
||||
case SubGhzReadRAWStatusLoadKeyTX:
|
||||
// Start Load Key TXRepeat
|
||||
model->status = SubGhzReadRAWStatusLoadKeyTXRepeat;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypeRelease) {
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
if(model->status == SubGhzReadRAWStatusTXRepeat) {
|
||||
// Stop repeat TX
|
||||
model->status = SubGhzReadRAWStatusTX;
|
||||
} else if(model->status == SubGhzReadRAWStatusLoadKeyTXRepeat) {
|
||||
// Stop repeat TX
|
||||
model->status = SubGhzReadRAWStatusLoadKeyTX;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
} else if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
switch(model->status) {
|
||||
case SubGhzReadRAWStatusREC:
|
||||
//Stop REC
|
||||
instance->callback(SubGhzCustomEventViewReadRAWIDLE, instance->context);
|
||||
model->status = SubGhzReadRAWStatusIDLE;
|
||||
break;
|
||||
case SubGhzReadRAWStatusLoadKeyTX:
|
||||
//Stop TxRx
|
||||
instance->callback(SubGhzCustomEventViewReadRAWTXRXStop, instance->context);
|
||||
model->status = SubGhzReadRAWStatusLoadKeyIDLE;
|
||||
break;
|
||||
case SubGhzReadRAWStatusTX:
|
||||
//Stop TxRx
|
||||
instance->callback(SubGhzCustomEventViewReadRAWTXRXStop, instance->context);
|
||||
model->status = SubGhzReadRAWStatusIDLE;
|
||||
break;
|
||||
case SubGhzReadRAWStatusLoadKeyIDLE:
|
||||
//Exit
|
||||
instance->callback(SubGhzCustomEventViewReadRAWBack, instance->context);
|
||||
break;
|
||||
|
||||
default:
|
||||
//Exit
|
||||
instance->callback(SubGhzCustomEventViewReadRAWBack, instance->context);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
} else if(event->key == InputKeyLeft && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
if(model->status == SubGhzReadRAWStatusStart) {
|
||||
//Config
|
||||
instance->callback(SubGhzCustomEventViewReadRAWConfig, instance->context);
|
||||
} else if(
|
||||
(model->status == SubGhzReadRAWStatusIDLE) ||
|
||||
(model->status == SubGhzReadRAWStatusLoadKeyIDLE)) {
|
||||
//Erase
|
||||
model->status = SubGhzReadRAWStatusStart;
|
||||
model->rssi_history_end = false;
|
||||
model->ind_write = 0;
|
||||
string_set_str(model->sample_write, "0 spl.");
|
||||
string_reset(model->file_name);
|
||||
instance->callback(SubGhzCustomEventViewReadRAWErase, instance->context);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
} else if(event->key == InputKeyRight && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
if(model->status == SubGhzReadRAWStatusIDLE) {
|
||||
//Save
|
||||
instance->callback(SubGhzCustomEventViewReadRAWSave, instance->context);
|
||||
} else if(model->status == SubGhzReadRAWStatusLoadKeyIDLE) {
|
||||
//More
|
||||
instance->callback(SubGhzCustomEventViewReadRAWMore, instance->context);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
if(model->status == SubGhzReadRAWStatusStart) {
|
||||
//Record
|
||||
instance->callback(SubGhzCustomEventViewReadRAWREC, instance->context);
|
||||
model->status = SubGhzReadRAWStatusREC;
|
||||
model->ind_write = 0;
|
||||
model->rssi_history_end = false;
|
||||
} else if(model->status == SubGhzReadRAWStatusREC) {
|
||||
//Stop
|
||||
instance->callback(SubGhzCustomEventViewReadRAWIDLE, instance->context);
|
||||
model->status = SubGhzReadRAWStatusIDLE;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void subghz_read_raw_set_status(
|
||||
SubGhzReadRAW* instance,
|
||||
SubGhzReadRAWStatus status,
|
||||
const char* file_name) {
|
||||
furi_assert(instance);
|
||||
|
||||
switch(status) {
|
||||
case SubGhzReadRAWStatusStart:
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
model->status = SubGhzReadRAWStatusStart;
|
||||
model->rssi_history_end = false;
|
||||
model->ind_write = 0;
|
||||
string_reset(model->file_name);
|
||||
string_set_str(model->sample_write, "0 spl.");
|
||||
return true;
|
||||
});
|
||||
break;
|
||||
case SubGhzReadRAWStatusIDLE:
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
model->status = SubGhzReadRAWStatusIDLE;
|
||||
return true;
|
||||
});
|
||||
break;
|
||||
case SubGhzReadRAWStatusLoadKeyTX:
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
model->status = SubGhzReadRAWStatusLoadKeyIDLE;
|
||||
model->rssi_history_end = false;
|
||||
model->ind_write = 0;
|
||||
string_set_str(model->file_name, file_name);
|
||||
string_set_str(model->sample_write, "RAW");
|
||||
return true;
|
||||
});
|
||||
break;
|
||||
case SubGhzReadRAWStatusSaveKey:
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
model->status = SubGhzReadRAWStatusLoadKeyIDLE;
|
||||
if(!model->ind_write) {
|
||||
string_set_str(model->file_name, file_name);
|
||||
string_set_str(model->sample_write, "RAW");
|
||||
} else {
|
||||
string_reset(model->file_name);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
FURI_LOG_W(TAG, "unknown status");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_read_raw_enter(void* context) {
|
||||
furi_assert(context);
|
||||
//SubGhzReadRAW* instance = context;
|
||||
}
|
||||
|
||||
void subghz_read_raw_exit(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzReadRAW* instance = context;
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
if(model->status != SubGhzReadRAWStatusIDLE &&
|
||||
model->status != SubGhzReadRAWStatusStart &&
|
||||
model->status != SubGhzReadRAWStatusLoadKeyIDLE) {
|
||||
instance->callback(SubGhzCustomEventViewReadRAWIDLE, instance->context);
|
||||
model->status = SubGhzReadRAWStatusStart;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
SubGhzReadRAW* subghz_read_raw_alloc() {
|
||||
SubGhzReadRAW* instance = malloc(sizeof(SubGhzReadRAW));
|
||||
|
||||
// View allocation and configuration
|
||||
instance->view = view_alloc();
|
||||
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(SubGhzReadRAWModel));
|
||||
view_set_context(instance->view, instance);
|
||||
view_set_draw_callback(instance->view, (ViewDrawCallback)subghz_read_raw_draw);
|
||||
view_set_input_callback(instance->view, subghz_read_raw_input);
|
||||
view_set_enter_callback(instance->view, subghz_read_raw_enter);
|
||||
view_set_exit_callback(instance->view, subghz_read_raw_exit);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
string_init(model->frequency_str);
|
||||
string_init(model->preset_str);
|
||||
string_init(model->sample_write);
|
||||
string_init(model->file_name);
|
||||
model->rssi_history = malloc(SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE * sizeof(uint8_t));
|
||||
return true;
|
||||
});
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_read_raw_free(SubGhzReadRAW* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
string_clear(model->frequency_str);
|
||||
string_clear(model->preset_str);
|
||||
string_clear(model->sample_write);
|
||||
string_clear(model->file_name);
|
||||
free(model->rssi_history);
|
||||
return true;
|
||||
});
|
||||
view_free(instance->view);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
View* subghz_read_raw_get_view(SubGhzReadRAW* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->view;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
typedef struct SubGhzReadRAW SubGhzReadRAW;
|
||||
|
||||
typedef void (*SubGhzReadRAWCallback)(SubGhzCustomEvent event, void* context);
|
||||
|
||||
typedef enum {
|
||||
SubGhzReadRAWStatusStart,
|
||||
SubGhzReadRAWStatusIDLE,
|
||||
SubGhzReadRAWStatusREC,
|
||||
SubGhzReadRAWStatusTX,
|
||||
SubGhzReadRAWStatusTXRepeat,
|
||||
|
||||
SubGhzReadRAWStatusLoadKeyIDLE,
|
||||
SubGhzReadRAWStatusLoadKeyTX,
|
||||
SubGhzReadRAWStatusLoadKeyTXRepeat,
|
||||
SubGhzReadRAWStatusSaveKey,
|
||||
} SubGhzReadRAWStatus;
|
||||
|
||||
void subghz_read_raw_set_callback(
|
||||
SubGhzReadRAW* subghz_read_raw,
|
||||
SubGhzReadRAWCallback callback,
|
||||
void* context);
|
||||
|
||||
SubGhzReadRAW* subghz_read_raw_alloc();
|
||||
|
||||
void subghz_read_raw_free(SubGhzReadRAW* subghz_static);
|
||||
|
||||
void subghz_read_raw_add_data_statusbar(
|
||||
SubGhzReadRAW* instance,
|
||||
const char* frequency_str,
|
||||
const char* preset_str);
|
||||
|
||||
void subghz_read_raw_update_sample_write(SubGhzReadRAW* instance, size_t sample);
|
||||
|
||||
void subghz_read_raw_stop_send(SubGhzReadRAW* instance);
|
||||
|
||||
void subghz_read_raw_update_sin(SubGhzReadRAW* instance);
|
||||
|
||||
void subghz_read_raw_add_data_rssi(SubGhzReadRAW* instance, float rssi);
|
||||
|
||||
void subghz_read_raw_set_status(
|
||||
SubGhzReadRAW* instance,
|
||||
SubGhzReadRAWStatus status,
|
||||
const char* file_name);
|
||||
|
||||
View* subghz_read_raw_get_view(SubGhzReadRAW* subghz_static);
|
||||
@@ -0,0 +1,213 @@
|
||||
#include "subghz_test_carrier.h"
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_testing.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <input/input.h>
|
||||
|
||||
struct SubGhzTestCarrier {
|
||||
View* view;
|
||||
FuriTimer* timer;
|
||||
SubGhzTestCarrierCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
SubGhzTestCarrierModelStatusRx,
|
||||
SubGhzTestCarrierModelStatusTx,
|
||||
} SubGhzTestCarrierModelStatus;
|
||||
|
||||
typedef struct {
|
||||
uint8_t frequency;
|
||||
uint32_t real_frequency;
|
||||
FuriHalSubGhzPath path;
|
||||
float rssi;
|
||||
SubGhzTestCarrierModelStatus status;
|
||||
} SubGhzTestCarrierModel;
|
||||
|
||||
void subghz_test_carrier_set_callback(
|
||||
SubGhzTestCarrier* subghz_test_carrier,
|
||||
SubGhzTestCarrierCallback callback,
|
||||
void* context) {
|
||||
furi_assert(subghz_test_carrier);
|
||||
furi_assert(callback);
|
||||
subghz_test_carrier->callback = callback;
|
||||
subghz_test_carrier->context = context;
|
||||
}
|
||||
|
||||
void subghz_test_carrier_draw(Canvas* canvas, SubGhzTestCarrierModel* model) {
|
||||
char buffer[64];
|
||||
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 0, 8, "CC1101 Basic Test");
|
||||
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
// Frequency
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"Freq: %03ld.%03ld.%03ld Hz",
|
||||
model->real_frequency / 1000000 % 1000,
|
||||
model->real_frequency / 1000 % 1000,
|
||||
model->real_frequency % 1000);
|
||||
canvas_draw_str(canvas, 0, 20, buffer);
|
||||
// Path
|
||||
char* path_name = "Unknown";
|
||||
if(model->path == FuriHalSubGhzPathIsolate) {
|
||||
path_name = "isolate";
|
||||
} else if(model->path == FuriHalSubGhzPath433) {
|
||||
path_name = "433MHz";
|
||||
} else if(model->path == FuriHalSubGhzPath315) {
|
||||
path_name = "315MHz";
|
||||
} else if(model->path == FuriHalSubGhzPath868) {
|
||||
path_name = "868MHz";
|
||||
}
|
||||
snprintf(buffer, sizeof(buffer), "Path: %d - %s", model->path, path_name);
|
||||
canvas_draw_str(canvas, 0, 31, buffer);
|
||||
if(model->status == SubGhzTestCarrierModelStatusRx) {
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"RSSI: %ld.%ld dBm",
|
||||
(int32_t)(model->rssi),
|
||||
(int32_t)fabs(model->rssi * 10) % 10);
|
||||
canvas_draw_str(canvas, 0, 42, buffer);
|
||||
} else {
|
||||
canvas_draw_str(canvas, 0, 42, "TX");
|
||||
}
|
||||
}
|
||||
|
||||
bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestCarrier* subghz_test_carrier = context;
|
||||
|
||||
if(event->key == InputKeyBack || event->type != InputTypeShort) {
|
||||
return false;
|
||||
}
|
||||
|
||||
with_view_model(
|
||||
subghz_test_carrier->view, (SubGhzTestCarrierModel * model) {
|
||||
furi_hal_subghz_idle();
|
||||
|
||||
if(event->key == InputKeyLeft) {
|
||||
if(model->frequency > 0) model->frequency--;
|
||||
} else if(event->key == InputKeyRight) {
|
||||
if(model->frequency < subghz_frequencies_count_testing - 1) model->frequency++;
|
||||
} else if(event->key == InputKeyDown) {
|
||||
if(model->path > 0) model->path--;
|
||||
} else if(event->key == InputKeyUp) {
|
||||
if(model->path < FuriHalSubGhzPath868) model->path++;
|
||||
} else if(event->key == InputKeyOk) {
|
||||
if(model->status == SubGhzTestCarrierModelStatusTx) {
|
||||
model->status = SubGhzTestCarrierModelStatusRx;
|
||||
} else {
|
||||
model->status = SubGhzTestCarrierModelStatusTx;
|
||||
}
|
||||
}
|
||||
|
||||
model->real_frequency =
|
||||
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
|
||||
furi_hal_subghz_set_path(model->path);
|
||||
|
||||
if(model->status == SubGhzTestCarrierModelStatusRx) {
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_subghz_rx();
|
||||
} else {
|
||||
furi_hal_gpio_init(
|
||||
&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_write(&gpio_cc1101_g0, true);
|
||||
if(!furi_hal_subghz_tx()) {
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
subghz_test_carrier->callback(
|
||||
SubGhzTestCarrierEventOnlyRx, subghz_test_carrier->context);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void subghz_test_carrier_enter(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestCarrier* subghz_test_carrier = context;
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
with_view_model(
|
||||
subghz_test_carrier->view, (SubGhzTestCarrierModel * model) {
|
||||
model->frequency = subghz_frequencies_433_92_testing; // 433
|
||||
model->real_frequency =
|
||||
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
|
||||
model->path = FuriHalSubGhzPathIsolate; // isolate
|
||||
model->rssi = 0.0f;
|
||||
model->status = SubGhzTestCarrierModelStatusRx;
|
||||
return true;
|
||||
});
|
||||
|
||||
furi_hal_subghz_rx();
|
||||
|
||||
furi_timer_start(subghz_test_carrier->timer, furi_kernel_get_tick_frequency() / 4);
|
||||
}
|
||||
|
||||
void subghz_test_carrier_exit(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestCarrier* subghz_test_carrier = context;
|
||||
|
||||
furi_timer_stop(subghz_test_carrier->timer);
|
||||
|
||||
// Reinitialize IC to default state
|
||||
furi_hal_subghz_sleep();
|
||||
}
|
||||
|
||||
void subghz_test_carrier_rssi_timer_callback(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestCarrier* subghz_test_carrier = context;
|
||||
|
||||
with_view_model(
|
||||
subghz_test_carrier->view, (SubGhzTestCarrierModel * model) {
|
||||
if(model->status == SubGhzTestCarrierModelStatusRx) {
|
||||
model->rssi = furi_hal_subghz_get_rssi();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
SubGhzTestCarrier* subghz_test_carrier_alloc() {
|
||||
SubGhzTestCarrier* subghz_test_carrier = malloc(sizeof(SubGhzTestCarrier));
|
||||
|
||||
// View allocation and configuration
|
||||
subghz_test_carrier->view = view_alloc();
|
||||
view_allocate_model(
|
||||
subghz_test_carrier->view, ViewModelTypeLocking, sizeof(SubGhzTestCarrierModel));
|
||||
view_set_context(subghz_test_carrier->view, subghz_test_carrier);
|
||||
view_set_draw_callback(subghz_test_carrier->view, (ViewDrawCallback)subghz_test_carrier_draw);
|
||||
view_set_input_callback(subghz_test_carrier->view, subghz_test_carrier_input);
|
||||
view_set_enter_callback(subghz_test_carrier->view, subghz_test_carrier_enter);
|
||||
view_set_exit_callback(subghz_test_carrier->view, subghz_test_carrier_exit);
|
||||
|
||||
subghz_test_carrier->timer = furi_timer_alloc(
|
||||
subghz_test_carrier_rssi_timer_callback, FuriTimerTypePeriodic, subghz_test_carrier);
|
||||
|
||||
return subghz_test_carrier;
|
||||
}
|
||||
|
||||
void subghz_test_carrier_free(SubGhzTestCarrier* subghz_test_carrier) {
|
||||
furi_assert(subghz_test_carrier);
|
||||
furi_timer_free(subghz_test_carrier->timer);
|
||||
view_free(subghz_test_carrier->view);
|
||||
free(subghz_test_carrier);
|
||||
}
|
||||
|
||||
View* subghz_test_carrier_get_view(SubGhzTestCarrier* subghz_test_carrier) {
|
||||
furi_assert(subghz_test_carrier);
|
||||
return subghz_test_carrier->view;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
|
||||
typedef enum {
|
||||
SubGhzTestCarrierEventOnlyRx,
|
||||
} SubGhzTestCarrierEvent;
|
||||
|
||||
typedef struct SubGhzTestCarrier SubGhzTestCarrier;
|
||||
|
||||
typedef void (*SubGhzTestCarrierCallback)(SubGhzTestCarrierEvent event, void* context);
|
||||
|
||||
void subghz_test_carrier_set_callback(
|
||||
SubGhzTestCarrier* subghz_test_carrier,
|
||||
SubGhzTestCarrierCallback callback,
|
||||
void* context);
|
||||
|
||||
SubGhzTestCarrier* subghz_test_carrier_alloc();
|
||||
|
||||
void subghz_test_carrier_free(SubGhzTestCarrier* subghz_test_carrier);
|
||||
|
||||
View* subghz_test_carrier_get_view(SubGhzTestCarrier* subghz_test_carrier);
|
||||
@@ -0,0 +1,269 @@
|
||||
#include "subghz_test_packet.h"
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_testing.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <input/input.h>
|
||||
#include <toolbox/level_duration.h>
|
||||
#include <lib/subghz/protocols/princeton_for_testing.h>
|
||||
|
||||
#define SUBGHZ_TEST_PACKET_COUNT 500
|
||||
|
||||
struct SubGhzTestPacket {
|
||||
View* view;
|
||||
FuriTimer* timer;
|
||||
|
||||
SubGhzDecoderPrinceton* decoder;
|
||||
SubGhzEncoderPrinceton* encoder;
|
||||
volatile size_t packet_rx;
|
||||
SubGhzTestPacketCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
SubGhzTestPacketModelStatusRx,
|
||||
SubGhzTestPacketModelStatusOnlyRx,
|
||||
SubGhzTestPacketModelStatusTx,
|
||||
} SubGhzTestPacketModelStatus;
|
||||
|
||||
typedef struct {
|
||||
uint8_t frequency;
|
||||
uint32_t real_frequency;
|
||||
FuriHalSubGhzPath path;
|
||||
float rssi;
|
||||
size_t packets;
|
||||
SubGhzTestPacketModelStatus status;
|
||||
} SubGhzTestPacketModel;
|
||||
|
||||
volatile bool subghz_test_packet_overrun = false;
|
||||
|
||||
void subghz_test_packet_set_callback(
|
||||
SubGhzTestPacket* subghz_test_packet,
|
||||
SubGhzTestPacketCallback callback,
|
||||
void* context) {
|
||||
furi_assert(subghz_test_packet);
|
||||
furi_assert(callback);
|
||||
subghz_test_packet->callback = callback;
|
||||
subghz_test_packet->context = context;
|
||||
}
|
||||
|
||||
static void subghz_test_packet_rx_callback(bool level, uint32_t duration, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestPacket* instance = context;
|
||||
subghz_decoder_princeton_for_testing_parse(instance->decoder, level, duration);
|
||||
}
|
||||
|
||||
//todo
|
||||
static void subghz_test_packet_rx_pt_callback(SubGhzDecoderPrinceton* parser, void* context) {
|
||||
UNUSED(parser);
|
||||
furi_assert(context);
|
||||
SubGhzTestPacket* instance = context;
|
||||
instance->packet_rx++;
|
||||
}
|
||||
|
||||
static void subghz_test_packet_rssi_timer_callback(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestPacket* instance = context;
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestPacketModel * model) {
|
||||
if(model->status == SubGhzTestPacketModelStatusRx) {
|
||||
model->rssi = furi_hal_subghz_get_rssi();
|
||||
model->packets = instance->packet_rx;
|
||||
} else if(model->status == SubGhzTestPacketModelStatusTx) {
|
||||
model->packets =
|
||||
SUBGHZ_TEST_PACKET_COUNT -
|
||||
subghz_encoder_princeton_for_testing_get_repeat_left(instance->encoder);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
static void subghz_test_packet_draw(Canvas* canvas, SubGhzTestPacketModel* model) {
|
||||
char buffer[64];
|
||||
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 0, 8, "CC1101 Packet Test");
|
||||
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
// Frequency
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"Freq: %03ld.%03ld.%03ld Hz",
|
||||
model->real_frequency / 1000000 % 1000,
|
||||
model->real_frequency / 1000 % 1000,
|
||||
model->real_frequency % 1000);
|
||||
canvas_draw_str(canvas, 0, 20, buffer);
|
||||
// Path
|
||||
char* path_name = "Unknown";
|
||||
if(model->path == FuriHalSubGhzPathIsolate) {
|
||||
path_name = "isolate";
|
||||
} else if(model->path == FuriHalSubGhzPath433) {
|
||||
path_name = "433MHz";
|
||||
} else if(model->path == FuriHalSubGhzPath315) {
|
||||
path_name = "315MHz";
|
||||
} else if(model->path == FuriHalSubGhzPath868) {
|
||||
path_name = "868MHz";
|
||||
}
|
||||
snprintf(buffer, sizeof(buffer), "Path: %d - %s", model->path, path_name);
|
||||
canvas_draw_str(canvas, 0, 31, buffer);
|
||||
|
||||
snprintf(buffer, sizeof(buffer), "Packets: %d", model->packets);
|
||||
canvas_draw_str(canvas, 0, 42, buffer);
|
||||
|
||||
if(model->status == SubGhzTestPacketModelStatusRx) {
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"RSSI: %ld.%ld dBm",
|
||||
(int32_t)(model->rssi),
|
||||
(int32_t)fabs(model->rssi * 10) % 10);
|
||||
canvas_draw_str(canvas, 0, 53, buffer);
|
||||
} else {
|
||||
canvas_draw_str(canvas, 0, 53, "TX");
|
||||
}
|
||||
}
|
||||
|
||||
static bool subghz_test_packet_input(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestPacket* instance = context;
|
||||
|
||||
if(event->key == InputKeyBack || event->type != InputTypeShort) {
|
||||
return false;
|
||||
}
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestPacketModel * model) {
|
||||
if(model->status == SubGhzTestPacketModelStatusRx) {
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
} else if(model->status == SubGhzTestPacketModelStatusTx) {
|
||||
subghz_encoder_princeton_for_testing_stop(instance->encoder, furi_get_tick());
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
}
|
||||
|
||||
if(event->key == InputKeyLeft) {
|
||||
if(model->frequency > 0) model->frequency--;
|
||||
} else if(event->key == InputKeyRight) {
|
||||
if(model->frequency < subghz_frequencies_count_testing - 1) model->frequency++;
|
||||
} else if(event->key == InputKeyDown) {
|
||||
if(model->path > 0) model->path--;
|
||||
} else if(event->key == InputKeyUp) {
|
||||
if(model->path < FuriHalSubGhzPath868) model->path++;
|
||||
} else if(event->key == InputKeyOk) {
|
||||
if(model->status == SubGhzTestPacketModelStatusRx) {
|
||||
model->status = SubGhzTestPacketModelStatusTx;
|
||||
} else {
|
||||
model->status = SubGhzTestPacketModelStatusRx;
|
||||
}
|
||||
}
|
||||
|
||||
model->real_frequency =
|
||||
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
|
||||
furi_hal_subghz_set_path(model->path);
|
||||
|
||||
if(model->status == SubGhzTestPacketModelStatusRx) {
|
||||
furi_hal_subghz_start_async_rx(subghz_test_packet_rx_callback, instance);
|
||||
} else {
|
||||
subghz_encoder_princeton_for_testing_set(
|
||||
instance->encoder,
|
||||
0x00AABBCC,
|
||||
SUBGHZ_TEST_PACKET_COUNT,
|
||||
subghz_frequencies_testing[model->frequency]);
|
||||
if(!furi_hal_subghz_start_async_tx(
|
||||
subghz_encoder_princeton_for_testing_yield, instance->encoder)) {
|
||||
model->status = SubGhzTestPacketModelStatusOnlyRx;
|
||||
instance->callback(SubGhzTestPacketEventOnlyRx, instance->context);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void subghz_test_packet_enter(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestPacket* instance = context;
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestPacketModel * model) {
|
||||
model->frequency = subghz_frequencies_433_92_testing;
|
||||
model->real_frequency =
|
||||
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
|
||||
model->path = FuriHalSubGhzPathIsolate; // isolate
|
||||
model->rssi = 0.0f;
|
||||
model->status = SubGhzTestPacketModelStatusRx;
|
||||
return true;
|
||||
});
|
||||
|
||||
furi_hal_subghz_start_async_rx(subghz_test_packet_rx_callback, instance);
|
||||
|
||||
furi_timer_start(instance->timer, furi_kernel_get_tick_frequency() / 4);
|
||||
}
|
||||
|
||||
void subghz_test_packet_exit(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestPacket* instance = context;
|
||||
|
||||
furi_timer_stop(instance->timer);
|
||||
|
||||
// Reinitialize IC to default state
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestPacketModel * model) {
|
||||
if(model->status == SubGhzTestPacketModelStatusRx) {
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
} else if(model->status == SubGhzTestPacketModelStatusTx) {
|
||||
subghz_encoder_princeton_for_testing_stop(instance->encoder, furi_get_tick());
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
furi_hal_subghz_sleep();
|
||||
}
|
||||
|
||||
SubGhzTestPacket* subghz_test_packet_alloc() {
|
||||
SubGhzTestPacket* instance = malloc(sizeof(SubGhzTestPacket));
|
||||
|
||||
// View allocation and configuration
|
||||
instance->view = view_alloc();
|
||||
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(SubGhzTestPacketModel));
|
||||
view_set_context(instance->view, instance);
|
||||
view_set_draw_callback(instance->view, (ViewDrawCallback)subghz_test_packet_draw);
|
||||
view_set_input_callback(instance->view, subghz_test_packet_input);
|
||||
view_set_enter_callback(instance->view, subghz_test_packet_enter);
|
||||
view_set_exit_callback(instance->view, subghz_test_packet_exit);
|
||||
|
||||
instance->timer =
|
||||
furi_timer_alloc(subghz_test_packet_rssi_timer_callback, FuriTimerTypePeriodic, instance);
|
||||
|
||||
instance->decoder = subghz_decoder_princeton_for_testing_alloc();
|
||||
subghz_decoder_princeton_for_testing_set_callback(
|
||||
instance->decoder, subghz_test_packet_rx_pt_callback, instance);
|
||||
instance->encoder = subghz_encoder_princeton_for_testing_alloc();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_test_packet_free(SubGhzTestPacket* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
subghz_decoder_princeton_for_testing_free(instance->decoder);
|
||||
subghz_encoder_princeton_for_testing_free(instance->encoder);
|
||||
|
||||
furi_timer_free(instance->timer);
|
||||
view_free(instance->view);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
View* subghz_test_packet_get_view(SubGhzTestPacket* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->view;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
|
||||
typedef enum {
|
||||
SubGhzTestPacketEventOnlyRx,
|
||||
} SubGhzTestPacketEvent;
|
||||
|
||||
typedef struct SubGhzTestPacket SubGhzTestPacket;
|
||||
|
||||
typedef void (*SubGhzTestPacketCallback)(SubGhzTestPacketEvent event, void* context);
|
||||
|
||||
void subghz_test_packet_set_callback(
|
||||
SubGhzTestPacket* subghz_test_packet,
|
||||
SubGhzTestPacketCallback callback,
|
||||
void* context);
|
||||
|
||||
SubGhzTestPacket* subghz_test_packet_alloc();
|
||||
|
||||
void subghz_test_packet_free(SubGhzTestPacket* subghz_test_packet);
|
||||
|
||||
View* subghz_test_packet_get_view(SubGhzTestPacket* subghz_test_packet);
|
||||
@@ -0,0 +1,191 @@
|
||||
#include "subghz_test_static.h"
|
||||
#include "../subghz_i.h"
|
||||
#include "../helpers/subghz_testing.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <input/input.h>
|
||||
#include <notification/notification_messages.h>
|
||||
#include <lib/subghz/protocols/princeton_for_testing.h>
|
||||
|
||||
#define TAG "SubGhzTestStatic"
|
||||
|
||||
typedef enum {
|
||||
SubGhzTestStaticStatusIDLE,
|
||||
SubGhzTestStaticStatusTX,
|
||||
} SubGhzTestStaticStatus;
|
||||
|
||||
static const uint32_t subghz_test_static_keys[] = {
|
||||
0x0074BADE,
|
||||
0x0074BADD,
|
||||
0x0074BADB,
|
||||
0x00E34A4E,
|
||||
};
|
||||
|
||||
struct SubGhzTestStatic {
|
||||
View* view;
|
||||
SubGhzTestStaticStatus status_tx;
|
||||
SubGhzEncoderPrinceton* encoder;
|
||||
SubGhzTestStaticCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t frequency;
|
||||
uint32_t real_frequency;
|
||||
uint8_t button;
|
||||
} SubGhzTestStaticModel;
|
||||
|
||||
void subghz_test_static_set_callback(
|
||||
SubGhzTestStatic* subghz_test_static,
|
||||
SubGhzTestStaticCallback callback,
|
||||
void* context) {
|
||||
furi_assert(subghz_test_static);
|
||||
furi_assert(callback);
|
||||
subghz_test_static->callback = callback;
|
||||
subghz_test_static->context = context;
|
||||
}
|
||||
|
||||
void subghz_test_static_draw(Canvas* canvas, SubGhzTestStaticModel* model) {
|
||||
char buffer[64];
|
||||
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 0, 8, "CC1101 Static");
|
||||
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
// Frequency
|
||||
snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"Freq: %03ld.%03ld.%03ld Hz",
|
||||
model->real_frequency / 1000000 % 1000,
|
||||
model->real_frequency / 1000 % 1000,
|
||||
model->real_frequency % 1000);
|
||||
canvas_draw_str(canvas, 0, 20, buffer);
|
||||
snprintf(buffer, sizeof(buffer), "Key: %d", model->button);
|
||||
canvas_draw_str(canvas, 0, 31, buffer);
|
||||
}
|
||||
|
||||
bool subghz_test_static_input(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestStatic* instance = context;
|
||||
|
||||
if(event->key == InputKeyBack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestStaticModel * model) {
|
||||
if(event->type == InputTypeShort) {
|
||||
if(event->key == InputKeyLeft) {
|
||||
if(model->frequency > 0) model->frequency--;
|
||||
} else if(event->key == InputKeyRight) {
|
||||
if(model->frequency < subghz_frequencies_count_testing - 1) model->frequency++;
|
||||
} else if(event->key == InputKeyDown) {
|
||||
if(model->button > 0) model->button--;
|
||||
} else if(event->key == InputKeyUp) {
|
||||
if(model->button < 3) model->button++;
|
||||
}
|
||||
}
|
||||
|
||||
model->real_frequency = subghz_frequencies_testing[model->frequency];
|
||||
|
||||
if(event->key == InputKeyOk) {
|
||||
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
|
||||
if(event->type == InputTypePress) {
|
||||
furi_hal_subghz_idle();
|
||||
furi_hal_subghz_set_frequency_and_path(
|
||||
subghz_frequencies_testing[model->frequency]);
|
||||
if(!furi_hal_subghz_tx()) {
|
||||
instance->callback(SubGhzTestStaticEventOnlyRx, instance->context);
|
||||
} else {
|
||||
notification_message_block(notification, &sequence_set_red_255);
|
||||
|
||||
FURI_LOG_I(TAG, "TX Start");
|
||||
|
||||
subghz_encoder_princeton_for_testing_set(
|
||||
instance->encoder,
|
||||
subghz_test_static_keys[model->button],
|
||||
10000,
|
||||
subghz_frequencies_testing[model->frequency]);
|
||||
|
||||
furi_hal_subghz_start_async_tx(
|
||||
subghz_encoder_princeton_for_testing_yield, instance->encoder);
|
||||
instance->status_tx = SubGhzTestStaticStatusTX;
|
||||
}
|
||||
} else if(event->type == InputTypeRelease) {
|
||||
if(instance->status_tx == SubGhzTestStaticStatusTX) {
|
||||
FURI_LOG_I(TAG, "TX Stop");
|
||||
subghz_encoder_princeton_for_testing_stop(
|
||||
instance->encoder, furi_get_tick());
|
||||
subghz_encoder_princeton_for_testing_print_log(instance->encoder);
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
notification_message(notification, &sequence_reset_red);
|
||||
}
|
||||
instance->status_tx = SubGhzTestStaticStatusIDLE;
|
||||
}
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void subghz_test_static_enter(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzTestStatic* instance = context;
|
||||
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_write(&gpio_cc1101_g0, false);
|
||||
instance->status_tx = SubGhzTestStaticStatusIDLE;
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestStaticModel * model) {
|
||||
model->frequency = subghz_frequencies_433_92_testing;
|
||||
model->real_frequency = subghz_frequencies_testing[model->frequency];
|
||||
model->button = 0;
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void subghz_test_static_exit(void* context) {
|
||||
furi_assert(context);
|
||||
furi_hal_subghz_sleep();
|
||||
}
|
||||
|
||||
SubGhzTestStatic* subghz_test_static_alloc() {
|
||||
SubGhzTestStatic* instance = malloc(sizeof(SubGhzTestStatic));
|
||||
|
||||
// View allocation and configuration
|
||||
instance->view = view_alloc();
|
||||
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(SubGhzTestStaticModel));
|
||||
view_set_context(instance->view, instance);
|
||||
view_set_draw_callback(instance->view, (ViewDrawCallback)subghz_test_static_draw);
|
||||
view_set_input_callback(instance->view, subghz_test_static_input);
|
||||
view_set_enter_callback(instance->view, subghz_test_static_enter);
|
||||
view_set_exit_callback(instance->view, subghz_test_static_exit);
|
||||
|
||||
instance->encoder = subghz_encoder_princeton_for_testing_alloc();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void subghz_test_static_free(SubGhzTestStatic* instance) {
|
||||
furi_assert(instance);
|
||||
subghz_encoder_princeton_for_testing_free(instance->encoder);
|
||||
view_free(instance->view);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
View* subghz_test_static_get_view(SubGhzTestStatic* instance) {
|
||||
furi_assert(instance);
|
||||
return instance->view;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
|
||||
typedef enum {
|
||||
SubGhzTestStaticEventOnlyRx,
|
||||
} SubGhzTestStaticEvent;
|
||||
|
||||
typedef struct SubGhzTestStatic SubGhzTestStatic;
|
||||
|
||||
typedef void (*SubGhzTestStaticCallback)(SubGhzTestStaticEvent event, void* context);
|
||||
|
||||
void subghz_test_static_set_callback(
|
||||
SubGhzTestStatic* subghz_test_static,
|
||||
SubGhzTestStaticCallback callback,
|
||||
void* context);
|
||||
|
||||
SubGhzTestStatic* subghz_test_static_alloc();
|
||||
|
||||
void subghz_test_static_free(SubGhzTestStatic* subghz_static);
|
||||
|
||||
View* subghz_test_static_get_view(SubGhzTestStatic* subghz_static);
|
||||
@@ -0,0 +1,175 @@
|
||||
#include "transmitter.h"
|
||||
#include "../subghz_i.h"
|
||||
|
||||
#include <input/input.h>
|
||||
#include <gui/elements.h>
|
||||
|
||||
struct SubGhzViewTransmitter {
|
||||
View* view;
|
||||
SubGhzViewTransmitterCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
string_t frequency_str;
|
||||
string_t preset_str;
|
||||
string_t key_str;
|
||||
uint8_t show_button;
|
||||
} SubGhzViewTransmitterModel;
|
||||
|
||||
void subghz_view_transmitter_set_callback(
|
||||
SubGhzViewTransmitter* subghz_transmitter,
|
||||
SubGhzViewTransmitterCallback callback,
|
||||
void* context) {
|
||||
furi_assert(subghz_transmitter);
|
||||
|
||||
subghz_transmitter->callback = callback;
|
||||
subghz_transmitter->context = context;
|
||||
}
|
||||
|
||||
void subghz_view_transmitter_add_data_to_show(
|
||||
SubGhzViewTransmitter* subghz_transmitter,
|
||||
const char* key_str,
|
||||
const char* frequency_str,
|
||||
const char* preset_str,
|
||||
uint8_t show_button) {
|
||||
furi_assert(subghz_transmitter);
|
||||
with_view_model(
|
||||
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
|
||||
string_set_str(model->key_str, key_str);
|
||||
string_set_str(model->frequency_str, frequency_str);
|
||||
string_set_str(model->preset_str, preset_str);
|
||||
model->show_button = show_button;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
static void subghz_view_transmitter_button_right(Canvas* canvas, const char* str) {
|
||||
const uint8_t button_height = 13;
|
||||
const uint8_t vertical_offset = 3;
|
||||
const uint8_t horizontal_offset = 1;
|
||||
const uint8_t string_width = canvas_string_width(canvas, str);
|
||||
const Icon* icon = &I_ButtonCenter_7x7;
|
||||
const uint8_t icon_offset = 3;
|
||||
const uint8_t icon_width_with_offset = icon_get_width(icon) + icon_offset;
|
||||
const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset;
|
||||
|
||||
const uint8_t x = (canvas_width(canvas) - button_width) / 2 + 40;
|
||||
const uint8_t y = canvas_height(canvas);
|
||||
|
||||
canvas_draw_box(canvas, x, y - button_height, button_width, button_height);
|
||||
|
||||
canvas_draw_line(canvas, x - 1, y, x - 1, y - button_height + 0);
|
||||
canvas_draw_line(canvas, x - 2, y, x - 2, y - button_height + 1);
|
||||
canvas_draw_line(canvas, x - 3, y, x - 3, y - button_height + 2);
|
||||
|
||||
canvas_draw_line(canvas, x + button_width + 0, y, x + button_width + 0, y - button_height + 0);
|
||||
canvas_draw_line(canvas, x + button_width + 1, y, x + button_width + 1, y - button_height + 1);
|
||||
canvas_draw_line(canvas, x + button_width + 2, y, x + button_width + 2, y - button_height + 2);
|
||||
|
||||
canvas_invert_color(canvas);
|
||||
canvas_draw_icon(
|
||||
canvas, x + horizontal_offset, y - button_height + vertical_offset, &I_ButtonCenter_7x7);
|
||||
canvas_draw_str(
|
||||
canvas, x + horizontal_offset + icon_width_with_offset, y - vertical_offset, str);
|
||||
canvas_invert_color(canvas);
|
||||
}
|
||||
|
||||
void subghz_view_transmitter_draw(Canvas* canvas, SubGhzViewTransmitterModel* model) {
|
||||
canvas_clear(canvas);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
elements_multiline_text(canvas, 0, 8, string_get_cstr(model->key_str));
|
||||
canvas_draw_str(canvas, 78, 8, string_get_cstr(model->frequency_str));
|
||||
canvas_draw_str(canvas, 113, 8, string_get_cstr(model->preset_str));
|
||||
if(model->show_button) subghz_view_transmitter_button_right(canvas, "Send");
|
||||
}
|
||||
|
||||
bool subghz_view_transmitter_input(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzViewTransmitter* subghz_transmitter = context;
|
||||
bool can_be_sent = false;
|
||||
|
||||
if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
|
||||
string_reset(model->frequency_str);
|
||||
string_reset(model->preset_str);
|
||||
string_reset(model->key_str);
|
||||
model->show_button = 0;
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
with_view_model(
|
||||
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
|
||||
if(model->show_button) {
|
||||
can_be_sent = true;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if(can_be_sent && event->key == InputKeyOk && event->type == InputTypePress) {
|
||||
subghz_transmitter->callback(
|
||||
SubGhzCustomEventViewTransmitterSendStart, subghz_transmitter->context);
|
||||
return true;
|
||||
} else if(can_be_sent && event->key == InputKeyOk && event->type == InputTypeRelease) {
|
||||
subghz_transmitter->callback(
|
||||
SubGhzCustomEventViewTransmitterSendStop, subghz_transmitter->context);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void subghz_view_transmitter_enter(void* context) {
|
||||
furi_assert(context);
|
||||
}
|
||||
|
||||
void subghz_view_transmitter_exit(void* context) {
|
||||
furi_assert(context);
|
||||
}
|
||||
|
||||
SubGhzViewTransmitter* subghz_view_transmitter_alloc() {
|
||||
SubGhzViewTransmitter* subghz_transmitter = malloc(sizeof(SubGhzViewTransmitter));
|
||||
|
||||
// View allocation and configuration
|
||||
subghz_transmitter->view = view_alloc();
|
||||
view_allocate_model(
|
||||
subghz_transmitter->view, ViewModelTypeLocking, sizeof(SubGhzViewTransmitterModel));
|
||||
view_set_context(subghz_transmitter->view, subghz_transmitter);
|
||||
view_set_draw_callback(
|
||||
subghz_transmitter->view, (ViewDrawCallback)subghz_view_transmitter_draw);
|
||||
view_set_input_callback(subghz_transmitter->view, subghz_view_transmitter_input);
|
||||
view_set_enter_callback(subghz_transmitter->view, subghz_view_transmitter_enter);
|
||||
view_set_exit_callback(subghz_transmitter->view, subghz_view_transmitter_exit);
|
||||
|
||||
with_view_model(
|
||||
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
|
||||
string_init(model->frequency_str);
|
||||
string_init(model->preset_str);
|
||||
string_init(model->key_str);
|
||||
return true;
|
||||
});
|
||||
return subghz_transmitter;
|
||||
}
|
||||
|
||||
void subghz_view_transmitter_free(SubGhzViewTransmitter* subghz_transmitter) {
|
||||
furi_assert(subghz_transmitter);
|
||||
|
||||
with_view_model(
|
||||
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
|
||||
string_clear(model->frequency_str);
|
||||
string_clear(model->preset_str);
|
||||
string_clear(model->key_str);
|
||||
return true;
|
||||
});
|
||||
view_free(subghz_transmitter->view);
|
||||
free(subghz_transmitter);
|
||||
}
|
||||
|
||||
View* subghz_view_transmitter_get_view(SubGhzViewTransmitter* subghz_transmitter) {
|
||||
furi_assert(subghz_transmitter);
|
||||
return subghz_transmitter->view;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../helpers/subghz_custom_event.h"
|
||||
|
||||
typedef struct SubGhzViewTransmitter SubGhzViewTransmitter;
|
||||
|
||||
typedef void (*SubGhzViewTransmitterCallback)(SubGhzCustomEvent event, void* context);
|
||||
|
||||
void subghz_view_transmitter_set_callback(
|
||||
SubGhzViewTransmitter* subghz_transmitter,
|
||||
SubGhzViewTransmitterCallback callback,
|
||||
void* context);
|
||||
|
||||
SubGhzViewTransmitter* subghz_view_transmitter_alloc();
|
||||
|
||||
void subghz_view_transmitter_free(SubGhzViewTransmitter* subghz_transmitter);
|
||||
|
||||
View* subghz_view_transmitter_get_view(SubGhzViewTransmitter* subghz_transmitter);
|
||||
|
||||
void subghz_view_transmitter_add_data_to_show(
|
||||
SubGhzViewTransmitter* subghz_transmitter,
|
||||
const char* key_str,
|
||||
const char* frequency_str,
|
||||
const char* preset_str,
|
||||
uint8_t show_button);
|
||||
Reference in New Issue
Block a user