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

Callback after subghz. Waiting still not correct

David Lee 1 год назад
Родитель
Сommit
644227f8be
7 измененных файлов с 58 добавлено и 36 удалено
  1. 2 1
      docs/changelog.md
  2. 8 24
      helpers/subghz/subghz.c
  3. 1 0
      scenes/xremote_scene_menu.c
  4. 44 11
      scenes/xremote_scene_transmit.c
  5. 1 0
      xremote.c
  6. 1 0
      xremote.h
  7. 1 0
      xremote_i.h

+ 2 - 1
docs/changelog.md

@@ -1,5 +1,6 @@
 ## v2.0
-
+- SubGhz Functionality added
+- Slight change in Storage format to enalbe individual IR timings later (feature request)
 - Fixed more memory leaks
 
 ## v1.1

+ 8 - 24
helpers/subghz/subghz.c

@@ -28,33 +28,23 @@ void subghz_free(SubGhz* subghz) {
 
 void subghz_scene_transmit_callback_end_tx(void* context) {
     furi_assert(context);
-    //UNUSED(context);
     FURI_LOG_D(TAG, "callback end");
     XRemote* app = context;
     view_dispatcher_send_custom_event(
         app->view_dispatcher, XRemoteCustomEventViewTransmitterSendStop);
+
+
+    //app->state_notifications = SubGhzNotificationStateIDLE;
+    //subghz_txrx_stop(app->subghz->txrx);
+    //app->transmitting = false;
+    //xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStop);
+    xremote_cross_remote_set_transmitting(app->cross_remote, XRemoteTransmittingStop);
 }
 
 void subghz_send(void* context, const char* path) {
-    //UNUSED(context);
     XRemote* app = context;
-    //SubGhz* subghz = subghz_alloc();
-
-    FURI_LOG_D(TAG, "loading protocol from file");
+    
     subghz_load_protocol_from_file(app->subghz, path);
-
-    /*Storage* storage = furi_record_open(RECORD_STORAGE);
-    FlipperFormat* ff = flipper_format_file_alloc(storage);
-
-    if(!flipper_format_file_open_existing(ff, MEAL_PAGER_TMP_FILE)) {
-        //totp_close_config_file(fff_file);
-        FURI_LOG_E(TAG, "Error reading Temp File %s", MEAL_PAGER_TMP_FILE);
-        furi_record_close(RECORD_STORAGE);
-        return;
-    }*/
-
-    //subghz_txrx_tx_start(subghz->txrx, ff);
-
     FURI_LOG_D(TAG, "Starting Transmission");
     subghz_txrx_tx_start(
         app->subghz->txrx,
@@ -65,13 +55,7 @@ void subghz_send(void* context, const char* path) {
         app->subghz->txrx, subghz_scene_transmit_callback_end_tx, app);
     app->state_notifications = SubGhzNotificationStateTx;
 
-    /*flipper_format_rewind(ff);
-    flipper_format_file_close(ff);
-    flipper_format_free(ff);
 
-    furi_record_close(RECORD_STORAGE);*/
 
-    //subghz_free(subghz);
     FURI_LOG_D(TAG, "Finished Transmitting");
-    //meal_pager_blink_stop(app);
 }

+ 1 - 0
scenes/xremote_scene_menu.c

@@ -1,3 +1,4 @@
+#include "../helpers/subghz/subghz.h"
 #include "../xremote.h"
 
 enum SubmenuIndex {

+ 44 - 11
scenes/xremote_scene_transmit.c

@@ -80,15 +80,13 @@ void xremote_scene_transmit_send_pause(XRemote* app, CrossRemoteItem* item) {
 }
 
 void xremote_scene_transmit_send_subghz(XRemote* app, CrossRemoteItem* item) {
-    UNUSED(item);
     app->transmitting = true;
     xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStartSend);
     // ADD SEND METHOD HERE
-    //FURI_LOG_D("SUBGZK", "path: %s", furi_string_get_cstr(item->filename));
     subghz_send(app, furi_string_get_cstr(item->filename)); //currently crashes, null pointer
-    furi_thread_flags_wait(0, FuriFlagWaitAny, 2000); //Remove later
-    app->transmitting = false;
-    xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStop);
+    //furi_thread_flags_wait(0, FuriFlagWaitAny, 2000); //Remove later
+    //app->transmitting = false;
+    //xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStop);
 }
 
 void xremote_scene_transmit_send_signal(void* context, CrossRemoteItem* item) {
@@ -104,13 +102,15 @@ void xremote_scene_transmit_send_signal(void* context, CrossRemoteItem* item) {
     xremote_transmit_model_set_type(app->xremote_transmit, item->type);
     if(item->type == XRemoteRemoteItemTypeInfrared) {
         xremote_scene_transmit_send_ir_signal(app, item);
+        xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingStop);
     } else if(item->type == XRemoteRemoteItemTypePause) {
         xremote_scene_transmit_send_pause(app, item);
+        xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingStop);
     } else if(item->type == XRemoteRemoteItemTypeSubGhz) {
         xremote_scene_transmit_send_subghz(app, item);
     }
 
-    xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingStop);
+    //xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingStop);
 }
 
 void xremote_scene_transmit_run_remote(void* context) {
@@ -125,7 +125,16 @@ void xremote_scene_transmit_run_remote(void* context) {
             CrossRemoteItem* item = xremote_cross_remote_get_item(remote, i);
             xremote_scene_transmit_send_signal(app, item);
             //furi_thread_flags_wait(0, FuriFlagWaitAny, 2000);
-            xremote_scene_ir_notification_message(app, InfraredNotificationMessageBlinkStartSend);
+            //furi_thread_flags_wait(0, FuriFlagWaitAny, 1000);
+            //xremote_scene_ir_notification_message(app, InfraredNotificationMessageBlinkStartSend);
+        } else if(xremote_cross_remote_get_transmitting(remote) == XRemoteTransmittingStopSubghz) {
+            i++;
+            app->state_notifications = SubGhzNotificationStateIDLE;
+            subghz_txrx_stop(app->subghz->txrx);
+            app->transmitting = false;
+            xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStop);
+            xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingIdle);
+            //furi_thread_flags_wait(0, FuriFlagWaitAny, 1000);
         } else if(xremote_cross_remote_get_transmitting(remote) == XRemoteTransmittingStop) {
             i++;
             xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingIdle);
