Просмотр исходного кода

[FL-2100] SubGhz: GUI download and transfer RAW file (#881)

* SubGhz: fix exit subghz_chat
* SubGhz: refactoring GUI RAW

Co-authored-by: あく <alleteam@gmail.com>
Skorpionm 4 лет назад
Родитель
Сommit
9f28338d9e

+ 1 - 1
applications/subghz/helpers/subghz_chat.c

@@ -27,7 +27,7 @@ static int32_t subghz_chat_worker_thread(void* context) {
     event.event = SubghzChatEventUserEntrance;
     osMessageQueuePut(instance->event_queue, &event, 0, 0);
     while(instance->worker_running) {
-        if(furi_hal_vcp_rx_with_timeout((uint8_t*)&c, 1, osWaitForever) == 1) {
+        if(furi_hal_vcp_rx_with_timeout((uint8_t*)&c, 1, 1000) == 1) {
             event.event = SubghzChatEventInputData;
             event.c = c;
             osMessageQueuePut(instance->event_queue, &event, 0, osWaitForever);

+ 6 - 2
applications/subghz/scenes/subghz_scene_read_raw.c

@@ -41,9 +41,13 @@ void subghz_scene_read_raw_on_enter(void* context) {
     SubGhz* subghz = context;
 
     if(subghz->txrx->rx_key_state == SubGhzRxKeyStateBack) {
-        subghz_read_raw_set_status(subghz->subghz_read_raw, SubghzReadRAWStatusIDLE);
+        subghz_read_raw_set_status(subghz->subghz_read_raw, SubghzReadRAWStatusIDLE, "");
+    } else if(subghz->txrx->rx_key_state == SubGhzRxKeyStateRAWLoad) {
+        subghz_read_raw_set_status(
+            subghz->subghz_read_raw, SubghzReadRAWStatusTX, subghz->file_name);
+        subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey;
     } else {
-        subghz_read_raw_set_status(subghz->subghz_read_raw, SubghzReadRAWStatusStart);
+        subghz_read_raw_set_status(subghz->subghz_read_raw, SubghzReadRAWStatusStart, "");
         subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
     }
 

+ 6 - 1
applications/subghz/scenes/subghz_scene_saved.c

@@ -4,7 +4,12 @@ void subghz_scene_saved_on_enter(void* context) {
     SubGhz* subghz = context;
 
     if(subghz_load_protocol_from_file(subghz)) {
-        scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSavedMenu);
+        if((!strcmp(subghz->txrx->protocol_result->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);
     }

+ 1 - 0
applications/subghz/subghz_i.h

@@ -73,6 +73,7 @@ typedef enum {
     SubGhzRxKeyStateBack,
     SubGhzRxKeyStateAddKey,
     SubGhzRxKeyStateExit,
+    SubGhzRxKeyStateRAWLoad,
 } SubGhzRxKeyState;
 
 struct SubGhzTxRx {

+ 21 - 1
applications/subghz/views/subghz_read_raw.c

@@ -21,6 +21,7 @@ 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;
@@ -224,6 +225,8 @@ void subghz_read_raw_draw(Canvas* canvas, SubghzReadRAWModel* model) {
         elements_button_left(canvas, "Erase");
         elements_button_center(canvas, "Send");
         elements_button_right(canvas, "Save");
+        canvas_draw_str_aligned(
+            canvas, 58, 28, AlignCenter, AlignTop, string_get_cstr(model->file_name));
     } else if(model->satus == SubghzReadRAWStatusStart) {
         elements_button_left(canvas, "Config");
         elements_button_center(canvas, "REC");
@@ -297,6 +300,7 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
                     model->rssi_history_end = false;
                     model->ind_write = 0;
                     string_set(model->sample_write, "0 spl.");
+                    string_reset(model->file_name);
                     instance->callback(SubghzCustomEventViewReadRAWErase, instance->context);
                 }
                 return true;
@@ -332,7 +336,10 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
     return true;
 }
 
-void subghz_read_raw_set_status(SubghzReadRAW* instance, SubghzReadRAWStatus satus) {
+void subghz_read_raw_set_status(
+    SubghzReadRAW* instance,
+    SubghzReadRAWStatus satus,
+    const char* file_name) {
     furi_assert(instance);
     if(satus == SubghzReadRAWStatusStart) {
         with_view_model(
@@ -340,6 +347,7 @@ void subghz_read_raw_set_status(SubghzReadRAW* instance, SubghzReadRAWStatus sat
                 model->satus = SubghzReadRAWStatusStart;
                 model->rssi_history_end = false;
                 model->ind_write = 0;
+                string_reset(model->file_name);
                 string_set(model->sample_write, "0 spl.");
                 return true;
             });
@@ -349,6 +357,16 @@ void subghz_read_raw_set_status(SubghzReadRAW* instance, SubghzReadRAWStatus sat
                 model->satus = SubghzReadRAWStatusIDLE;
                 return true;
             });
+    } else if(satus == SubghzReadRAWStatusTX) {
+        with_view_model(
+            instance->view, (SubghzReadRAWModel * model) {
+                model->satus = SubghzReadRAWStatusIDLE;
+                model->rssi_history_end = false;
+                model->ind_write = 0;
+                string_set(model->file_name, file_name);
+                string_set(model->sample_write, "RAW");
+                return true;
+            });
     }
 }
 
@@ -389,6 +407,7 @@ SubghzReadRAW* subghz_read_raw_alloc() {
             string_init(model->frequency_str);
             string_init(model->preset_str);
             string_init(model->sample_write);
+            string_init(model->file_name);
             model->rssi_history = furi_alloc(SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE * sizeof(uint8_t));
             return true;
         });
@@ -404,6 +423,7 @@ void subghz_read_raw_free(SubghzReadRAW* instance) {
             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;
         });

+ 4 - 1
applications/subghz/views/subghz_read_raw.h

@@ -37,6 +37,9 @@ 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 satus);
+void subghz_read_raw_set_status(
+    SubghzReadRAW* instance,
+    SubghzReadRAWStatus satus,
+    const char* file_name);
 
 View* subghz_read_raw_get_view(SubghzReadRAW* subghz_static);