Skip to content

Commit

Permalink
A few more comments here and there.
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Dec 30, 2022
1 parent 7026e42 commit d57370e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
15 changes: 9 additions & 6 deletions app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -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++;
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions app.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ 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? */
};

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. */
Expand Down
11 changes: 9 additions & 2 deletions proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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,
};
Expand Down

0 comments on commit d57370e

Please sign in to comment.