@@ -149,14 +158,38 @@ void xremote_scene_transmit_on_enter(void* context) {
 
 bool xremote_scene_transmit_on_event(void* context, SceneManagerEvent event) {
     XRemote* app = context;
-
-    UNUSED(app);
-    UNUSED(event);
     bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        FURI_LOG_D(TAG, "Custom Event");
+        switch(event.event) {
+            case XRemoteCustomEventViewTransmitterSendStop:
+                FURI_LOG_D("SUBGHZ", "stop event");
+                //app->stop_transmit = true;
+                app->state_notifications = SubGhzNotificationStateIDLE;
+                subghz_txrx_stop(app->subghz->txrx);
+                app->transmitting = false;
+                xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStop);
+                xremote_cross_remote_set_transmitting(app->cross_remote, XRemoteTransmittingStop);
+                break;
+            default: 
+                break;
+        }
+    } else if(event.type == SceneManagerEventTypeTick) {
+        FURI_LOG_D(TAG, "Tick Event");
+        if (app->state_notifications == SubGhzNotificationStateTx && app->led == 1) {
+            //blink for subghz
+        }
+    }
+
+    
     return consumed;
 }
 
 void xremote_scene_transmit_on_exit(void* context) {
     XRemote* app = context;
-    UNUSED(app);
+    app->transmitting = false;
+    subghz_txrx_stop(app->subghz->txrx);
+    app->state_notifications = SubGhzNotificationStateIDLE;
+    //xremote_cross_remote_set_transmitting(remote, XRemoteTransmittingIdle);
 }

+ 1 - 0
xremote.c

@@ -49,6 +49,7 @@ XRemote* xremote_app_alloc() {
     app->transmitting = 0;
     app->ir_timing = 1000;
     app->ir_timing_char = "1000";
+    app->stop_transmit = false;
 
     // Load configs
     xremote_read_settings(app);

+ 1 - 0
xremote.h

@@ -46,6 +46,7 @@ typedef struct {
     uint32_t ir_timing;
     char* ir_timing_char;
     bool transmitting;
+    bool stop_transmit;
     char text_store[XREMOTE_TEXT_STORE_NUM][XREMOTE_TEXT_STORE_SIZE + 1];
     SubGhz* subghz;
 } XRemote;

+ 1 - 0
xremote_i.h

@@ -87,6 +87,7 @@ typedef enum {
     XRemoteTransmittingIdle,
     XRemoteTransmittingStart,
     XRemoteTransmittingStop,
+    XRemoteTransmittingStopSubghz,
 } XRemoteRemoteTransmissionStatus;
 
 struct InfraredSignal {