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

Stabilized save and run, still a crash left after deleting items

David Lee 1 год назад
Родитель
Сommit
14db43dd1a

+ 1 - 1
helpers/subghz/subghz.c

@@ -38,7 +38,7 @@ void subghz_scene_transmit_callback_end_tx(void* context) {
 
 void subghz_send(void* context, const char* path) {
     XRemote* app = context;
-    
+
     subghz_load_protocol_from_file(app->subghz, path);
     FURI_LOG_D(TAG, "Starting Transmission");
     subghz_txrx_tx_start(

+ 4 - 2
models/cross/xremote_cross_remote.c

@@ -111,10 +111,11 @@ bool xremote_cross_remote_add_pause(CrossRemote* remote, int time) {
 }
 
 bool xremote_cross_remote_add_subghz(CrossRemote* remote, SubGhzRemote* subghz) {
-    UNUSED(subghz);
     CrossRemoteItem* item = xremote_cross_remote_item_alloc();
     xremote_cross_remote_item_set_type(item, XRemoteRemoteItemTypeSubGhz);
     xremote_cross_remote_item_set_name(item, xremote_sg_remote_get_name(subghz));
+    xremote_cross_remote_item_set_filename(item, xremote_sg_remote_get_filename(subghz));
+    FURI_LOG_D(TAG, "add subghz: %s", xremote_sg_remote_get_filename(subghz));
     xremote_cross_remote_item_set_sg_signal(item, subghz);
 
     CrossRemoteItemArray_push_back(remote->items, item);
@@ -217,7 +218,8 @@ static bool xremote_cross_remote_store(CrossRemote* remote) {
                 success = xremote_cross_remote_item_sg_signal_save(
                     xremote_cross_remote_item_get_sg_signal(item),
                     ff,
-                    xremote_cross_remote_item_get_name(item));
+                    xremote_cross_remote_item_get_name(item),
+                    xremote_cross_remote_item_get_filename(item));
             }
             if(!success) {
                 break;

+ 16 - 6
models/cross/xremote_cross_remote_item.c

@@ -73,13 +73,15 @@ static bool xremote_cross_remote_item_read_sg(CrossRemoteItem* item, FlipperForm
     buf = furi_string_alloc();
     item->type = XRemoteRemoteItemTypeSubGhz;
     item->time = 0;
-
     do {
-        if(!flipper_format_read_string(ff, "name", item->name)) break;
-        if(!flipper_format_read_string(ff, "filename", item->filename)) break;
-        success = true;
+        success = flipper_format_read_string(ff, "name", item->name) &&
+                  flipper_format_read_string(ff, "filename", item->filename);
+        if(!success) break;
+
     } while(false);
     furi_string_free(buf);
+    FURI_LOG_D(TAG, "final name: %s", furi_string_get_cstr(item->name));
+    FURI_LOG_D(TAG, "final filename: %s", furi_string_get_cstr(item->filename));
 
     return success;
 }
@@ -205,6 +207,10 @@ void xremote_cross_remote_item_set_name(CrossRemoteItem* item, const char* name)
     furi_string_set(item->name, name);
 }
 
+void xremote_cross_remote_item_set_filename(CrossRemoteItem* item, const char* filename) {
+    furi_string_set(item->filename, filename);
+}
+
 void xremote_cross_remote_item_set_time(CrossRemoteItem* item, uint32_t time) {
     item->time = time;
 }
@@ -221,6 +227,10 @@ const char* xremote_cross_remote_item_get_name(CrossRemoteItem* item) {
     return furi_string_get_cstr(item->name);
 }
 
+const char* xremote_cross_remote_item_get_filename(CrossRemoteItem* item) {
+    return furi_string_get_cstr(item->filename);
+}
+
 InfraredSignal* xremote_cross_remote_item_get_ir_signal(CrossRemoteItem* item) {
     return item->ir_signal;
 }
@@ -256,11 +266,11 @@ bool xremote_cross_remote_item_pause_save(FlipperFormat* ff, uint32_t time, cons
     return true;
 }
 
-bool xremote_cross_remote_item_sg_signal_save(SubGhzRemote* remote, FlipperFormat* ff, const char* name) {
+bool xremote_cross_remote_item_sg_signal_save(SubGhzRemote* remote, FlipperFormat* ff, const char* name, const char* filename) {
     if(!flipper_format_write_comment_cstr(ff, "") ||
        !flipper_format_write_string_cstr(ff, "remote_type", "SG") ||
        !flipper_format_write_string_cstr(ff, "name", name) ||
-       !flipper_format_write_string_cstr(ff, "filename", xremote_sg_remote_get_filename(remote))) {
+       !flipper_format_write_string_cstr(ff, "filename", filename)) {
         return false;
     }
     return xremote_sg_signal_save_data(remote, ff);

+ 3 - 1
models/cross/xremote_cross_remote_item.h

@@ -11,6 +11,8 @@ void xremote_cross_remote_item_free(CrossRemoteItem* item);
 
 void xremote_cross_remote_item_set_name(CrossRemoteItem* item, const char* name);
 const char* xremote_cross_remote_item_get_name(CrossRemoteItem* item);
+void xremote_cross_remote_item_set_filename(CrossRemoteItem* item, const char* filename);
+const char* xremote_cross_remote_item_get_filename(CrossRemoteItem* item);
 
 void xremote_cross_remote_item_set_type(CrossRemoteItem* item, int type);
 void xremote_cross_remote_item_set_time(CrossRemoteItem* item, uint32_t time);
@@ -23,4 +25,4 @@ void xremote_cross_remote_item_set_sg_signal(CrossRemoteItem* item, SubGhzRemote
 
 bool xremote_cross_remote_item_pause_save(FlipperFormat* ff, uint32_t time, const char* name);
 bool xremote_cross_remote_item_ir_signal_save(InfraredSignal* signal, FlipperFormat* ff, const char* name, uint32_t time);
-bool xremote_cross_remote_item_sg_signal_save(SubGhzRemote* remote, FlipperFormat* ff, const char* name);
+bool xremote_cross_remote_item_sg_signal_save(SubGhzRemote* remote, FlipperFormat* ff, const char* name, const char* filename);

+ 0 - 28
scenes/xremote_scene_create.c

@@ -16,7 +16,6 @@ static void xremote_create_callback(void* context, int32_t index, InputType type
     } else if(type == InputTypeRelease) {
         custom_type = XRemoteCustomEventMenuVoid;
     } else if(type == InputTypeShort) {
-        //somehow ButtonMenuItemTypeCommon uses InputTypeShort
         custom_type = XRemoteCustomEventMenuSelected;
     } else {
         furi_crash("Unexpected Input Type");
@@ -30,7 +29,6 @@ void xremote_scene_create_on_enter(void* context) {
     furi_assert(context);
     XRemote* app = context;
     ButtonMenu* button_menu = app->button_menu_create;
-    //SceneManager* scene_manager = app->scene_manager;
 
     size_t item_count = xremote_cross_remote_get_item_count(app->cross_remote);
     for(size_t i = 0; i < item_count; ++i) {
@@ -76,13 +74,6 @@ bool xremote_scene_create_on_event(void* context, SceneManagerEvent event) {
     if(event.type == SceneManagerEventTypeBack) {
         scene_manager_next_scene(app->scene_manager, XRemoteSceneMenu);
         consumed = true;
-        /*if(is_transmitter_idle) {
-            const uint32_t possible_scenes[] = {InfraredSceneRemoteList, InfraredSceneStart};
-            consumed = scene_manager_search_and_switch_to_previous_scene_one_of(
-                scene_manager, possible_scenes, COUNT_OF(possible_scenes));
-        } else {
-            consumed = true;
-        }*/
     } else if(event.type == SceneManagerEventTypeCustom) {
         const uint16_t custom_type = xremote_custom_menu_event_get_type(event.event);
         const int16_t button_index = xremote_custom_menu_event_get_value(event.event);
@@ -101,25 +92,6 @@ bool xremote_scene_create_on_event(void* context, SceneManagerEvent event) {
             app->edit_item = button_index;
             scene_manager_next_scene(app->scene_manager, XRemoteSceneEditItem);
         }
-        /*switch(event.event) {
-            case XRemoteCustomEventCreateLeft:
-            case XRemoteCustomEventCreateRight:
-                break;
-            case XRemoteCustomEventCreateUp:
-            case XRemoteCustomEventCreateDown:
-                break;
-            case XRemoteCustomEventCreateBack:
-                notification_message(app->notification, &sequence_reset_red);
-                notification_message(app->notification, &sequence_reset_green);
-                notification_message(app->notification, &sequence_reset_blue);
-                if(!scene_manager_search_and_switch_to_previous_scene(
-                    app->scene_manager, XRemoteSceneMenu)) {
-                        scene_manager_stop(app->scene_manager);
-                        view_dispatcher_stop(app->view_dispatcher);
-                    }
-                consumed = true;
-                break;
-        }*/
     }
 
     return consumed;

+ 9 - 4
scenes/xremote_scene_transmit.c

@@ -82,6 +82,11 @@ void xremote_scene_transmit_send_pause(XRemote* app, CrossRemoteItem* item) {
 void xremote_scene_transmit_send_subghz(XRemote* app, CrossRemoteItem* item) {
     app->transmitting = true;
     xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStartSend);
+    if (furi_string_utf8_length(item->filename) < 3) {
+        xremote_cross_remote_set_transmitting(app->cross_remote, XRemoteTransmittingStop);
+        app->transmitting = false;
+        return;
+    }
     subghz_send(app, furi_string_get_cstr(item->filename)); 
     //furi_thread_flags_wait(0, FuriFlagWaitAny, 2000);
 }
@@ -156,13 +161,13 @@ bool xremote_scene_transmit_on_event(void* context, SceneManagerEvent event) {
         FURI_LOG_D(TAG, "Custom Event");
         switch(event.event) {
             case XRemoteCustomEventViewTransmitterSendStop:
-                FURI_LOG_D("SUBGHZ", "stop event");
+                FURI_LOG_D("SUBGHZ", "stop event"); // doesn't trigger
                 //app->stop_transmit = true;
-                app->state_notifications = SubGhzNotificationStateIDLE;
+                /*app->state_notifications = SubGhzNotificationStateIDLE;
                 app->transmitting = false;
                 subghz_txrx_stop(app->subghz->txrx);
                 xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStop);
-                xremote_cross_remote_set_transmitting(app->cross_remote, XRemoteTransmittingStop);
+                xremote_cross_remote_set_transmitting(app->cross_remote, XRemoteTransmittingStop);*/
                 break;
             default: 
                 break;
@@ -182,6 +187,6 @@ void xremote_scene_transmit_on_exit(void* context) {
     XRemote* app = context;
     app->transmitting = false;
     app->state_notifications = SubGhzNotificationStateIDLE;
-    subghz_txrx_stop(app->subghz->txrx);
+    //subghz_txrx_stop(app->subghz->txrx);
     //xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingIdle);
 }