Skip to content

Commit

Permalink
[FL-1913, FL-1963] SubGhz: save raw signal, add came atomo decoder (#…
Browse files Browse the repository at this point in the history
…783)

* File_Worker: getting the name of a new file with an index
* SubGhz: add decoder RAW protocol
* SubGhz: add view Save RAW
* SubGhz: refactoring subghz custom event
* SubGhz: fix syntax
* SubGhz: fix error build
* SubGhz: test build
* SubGhz: refactoring subghz, add rename, delete, start and emulate RAW signal
* SubGhz: fix triangle glitch in save raw view
* SubGhz: fix receiver config scene
* SubGhz: fix transfer after returning from save scene
* Canvas: add font rotation
* SubGhz: raw protocol encoder
* SubGhz: fix error completion of transfer raw encoder
* SubGhz: increased the speed of reading RAW data from a flash drive, displaying the name of the saved file in the Save RAW scene
* Canvas: fix font rotation
* SubGhz: fix navigation save RAW  scene
* SubGhz: add decode came atomo
* Git: renormalize
* Cleanup sources and enums
* Gui: add font direction to canvas reset, canvas init sequence cleanup.
* SubGhz: reorder menu.
* Gui: correct canvas_set_font_direction signature

Co-authored-by: Aleksandr Kutuzov <[email protected]>
  • Loading branch information
Skorpionm and skotopes authored Oct 25, 2021
1 parent 88cee46 commit 9d952ed
Show file tree
Hide file tree
Showing 59 changed files with 1,693 additions and 199 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto

23 changes: 17 additions & 6 deletions applications/gui/canvas.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ Canvas* canvas_init() {

furi_hal_power_insomnia_enter();

canvas->orientation = CanvasOrientationHorizontal;
// Setup u8g2
u8g2_Setup_st756x_flipper(&canvas->fb, U8G2_R0, u8x8_hw_spi_stm32, u8g2_gpio_and_delay_stm32);

// send init sequence to the display, display is in sleep mode after this
canvas->orientation = CanvasOrientationHorizontal;
// Initialize display
u8g2_InitDisplay(&canvas->fb);
// wake up display
u8g2_ClearBuffer(&canvas->fb);
// Wake up display
u8g2_SetPowerSave(&canvas->fb, 0);
u8g2_SendBuffer(&canvas->fb);

// Clear buffer and send to device
canvas_clear(canvas);
canvas_commit(canvas);

furi_hal_power_insomnia_exit();

return canvas;
}

Expand All @@ -32,9 +35,12 @@ void canvas_free(Canvas* canvas) {

void canvas_reset(Canvas* canvas) {
furi_assert(canvas);

canvas_clear(canvas);

canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontSecondary);
canvas_set_font_direction(canvas, CanvasFontDirectionLeftToRight);
}

