Skip to content

Commit

Permalink
Callback after subghz. Waiting still not correct
Browse files Browse the repository at this point in the history
  • Loading branch information
David Lee committed Jan 29, 2024
1 parent 97c98a8 commit 644227f
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 36 deletions.
3 changes: 2 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
32 changes: 8 additions & 24 deletions helpers/subghz/subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 change: 1 addition & 0 deletions scenes/xremote_scene_menu.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "../helpers/subghz/subghz.h"
#include "../xremote.h"

enum SubmenuIndex {
Expand Down
55 changes: 44 additions & 11 deletions scenes/xremote_scene_transmit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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 change: 1 addition & 0 deletions xremote.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions xremote.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions xremote_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ typedef enum {
XRemoteTransmittingIdle,
XRemoteTransmittingStart,
XRemoteTransmittingStop,
XRemoteTransmittingStopSubghz,
} XRemoteRemoteTransmissionStatus;

struct InfraredSignal {
Expand Down

0 comments on commit 644227f

Please sign in to comment.