diff --git a/app.c b/app.c index 1ab3f2cef61..be0509fa98e 100644 --- a/app.c +++ b/app.c @@ -242,8 +242,6 @@ ProtoViewApp* protoview_app_alloc() { //init Worker & Protocol app->txrx = malloc(sizeof(ProtoViewTxRx)); - app->txrx->preset = malloc(sizeof(SubGhzRadioPreset)); - app->txrx->preset->name = furi_string_alloc(); /* Setup rx worker and environment. */ app->txrx->worker = subghz_worker_alloc(); @@ -286,8 +284,6 @@ void protoview_app_free(ProtoViewApp *app) { subghz_receiver_free(app->txrx->receiver); subghz_environment_free(app->txrx->environment); subghz_worker_free(app->txrx->worker); - furi_string_free(app->txrx->preset->name); - free(app->txrx->preset); free(app->txrx); furi_hal_power_suppress_charge_exit(); @@ -313,13 +309,21 @@ int32_t protoview_app_entry(void* p) { FuriTimer *timer = furi_timer_alloc(timer_callback, FuriTimerTypePeriodic, app); furi_timer_start(timer, furi_kernel_get_tick_frequency() / 10); + /* Start listening to signals immediately. */ radio_begin(app); radio_rx(app, FREQ); + /* This is the main event loop: here we get the events that are pushed + * in the queue by input_callback(), and process them one after the + * other. The timeout is 100 milliseconds, so if not input is received + * before such time, we exit the queue_get() function and call + * view_port_update() in order to refresh our screen content. */ InputEvent input; while(app->running) { FuriStatus qstat = furi_message_queue_get(app->event_queue, &input, 100); if (qstat == FuriStatusOk) { + FURI_LOG_E(TAG, "Main Loop - Input: %u", input.key); + if (input.key == InputKeyBack) { app->running = 0; } else if (input.key == InputKeyOk) { @@ -333,8 +337,6 @@ int32_t protoview_app_entry(void* p) { uint32_t scale_step = app->us_scale > 50 ? 50 : 10; if (app->us_scale > 10) app->us_scale -= scale_step; } - - FURI_LOG_E(TAG, "Main Loop - Input: %u", input.key); } else { static int c = 0; c++; @@ -343,6 +345,7 @@ int32_t protoview_app_entry(void* p) { view_port_update(app->view_port); } + /* App no longer running. Shut down and free. */ if (app->txrx->txrx_state == TxRxStateRx) { FURI_LOG_E(TAG, "Putting CC1101 to sleep before exiting."); radio_rx_end(app); diff --git a/app.h b/app.h index c1961fc6972..41f24ac8159 100644 --- a/app.h +++ b/app.h @@ -28,10 +28,9 @@ typedef enum { * It receives data and we get our protocol "feed" callback called * with the level (1 or 0) and duration. */ struct ProtoViewTxRx { - SubGhzWorker* worker; + SubGhzWorker* worker; /* Our background worker. */ SubGhzEnvironment* environment; SubGhzReceiver* receiver; - SubGhzRadioPreset* preset; TxRxState txrx_state; /* Receiving, idle or sleeping? */ }; @@ -39,10 +38,11 @@ typedef struct ProtoViewTxRx ProtoViewTxRx; struct ProtoViewApp { Gui *gui; - ViewPort *view_port; - FuriMessageQueue *event_queue; + ViewPort *view_port; /* We just use a raw viewport and we render + everything into the low level canvas. */ + FuriMessageQueue *event_queue; /* Keypress events go here. */ ProtoViewTxRx *txrx; /* Radio state. */ - SubGhzSetting *setting; + SubGhzSetting *setting; /* A list of valid frequencies. */ int running; /* Once false exists the app. */ uint32_t signal_bestlen; /* Longest coherent signal observed so far. */ uint32_t us_scale; /* microseconds per pixel. */ diff --git a/proto.c b/proto.c index c0dd0fc0ce2..0c7f29c1b05 100644 --- a/proto.c +++ b/proto.c @@ -40,7 +40,8 @@ void subghz_protocol_decoder_protoview_reset(void* context) { } /* That's the only thig we really use of the protocol decoder - * implementation. */ + * implementation. We avoid the subghz provided abstractions and put + * the data in our simple abstraction: the RawSamples circular buffer. */ void subghz_protocol_decoder_protoview_feed(void* context, bool level, uint32_t duration) { furi_assert(context); UNUSED(context); @@ -58,6 +59,7 @@ uint8_t subghz_protocol_decoder_protoview_get_hash_data(void* context) { return 123; } +/* Not used. */ bool subghz_protocol_decoder_protoview_serialize( void* context, FlipperFormat* flipper_format, @@ -69,6 +71,7 @@ bool subghz_protocol_decoder_protoview_serialize( return false; } +/* Not used. */ bool subghz_protocol_decoder_protoview_deserialize(void* context, FlipperFormat* flipper_format) { UNUSED(context); @@ -93,13 +96,17 @@ const SubGhzProtocolDecoder subghz_protocol_protoview_decoder = { .get_string = subhz_protocol_decoder_protoview_get_string, }; +/* Well, we don't really target a specific protocol. So let's put flags + * that make sense. */ const SubGhzProtocol subghz_protocol_protoview = { .name = "Protoview", .type = SubGhzProtocolTypeStatic, - .flag = SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable, + .flag = SubGhzProtocolFlag_AM | SubGhzProtocolFlag_FM | SubGhzProtocolFlag_Decodable, .decoder = &subghz_protocol_protoview_decoder, }; +/* Our table has just the single dummy protocol we defined for the + * sake of data collection. */ const SubGhzProtocol* protoview_protocol_registry_items[] = { &subghz_protocol_protoview, };