2021-10-27 17:37:11 +00:00
|
|
|
#include "subghz_read_raw.h"
|
|
|
|
#include "../subghz_i.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <furi.h>
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <furi_hal.h>
|
2021-10-27 17:37:11 +00:00
|
|
|
#include <input/input.h>
|
|
|
|
#include <gui/elements.h>
|
|
|
|
|
|
|
|
#include <assets_icons.h>
|
|
|
|
#define SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE 100
|
2022-03-03 09:48:56 +00:00
|
|
|
#define TAG "SubGhzReadRAW"
|
2021-10-27 17:37:11 +00:00
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
struct SubGhzReadRAW {
|
2021-10-27 17:37:11 +00:00
|
|
|
View* view;
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzReadRAWCallback callback;
|
2021-10-27 17:37:11 +00:00
|
|
|
void* context;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
string_t frequency_str;
|
|
|
|
string_t preset_str;
|
|
|
|
string_t sample_write;
|
2021-12-08 15:00:54 +00:00
|
|
|
string_t file_name;
|
2021-10-27 17:37:11 +00:00
|
|
|
uint8_t* rssi_history;
|
|
|
|
bool rssi_history_end;
|
|
|
|
uint8_t ind_write;
|
2021-11-24 13:59:45 +00:00
|
|
|
uint8_t ind_sin;
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzReadRAWStatus satus;
|
|
|
|
} SubGhzReadRAWModel;
|
2021-10-27 17:37:11 +00:00
|
|
|
|
|
|
|
void subghz_read_raw_set_callback(
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzReadRAW* subghz_read_raw,
|
|
|
|
SubGhzReadRAWCallback callback,
|
2021-10-27 17:37:11 +00:00
|
|
|
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(
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzReadRAW* instance,
|
2021-10-27 17:37:11 +00:00
|
|
|
const char* frequency_str,
|
|
|
|
const char* preset_str) {
|
|
|
|
furi_assert(instance);
|
|
|
|
with_view_model(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
2021-10-27 17:37:11 +00:00
|
|
|
string_set(model->frequency_str, frequency_str);
|
|
|
|
string_set(model->preset_str, preset_str);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
void subghz_read_raw_add_data_rssi(SubGhzReadRAW* instance, float rssi) {
|
2021-10-27 17:37:11 +00:00
|
|
|
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(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
2021-10-27 17:37:11 +00:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
void subghz_read_raw_update_sample_write(SubGhzReadRAW* instance, size_t sample) {
|
2021-10-27 17:37:11 +00:00
|
|
|
furi_assert(instance);
|
|
|
|
|
|
|
|
with_view_model(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
2021-10-27 17:37:11 +00:00
|
|
|
string_printf(model->sample_write, "%d spl.", sample);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
void subghz_read_raw_stop_send(SubGhzReadRAW* instance) {
|
2021-11-24 13:59:45 +00:00
|
|
|
furi_assert(instance);
|
|
|
|
|
|
|
|
with_view_model(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
2021-12-22 13:01:20 +00:00
|
|
|
switch(model->satus) {
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusTXRepeat:
|
|
|
|
case SubGhzReadRAWStatusLoadKeyTXRepeat:
|
|
|
|
instance->callback(SubGhzCustomEventViewReadRAWSendStart, instance->context);
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusTX:
|
|
|
|
model->satus = SubGhzReadRAWStatusIDLE;
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusLoadKeyTX:
|
|
|
|
model->satus = SubGhzReadRAWStatusLoadKeyIDLE;
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FURI_LOG_W(TAG, "unknown status");
|
2022-03-03 09:48:56 +00:00
|
|
|
model->satus = SubGhzReadRAWStatusIDLE;
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
2021-11-24 13:59:45 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
void subghz_read_raw_update_sin(SubGhzReadRAW* instance) {
|
2021-11-24 13:59:45 +00:00
|
|
|
furi_assert(instance);
|
|
|
|
with_view_model(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
2021-11-24 13:59:45 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
void subghz_read_raw_draw_sin(Canvas* canvas, SubGhzReadRAWModel* model) {
|
2021-11-24 13:59:45 +00:00
|
|
|
#define SUBGHZ_RAW_SIN_AMPLITUDE 11
|
2021-11-26 14:01:03 +00:00
|
|
|
for(int i = 113; i > 0; i--) {
|
2021-11-24 13:59:45 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
void subghz_read_raw_draw_scale(Canvas* canvas, SubGhzReadRAWModel* model) {
|
2021-11-24 13:59:45 +00:00
|
|
|
#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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
void subghz_read_raw_draw_rssi(Canvas* canvas, SubGhzReadRAWModel* model) {
|
2021-10-27 17:37:11 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
void subghz_read_raw_draw(Canvas* canvas, SubGhzReadRAWModel* model) {
|
2021-12-22 13:01:20 +00:00
|
|
|
uint8_t graphics_mode = 1;
|
2021-10-27 17:37:11 +00:00
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
|
canvas_draw_str(canvas, 5, 8, string_get_cstr(model->frequency_str));
|
|
|
|
canvas_draw_str(canvas, 40, 8, 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);
|
2021-11-24 13:59:45 +00:00
|
|
|
|
2021-12-22 13:01:20 +00:00
|
|
|
switch(model->satus) {
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusIDLE:
|
2021-11-24 13:59:45 +00:00
|
|
|
elements_button_left(canvas, "Erase");
|
|
|
|
elements_button_center(canvas, "Send");
|
|
|
|
elements_button_right(canvas, "Save");
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusLoadKeyIDLE:
|
2021-12-22 13:01:20 +00:00
|
|
|
elements_button_left(canvas, "New");
|
|
|
|
elements_button_center(canvas, "Send");
|
|
|
|
elements_button_right(canvas, "More");
|
2022-01-27 16:38:47 +00:00
|
|
|
elements_text_box(
|
2022-04-19 19:23:50 +00:00
|
|
|
canvas,
|
|
|
|
4,
|
|
|
|
12,
|
|
|
|
110,
|
|
|
|
44,
|
|
|
|
AlignCenter,
|
|
|
|
AlignCenter,
|
|
|
|
string_get_cstr(model->file_name),
|
|
|
|
true);
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusTX:
|
|
|
|
case SubGhzReadRAWStatusTXRepeat:
|
|
|
|
case SubGhzReadRAWStatusLoadKeyTX:
|
|
|
|
case SubGhzReadRAWStatusLoadKeyTXRepeat:
|
2021-12-22 13:01:20 +00:00
|
|
|
graphics_mode = 0;
|
|
|
|
elements_button_center(canvas, "Send");
|
|
|
|
break;
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusStart:
|
2021-10-27 17:37:11 +00:00
|
|
|
elements_button_left(canvas, "Config");
|
|
|
|
elements_button_center(canvas, "REC");
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-10-27 17:37:11 +00:00
|
|
|
elements_button_center(canvas, "Stop");
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
2021-10-27 17:37:11 +00:00
|
|
|
}
|
|
|
|
|
2021-12-22 13:01:20 +00:00
|
|
|
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);
|
|
|
|
}
|
2021-10-27 17:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool subghz_read_raw_input(InputEvent* event, void* context) {
|
|
|
|
furi_assert(context);
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzReadRAW* instance = context;
|
2021-10-27 17:37:11 +00:00
|
|
|
|
2021-11-26 14:01:03 +00:00
|
|
|
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) {
|
2021-11-24 13:59:45 +00:00
|
|
|
with_view_model(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
2021-11-24 13:59:45 +00:00
|
|
|
uint8_t ret = false;
|
2021-12-22 13:01:20 +00:00
|
|
|
switch(model->satus) {
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusIDLE:
|
2021-11-24 13:59:45 +00:00
|
|
|
// Start TX
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->callback(SubGhzCustomEventViewReadRAWSendStart, instance->context);
|
|
|
|
instance->callback(SubGhzCustomEventViewReadRAWVibro, instance->context);
|
|
|
|
model->satus = SubGhzReadRAWStatusTXRepeat;
|
2021-11-24 13:59:45 +00:00
|
|
|
ret = true;
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusTX:
|
2021-12-22 13:01:20 +00:00
|
|
|
// Start TXRepeat
|
2022-03-03 09:48:56 +00:00
|
|
|
model->satus = SubGhzReadRAWStatusTXRepeat;
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusLoadKeyIDLE:
|
2021-12-22 13:01:20 +00:00
|
|
|
// Start Load Key TX
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->callback(SubGhzCustomEventViewReadRAWSendStart, instance->context);
|
|
|
|
instance->callback(SubGhzCustomEventViewReadRAWVibro, instance->context);
|
|
|
|
model->satus = SubGhzReadRAWStatusLoadKeyTXRepeat;
|
2021-12-22 13:01:20 +00:00
|
|
|
ret = true;
|
|
|
|
break;
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusLoadKeyTX:
|
2021-12-22 13:01:20 +00:00
|
|
|
// Start Load Key TXRepeat
|
2022-03-03 09:48:56 +00:00
|
|
|
model->satus = SubGhzReadRAWStatusLoadKeyTXRepeat;
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2021-11-24 13:59:45 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
});
|
|
|
|
} else if(event->key == InputKeyOk && event->type == InputTypeRelease) {
|
|
|
|
with_view_model(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
|
|
|
if(model->satus == SubGhzReadRAWStatusTXRepeat) {
|
2021-11-24 13:59:45 +00:00
|
|
|
// Stop repeat TX
|
2022-03-03 09:48:56 +00:00
|
|
|
model->satus = SubGhzReadRAWStatusTX;
|
|
|
|
} else if(model->satus == SubGhzReadRAWStatusLoadKeyTXRepeat) {
|
2021-12-22 13:01:20 +00:00
|
|
|
// Stop repeat TX
|
2022-03-03 09:48:56 +00:00
|
|
|
model->satus = SubGhzReadRAWStatusLoadKeyTX;
|
2021-11-24 13:59:45 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
} else if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
|
|
|
with_view_model(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
2021-12-22 13:01:20 +00:00
|
|
|
switch(model->satus) {
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusREC:
|
2021-11-24 13:59:45 +00:00
|
|
|
//Stop REC
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->callback(SubGhzCustomEventViewReadRAWIDLE, instance->context);
|
|
|
|
model->satus = SubGhzReadRAWStatusIDLE;
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusLoadKeyTX:
|
2021-12-22 13:01:20 +00:00
|
|
|
//Stop TxRx
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->callback(SubGhzCustomEventViewReadRAWTXRXStop, instance->context);
|
|
|
|
model->satus = SubGhzReadRAWStatusLoadKeyIDLE;
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusTX:
|
2021-12-22 13:01:20 +00:00
|
|
|
//Stop TxRx
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->callback(SubGhzCustomEventViewReadRAWTXRXStop, instance->context);
|
|
|
|
model->satus = SubGhzReadRAWStatusIDLE;
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusLoadKeyIDLE:
|
2021-11-24 13:59:45 +00:00
|
|
|
//Exit
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->callback(SubGhzCustomEventViewReadRAWBack, instance->context);
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
//Exit
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->callback(SubGhzCustomEventViewReadRAWBack, instance->context);
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
2021-11-24 13:59:45 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2021-10-27 17:37:11 +00:00
|
|
|
} else if(event->key == InputKeyLeft && event->type == InputTypeShort) {
|
|
|
|
with_view_model(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
|
|
|
if(model->satus == SubGhzReadRAWStatusStart) {
|
2021-11-24 13:59:45 +00:00
|
|
|
//Config
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->callback(SubGhzCustomEventViewReadRAWConfig, instance->context);
|
2021-12-22 13:01:20 +00:00
|
|
|
} else if(
|
2022-03-03 09:48:56 +00:00
|
|
|
(model->satus == SubGhzReadRAWStatusIDLE) ||
|
|
|
|
(model->satus == SubGhzReadRAWStatusLoadKeyIDLE)) {
|
2021-11-24 13:59:45 +00:00
|
|
|
//Erase
|
2022-03-03 09:48:56 +00:00
|
|
|
model->satus = SubGhzReadRAWStatusStart;
|
2021-11-24 13:59:45 +00:00
|
|
|
model->rssi_history_end = false;
|
|
|
|
model->ind_write = 0;
|
|
|
|
string_set(model->sample_write, "0 spl.");
|
2021-12-08 15:00:54 +00:00
|
|
|
string_reset(model->file_name);
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->callback(SubGhzCustomEventViewReadRAWErase, instance->context);
|
2021-11-24 13:59:45 +00:00
|
|
|
}
|
2021-10-27 17:37:11 +00:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
} else if(event->key == InputKeyRight && event->type == InputTypeShort) {
|
|
|
|
with_view_model(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
|
|
|
if(model->satus == SubGhzReadRAWStatusIDLE) {
|
2021-12-22 13:01:20 +00:00
|
|
|
//Save
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->callback(SubGhzCustomEventViewReadRAWSave, instance->context);
|
|
|
|
} else if(model->satus == SubGhzReadRAWStatusLoadKeyIDLE) {
|
2021-12-22 13:01:20 +00:00
|
|
|
//More
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->callback(SubGhzCustomEventViewReadRAWMore, instance->context);
|
2021-10-27 17:37:11 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
} else if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
|
|
|
with_view_model(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
|
|
|
if(model->satus == SubGhzReadRAWStatusStart) {
|
2021-11-24 13:59:45 +00:00
|
|
|
//Record
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->callback(SubGhzCustomEventViewReadRAWREC, instance->context);
|
|
|
|
model->satus = SubGhzReadRAWStatusREC;
|
2021-10-27 17:37:11 +00:00
|
|
|
model->ind_write = 0;
|
|
|
|
model->rssi_history_end = false;
|
2022-03-03 09:48:56 +00:00
|
|
|
} else if(model->satus == SubGhzReadRAWStatusREC) {
|
2021-11-24 13:59:45 +00:00
|
|
|
//Stop
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->callback(SubGhzCustomEventViewReadRAWIDLE, instance->context);
|
|
|
|
model->satus = SubGhzReadRAWStatusIDLE;
|
2021-10-27 17:37:11 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-12-08 15:00:54 +00:00
|
|
|
void subghz_read_raw_set_status(
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzReadRAW* instance,
|
|
|
|
SubGhzReadRAWStatus satus,
|
2021-12-08 15:00:54 +00:00
|
|
|
const char* file_name) {
|
2021-11-24 13:59:45 +00:00
|
|
|
furi_assert(instance);
|
2021-12-22 13:01:20 +00:00
|
|
|
|
|
|
|
switch(satus) {
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusStart:
|
2021-11-24 13:59:45 +00:00
|
|
|
with_view_model(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
|
|
|
model->satus = SubGhzReadRAWStatusStart;
|
2021-11-24 13:59:45 +00:00
|
|
|
model->rssi_history_end = false;
|
|
|
|
model->ind_write = 0;
|
2021-12-08 15:00:54 +00:00
|
|
|
string_reset(model->file_name);
|
2021-11-24 13:59:45 +00:00
|
|
|
string_set(model->sample_write, "0 spl.");
|
|
|
|
return true;
|
|
|
|
});
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusIDLE:
|
2021-11-24 13:59:45 +00:00
|
|
|
with_view_model(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
|
|
|
model->satus = SubGhzReadRAWStatusIDLE;
|
2021-11-24 13:59:45 +00:00
|
|
|
return true;
|
|
|
|
});
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusLoadKeyTX:
|
2021-12-08 15:00:54 +00:00
|
|
|
with_view_model(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
|
|
|
model->satus = SubGhzReadRAWStatusLoadKeyIDLE;
|
2021-12-08 15:00:54 +00:00
|
|
|
model->rssi_history_end = false;
|
|
|
|
model->ind_write = 0;
|
|
|
|
string_set(model->file_name, file_name);
|
|
|
|
string_set(model->sample_write, "RAW");
|
|
|
|
return true;
|
|
|
|
});
|
2021-12-22 13:01:20 +00:00
|
|
|
break;
|
2022-03-03 09:48:56 +00:00
|
|
|
case SubGhzReadRAWStatusSaveKey:
|
2021-12-22 13:01:20 +00:00
|
|
|
with_view_model(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
|
|
|
model->satus = SubGhzReadRAWStatusLoadKeyIDLE;
|
2021-12-22 13:01:20 +00:00
|
|
|
if(!model->ind_write) {
|
|
|
|
string_set(model->file_name, file_name);
|
|
|
|
string_set(model->sample_write, "RAW");
|
|
|
|
} else {
|
|
|
|
string_reset(model->file_name);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FURI_LOG_W(TAG, "unknown status");
|
|
|
|
break;
|
2021-11-24 13:59:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-27 17:37:11 +00:00
|
|
|
void subghz_read_raw_enter(void* context) {
|
|
|
|
furi_assert(context);
|
2022-03-03 09:48:56 +00:00
|
|
|
//SubGhzReadRAW* instance = context;
|
2021-10-27 17:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_read_raw_exit(void* context) {
|
|
|
|
furi_assert(context);
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzReadRAW* instance = context;
|
2021-10-27 17:37:11 +00:00
|
|
|
|
|
|
|
with_view_model(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
|
|
|
if(model->satus != SubGhzReadRAWStatusIDLE &&
|
|
|
|
model->satus != SubGhzReadRAWStatusStart &&
|
|
|
|
model->satus != SubGhzReadRAWStatusLoadKeyIDLE) {
|
|
|
|
instance->callback(SubGhzCustomEventViewReadRAWIDLE, instance->context);
|
|
|
|
model->satus = SubGhzReadRAWStatusStart;
|
2021-10-27 17:37:11 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
SubGhzReadRAW* subghz_read_raw_alloc() {
|
|
|
|
SubGhzReadRAW* instance = malloc(sizeof(SubGhzReadRAW));
|
2021-10-27 17:37:11 +00:00
|
|
|
|
|
|
|
// View allocation and configuration
|
|
|
|
instance->view = view_alloc();
|
2022-03-03 09:48:56 +00:00
|
|
|
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(SubGhzReadRAWModel));
|
2021-10-27 17:37:11 +00:00
|
|
|
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(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
2021-10-27 17:37:11 +00:00
|
|
|
string_init(model->frequency_str);
|
|
|
|
string_init(model->preset_str);
|
|
|
|
string_init(model->sample_write);
|
2021-12-08 15:00:54 +00:00
|
|
|
string_init(model->file_name);
|
2022-02-18 19:53:46 +00:00
|
|
|
model->rssi_history = malloc(SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE * sizeof(uint8_t));
|
2021-10-27 17:37:11 +00:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
void subghz_read_raw_free(SubGhzReadRAW* instance) {
|
2021-10-27 17:37:11 +00:00
|
|
|
furi_assert(instance);
|
|
|
|
|
|
|
|
with_view_model(
|
2022-03-03 09:48:56 +00:00
|
|
|
instance->view, (SubGhzReadRAWModel * model) {
|
2021-10-27 17:37:11 +00:00
|
|
|
string_clear(model->frequency_str);
|
|
|
|
string_clear(model->preset_str);
|
|
|
|
string_clear(model->sample_write);
|
2021-12-08 15:00:54 +00:00
|
|
|
string_clear(model->file_name);
|
2021-11-24 13:59:45 +00:00
|
|
|
free(model->rssi_history);
|
2021-10-27 17:37:11 +00:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
view_free(instance->view);
|
|
|
|
free(instance);
|
|
|
|
}
|
|
|
|
|
2022-03-03 09:48:56 +00:00
|
|
|
View* subghz_read_raw_get_view(SubGhzReadRAW* instance) {
|
2021-10-27 17:37:11 +00:00
|
|
|
furi_assert(instance);
|
|
|
|
return instance->view;
|
2022-02-18 19:53:46 +00:00
|
|
|
}
|