void canvas_commit(Canvas* canvas) {
Expand Down Expand Up @@ -96,6 +102,11 @@ void canvas_set_color(Canvas* canvas, Color color) {
u8g2_SetDrawColor(&canvas->fb, color);
}

void canvas_set_font_direction(Canvas* canvas, CanvasFontDirection dir) {
furi_assert(canvas);
u8g2_SetFontDirection(&canvas->fb, dir);
}

void canvas_invert_color(Canvas* canvas) {
canvas->fb.draw_color = !canvas->fb.draw_color;
}
Expand Down
16 changes: 16 additions & 0 deletions applications/gui/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ typedef enum {
CanvasOrientationVertical,
} CanvasOrientation;

/** Font Direction */
typedef enum {
CanvasFontDirectionLeftToRight,
CanvasFontDirectionTopToDown,
CanvasFontDirectionRightToLeft,
CanvasFontDirectionDownToTop,
} CanvasFontDirection;

/** Canvas anonymouse structure */
typedef struct Canvas Canvas;

Expand Down Expand Up @@ -77,6 +85,14 @@ void canvas_clear(Canvas* canvas);
*/
void canvas_set_color(Canvas* canvas, Color color);

/** Set font swap
* Argument String Rotation Description
*
* @param canvas Canvas instance
* @param dir Direction font
*/
void canvas_set_font_direction(Canvas* canvas, CanvasFontDirection dir);

/** Invert drawing color
*
* @param canvas Canvas instance
Expand Down
28 changes: 28 additions & 0 deletions applications/subghz/helpers/subghz_custom_event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

typedef enum {
SubghzCustomEventSceneDeleteSuccess = 100,
SubghzCustomEventSceneDelete,
SubghzCustomEventSceneReceiverInfoTxStart,
SubghzCustomEventSceneReceiverInfoTxStop,
SubghzCustomEventSceneReceiverInfoSave,
SubghzCustomEventSceneSaveName,
SubghzCustomEventSceneSaveSuccess,
SubghzCustomEventSceneShowError,
SubghzCustomEventSceneShowOnlyRX,

SubghzCustomEventViewReceverOK,
SubghzCustomEventViewReceverConfig,
SubghzCustomEventViewReceverBack,

SubghzCustomEventViewSaveRAWBack,
SubghzCustomEventViewSaveRAWIDLE,
SubghzCustomEventViewSaveRAWREC,
SubghzCustomEventViewSaveRAWConfig,
SubghzCustomEventViewSaveRAWMore,

SubghzCustomEventViewTransmitterBack,
SubghzCustomEventViewTransmitterSendStart,
SubghzCustomEventViewTransmitterSendStop,
SubghzCustomEventViewTransmitterError,
} SubghzCustomEvent;
3 changes: 2 additions & 1 deletion applications/subghz/scenes/subghz_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ 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, frequency_analyzer, FrequencyAnalyzer)
ADD_SCENE(subghz, save_raw, SaveRAW)
10 changes: 3 additions & 7 deletions applications/subghz/scenes/subghz_scene_delete.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#include "../subghz_i.h"

typedef enum {
SubGhzSceneDeleteInfoCustomEventDelete,
} SubGhzSceneDeleteInfoCustomEvent;
#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, SubGhzSceneDeleteInfoCustomEventDelete);
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneDelete);
}
}

Expand Down Expand Up @@ -53,7 +49,7 @@ void subghz_scene_delete_on_enter(void* context) {
bool subghz_scene_delete_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzSceneDeleteInfoCustomEventDelete) {
if(event.event == SubghzCustomEventSceneDelete) {
memcpy(subghz->file_name_tmp, subghz->file_name, strlen(subghz->file_name));
if(subghz_delete_file(subghz)) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneDeleteSuccess);
Expand Down
8 changes: 4 additions & 4 deletions applications/subghz/scenes/subghz_scene_delete_success.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "../subghz_i.h"

#define SCENE_DELETE_SUCCESS_CUSTOM_EVENT (0UL)
#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, SCENE_DELETE_SUCCESS_CUSTOM_EVENT);
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubghzCustomEventSceneDeleteSuccess);
}

void subghz_scene_delete_success_on_enter(void* context) {
Expand All @@ -25,7 +25,7 @@ bool subghz_scene_delete_success_on_event(void* context, SceneManagerEvent event
SubGhz* subghz = context;

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SCENE_DELETE_SUCCESS_CUSTOM_EVENT) {
if(event.event == SubghzCustomEventSceneDeleteSuccess) {
return scene_manager_search_and_switch_to_previous_scene(
subghz->scene_manager, SubGhzSceneStart);
}
Expand Down
10 changes: 2 additions & 8 deletions applications/subghz/scenes/subghz_scene_frequency_analyzer.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "../subghz_i.h"
#include "../views/subghz_frequency_analyzer.h"

void subghz_scene_frequency_analyzer_callback(SubghzFrequencyAnalyzerEvent event, void* context) {
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);
Expand All @@ -15,13 +15,7 @@ void subghz_scene_frequency_analyzer_on_enter(void* context) {
}

bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubghzFrequencyAnalyzerEventOnlyRx) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
return true;
}
}
//SubGhz* subghz = context;
return false;
}

Expand Down
9 changes: 5 additions & 4 deletions applications/subghz/scenes/subghz_scene_receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static void subghz_scene_receiver_update_statusbar(void* context) {
string_clear(history_stat_str);
}

void subghz_scene_receiver_callback(SubghzReceverEvent event, void* context) {
void subghz_scene_receiver_callback(SubghzCustomEvent event, void* context) {
furi_assert(context);
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
Expand Down Expand Up @@ -102,8 +102,9 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {

if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case SubghzReceverEventBack:
case SubghzCustomEventViewReceverBack:
// Stop CC1101 Rx
subghz->state_notifications = NOTIFICATION_IDLE_STATE;
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
subghz_rx_end(subghz);
subghz_sleep(subghz);
Expand All @@ -118,12 +119,12 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
subghz->scene_manager, SubGhzSceneStart);
return true;
break;
case SubghzReceverEventOK:
case SubghzCustomEventViewReceverOK:
subghz->txrx->idx_menu_chosen = subghz_receiver_get_idx_menu(subghz->subghz_receiver);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverInfo);
return true;
break;
case SubghzReceverEventConfig:
case SubghzCustomEventViewReceverConfig:
subghz->state_notifications = NOTIFICATION_IDLE_STATE;
subghz->txrx->idx_menu_chosen = subghz_receiver_get_idx_menu(subghz->subghz_receiver);
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig);
Expand Down
39 changes: 23 additions & 16 deletions applications/subghz/scenes/subghz_scene_receiver_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) {
if(subghz->txrx->hopper_state == SubGhzHopperStateOFF) {
variable_item_set_current_value_text(item, subghz_frequencies_text[index]);
subghz->txrx->frequency = subghz_frequencies[index];
} else {
variable_item_set_current_value_index(item, subghz_frequencies_433_92);
}
}

Expand All @@ -88,22 +90,24 @@ static void subghz_scene_receiver_config_set_hopping_runing(VariableItem* item)
subghz->scene_manager, SubGhzSceneReceiverConfig),
subghz_frequencies_text[subghz_frequencies_433_92]);
subghz->txrx->frequency = subghz_frequencies[subghz_frequencies_433_92];
variable_item_set_current_value_index(
(VariableItem*)scene_manager_get_scene_state(
subghz->scene_manager, SubGhzSceneReceiverConfig),
subghz_frequencies_433_92);
} 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_frequencies_433_92);
}

subghz->txrx->hopper_state = hopping_value[index];
}

void subghz_scene_receiver_config_callback(SubghzReceverEvent event, void* context) {
furi_assert(context);
SubGhz* subghz = context;
view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
}

void subghz_scene_receiver_config_on_enter(void* context) {
SubGhz* subghz = context;
VariableItem* item;
Expand All @@ -122,16 +126,18 @@ void subghz_scene_receiver_config_on_enter(void* context) {
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, subghz_frequencies_text[value_index]);

item = variable_item_list_add(
subghz->variable_item_list,
"Hopping:",
HOPPING_COUNT,
subghz_scene_receiver_config_set_hopping_runing,
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]);
if(!scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneSaveRAW)) {
item = variable_item_list_add(
subghz->variable_item_list,
"Hopping:",
HOPPING_COUNT,
subghz_scene_receiver_config_set_hopping_runing,
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,
Expand All @@ -155,4 +161,5 @@ bool subghz_scene_receiver_config_on_event(void* context, SceneManagerEvent even
void subghz_scene_receiver_config_on_exit(void* context) {
SubGhz* subghz = context;
variable_item_list_clean(subghz->variable_item_list);
scene_manager_set_scene_state(subghz->scene_manager, SubGhzSceneSaveRAW, 0);
}
22 changes: 9 additions & 13 deletions applications/subghz/scenes/subghz_scene_receiver_info.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
#include "../subghz_i.h"

typedef enum {
SubGhzSceneReceiverInfoCustomEventTxStart,
SubGhzSceneReceiverInfoCustomEventTxStop,
SubGhzSceneReceiverInfoCustomEventSave,
} SubGhzSceneReceiverInfoCustomEvent;
#include "../helpers/subghz_custom_event.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, SubGhzSceneReceiverInfoCustomEventTxStart);
subghz->view_dispatcher, SubghzCustomEventSceneReceiverInfoTxStart);
} else if((result == GuiButtonTypeCenter) && (type == InputTypeRelease)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubGhzSceneReceiverInfoCustomEventTxStop);
subghz->view_dispatcher, SubghzCustomEventSceneReceiverInfoTxStop);
} else if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubGhzSceneReceiverInfoCustomEventSave);
subghz->view_dispatcher, SubghzCustomEventSceneReceiverInfoSave);
}
}

Expand Down Expand Up @@ -101,7 +96,7 @@ void subghz_scene_receiver_info_on_enter(void* context) {
bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) {
SubGhz* subghz = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzSceneReceiverInfoCustomEventTxStart) {
if(event.event == SubghzCustomEventSceneReceiverInfoTxStart) {
//CC1101 Stop RX -> Start TX
if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
subghz->txrx->hopper_state = SubGhzHopperStatePause;
Expand All @@ -112,15 +107,16 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
if(!subghz_scene_receiver_info_update_parser(subghz)) {
return false;
}
if(subghz->txrx->txrx_state == SubGhzTxRxStateIdle) {
if(subghz->txrx->txrx_state == SubGhzTxRxStateIdle ||
subghz->txrx->txrx_state == SubGhzTxRxStateSleep) {
if(!subghz_tx_start(subghz)) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
} else {
subghz->state_notifications = NOTIFICATION_TX_STATE;
}
}
return true;
} else if(event.event == SubGhzSceneReceiverInfoCustomEventTxStop) {
} else if(event.event == SubghzCustomEventSceneReceiverInfoTxStop) {
//CC1101 Stop Tx -> Start RX
subghz->state_notifications = NOTIFICATION_IDLE_STATE;
if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
Expand All @@ -135,7 +131,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
}
subghz->state_notifications = NOTIFICATION_RX_STATE;
return true;
} else if(event.event == SubGhzSceneReceiverInfoCustomEventSave) {
} else if(event.event == SubghzCustomEventSceneReceiverInfoSave) {
//CC1101 Stop RX -> Save
subghz->state_notifications = NOTIFICATION_IDLE_STATE;
if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
Expand Down
Loading

0 comments on commit 9d952ed

Please sign in to comment.