issue #2 - unused var gives errors in latest SDK
This commit is contained in:
parent
b6fef49575
commit
9d123a5963
@ -55,14 +55,14 @@ typedef enum {
|
|||||||
// Some data fields are only set for particular types.
|
// Some data fields are only set for particular types.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
DemoEventType type; // The reason for this event.
|
DemoEventType type; // The reason for this event.
|
||||||
|
|
||||||
// You can add additional data that is helpful for your events.
|
// You can add additional data that is helpful for your events.
|
||||||
InputEvent input; // This data is specific to DemoEventTypeKey.
|
InputEvent input; // This data is specific to DemoEventTypeKey.
|
||||||
unsigned int number; // This data is specific to DemoEventSendCounter/DemoEventReceivedCounter/DemoEventSendTone/DemoEventReceivedTone.
|
unsigned int number; // This data is specific to DemoEventSendCounter/DemoEventReceivedCounter/DemoEventSendTone/DemoEventReceivedTone.
|
||||||
FuriString* senderName; // This data is specific to DemoEventReceivedCounter/DemoEventReceivedTone.
|
FuriString* senderName; // This data is specific to DemoEventReceivedCounter/DemoEventReceivedTone.
|
||||||
} DemoEvent;
|
} DemoEvent;
|
||||||
|
|
||||||
// This is the data for our application. You might have a game board,
|
// This is the data for our application. You might have a game board,
|
||||||
// current player, etc. For this demo we have two counters & a general purpose buffer.
|
// current player, etc. For this demo we have two counters & a general purpose buffer.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
FuriString* buffer;
|
FuriString* buffer;
|
||||||
@ -77,7 +77,7 @@ typedef struct {
|
|||||||
FuriMessageQueue* queue; // Message queue (DemoEvent items to process).
|
FuriMessageQueue* queue; // Message queue (DemoEvent items to process).
|
||||||
FuriMutex* mutex; // Used to provide thread safe access to data.
|
FuriMutex* mutex; // Used to provide thread safe access to data.
|
||||||
DemoData* data; // Data accessed by multiple threads (acquire the mutex before accessing!)
|
DemoData* data; // Data accessed by multiple threads (acquire the mutex before accessing!)
|
||||||
|
|
||||||
// Used for subghz communication
|
// Used for subghz communication
|
||||||
SubGhzTxRxWorker* subghz_txrx;
|
SubGhzTxRxWorker* subghz_txrx;
|
||||||
} DemoContext;
|
} DemoContext;
|
||||||
@ -103,8 +103,8 @@ static void subghz_demo_receive_data(DemoContext* instance) {
|
|||||||
size_t game_name_len = strlen(SUBGHZ_GAME_NAME);
|
size_t game_name_len = strlen(SUBGHZ_GAME_NAME);
|
||||||
if (len < (game_name_len + 2)) {
|
if (len < (game_name_len + 2)) {
|
||||||
FURI_LOG_D(TAG, "Message not long enough. >%s<", message);
|
FURI_LOG_D(TAG, "Message not long enough. >%s<", message);
|
||||||
|
|
||||||
// Message wasn't big enough to have our game name + the reason code + version; so it must not be for us.
|
// Message wasn't big enough to have our game name + the reason code + version; so it must not be for us.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,56 +118,56 @@ static void subghz_demo_receive_data(DemoContext* instance) {
|
|||||||
|
|
||||||
// Right now we don't care much about the version of the application, but in the future we might need to
|
// Right now we don't care much about the version of the application, but in the future we might need to
|
||||||
// respond differently based on the version of the application running on the other Flipper Zero.
|
// respond differently based on the version of the application running on the other Flipper Zero.
|
||||||
// Important: Don't always trust what is sent, some people with Flipper Zero might send an
|
// Important: Don't always trust what is sent, some people with Flipper Zero might send an
|
||||||
// invalid version to trick your code into interpreting the payload in a special way.
|
// invalid version to trick your code into interpreting the payload in a special way.
|
||||||
|
|
||||||
// Null terminate the buffer at the end of message so we don't accidently overrun our buffer.
|
// Null terminate the buffer at the end of message so we don't accidently overrun our buffer.
|
||||||
message[MESSAGE_MAX_LEN - 1] = 0;
|
message[MESSAGE_MAX_LEN - 1] = 0;
|
||||||
|
|
||||||
unsigned int number;
|
unsigned int number;
|
||||||
char senderName[9];
|
char senderName[9];
|
||||||
switch (purpose) {
|
switch (purpose) {
|
||||||
case DemoRfPurposeCounter:
|
case DemoRfPurposeCounter:
|
||||||
// We expect this mesage to contain both the count and the sender name.
|
// We expect this mesage to contain both the count and the sender name.
|
||||||
if (sscanf((const char*)message+game_name_len+2, "%04u:%8s", &number, senderName) == 2) {
|
if (sscanf((const char*)message+game_name_len+2, "%04u:%8s", &number, senderName) == 2) {
|
||||||
// IMPORTANT: The code processing the event needs to furi_string_free the senderName!
|
// IMPORTANT: The code processing the event needs to furi_string_free the senderName!
|
||||||
FuriString* name = furi_string_alloc();
|
FuriString* name = furi_string_alloc();
|
||||||
furi_string_set(name, senderName);
|
furi_string_set(name, senderName);
|
||||||
// The counter is supposed to be a 4 digit number.
|
// The counter is supposed to be a 4 digit number.
|
||||||
if (number >= 10000U) {
|
if (number >= 10000U) {
|
||||||
FURI_LOG_W(TAG, "Number was >= 10000U. >%s<", message);
|
FURI_LOG_W(TAG, "Number was >= 10000U. >%s<", message);
|
||||||
number %= 10000U;
|
number %= 10000U;
|
||||||
}
|
|
||||||
DemoEvent event = {.type = DemoEventReceivedCounter, .number = number, .senderName = name};
|
|
||||||
furi_message_queue_put(instance->queue, &event, FuriWaitForever);
|
|
||||||
} else {
|
|
||||||
FURI_LOG_W(TAG, "Failed to parse counter message. >%s<", message);
|
|
||||||
}
|
}
|
||||||
|
DemoEvent event = {.type = DemoEventReceivedCounter, .number = number, .senderName = name};
|
||||||
|
furi_message_queue_put(instance->queue, &event, FuriWaitForever);
|
||||||
|
} else {
|
||||||
|
FURI_LOG_W(TAG, "Failed to parse counter message. >%s<", message);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DemoRfPurposeTone:
|
case DemoRfPurposeTone:
|
||||||
// We expect this message to contain both the frequency and the sender name.
|
// We expect this message to contain both the frequency and the sender name.
|
||||||
if (sscanf((const char*)message+game_name_len+2, "%u:%8s", &number, senderName) == 2) {
|
if (sscanf((const char*)message+game_name_len+2, "%u:%8s", &number, senderName) == 2) {
|
||||||
// IMPORTANT: The code processing the event needs to furi_string_free the senderName!
|
// IMPORTANT: The code processing the event needs to furi_string_free the senderName!
|
||||||
FuriString* name = furi_string_alloc();
|
FuriString* name = furi_string_alloc();
|
||||||
furi_string_set(name, senderName);
|
furi_string_set(name, senderName);
|
||||||
DemoEvent event = {.type = DemoEventReceivedTone, .number = number, .senderName = name};
|
DemoEvent event = {.type = DemoEventReceivedTone, .number = number, .senderName = name};
|
||||||
furi_message_queue_put(instance->queue, &event, FuriWaitForever);
|
furi_message_queue_put(instance->queue, &event, FuriWaitForever);
|
||||||
} else {
|
} else {
|
||||||
FURI_LOG_W(TAG, "Failed to parse tone message. >%s<", message);
|
FURI_LOG_W(TAG, "Failed to parse tone message. >%s<", message);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Add parsing for other messages here.
|
// Add parsing for other messages here.
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (version <= MAJOR_VERSION) {
|
if (version <= MAJOR_VERSION) {
|
||||||
// The version is same or less than ours, so we should know about the message purpose.
|
// The version is same or less than ours, so we should know about the message purpose.
|
||||||
FURI_LOG_W(TAG, "Message purpose not handled for known version. >%s<", message);
|
FURI_LOG_W(TAG, "Message purpose not handled for known version. >%s<", message);
|
||||||
} else {
|
} else {
|
||||||
// The version is newer, so it's not surprising we don't know about the purpose.
|
// The version is newer, so it's not surprising we don't know about the purpose.
|
||||||
FURI_LOG_T(TAG, "Message purpose not handled. >%s<", message);
|
FURI_LOG_T(TAG, "Message purpose not handled. >%s<", message);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -175,7 +175,7 @@ static void subghz_demo_receive_data(DemoContext* instance) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This gets invoked when input (button press) is detected.
|
// This gets invoked when input (button press) is detected.
|
||||||
// We queue a DemoEventTypeKey message with the input event data.
|
// We queue a DemoEventTypeKey message with the input event data.
|
||||||
static void subghz_demo_input_callback(InputEvent* input_event, void* ctx_q) {
|
static void subghz_demo_input_callback(InputEvent* input_event, void* ctx_q) {
|
||||||
furi_assert(ctx_q);
|
furi_assert(ctx_q);
|
||||||
@ -184,7 +184,7 @@ static void subghz_demo_input_callback(InputEvent* input_event, void* ctx_q) {
|
|||||||
furi_message_queue_put(queue, &event, FuriWaitForever);
|
furi_message_queue_put(queue, &event, FuriWaitForever);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We register this callback to get invoked by the timer on every tick.
|
// We register this callback to get invoked by the timer on every tick.
|
||||||
// We queue a DemoEventTypeTick message and then return to the caller.
|
// We queue a DemoEventTypeTick message and then return to the caller.
|
||||||
static void subghz_demo_tick_callback(void* ctx_q) {
|
static void subghz_demo_tick_callback(void* ctx_q) {
|
||||||
furi_assert(ctx_q);
|
furi_assert(ctx_q);
|
||||||
@ -211,13 +211,12 @@ static void subghz_demo_send_count(void* ctx) {
|
|||||||
static void subghz_demo_send_tone(void* ctx, unsigned int frequency) {
|
static void subghz_demo_send_tone(void* ctx, unsigned int frequency) {
|
||||||
furi_assert(ctx);
|
furi_assert(ctx);
|
||||||
DemoContext* demo_context = ctx;
|
DemoContext* demo_context = ctx;
|
||||||
DemoData* data = demo_context->data;
|
|
||||||
FuriMessageQueue* queue = demo_context->queue;
|
FuriMessageQueue* queue = demo_context->queue;
|
||||||
DemoEvent event = {.type = DemoEventSendTone, .number = frequency};
|
DemoEvent event = {.type = DemoEventSendTone, .number = frequency};
|
||||||
furi_message_queue_put(queue, &event, FuriWaitForever);
|
furi_message_queue_put(queue, &event, FuriWaitForever);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We register this callback to get invoked whenever we need to render the screen.
|
// We register this callback to get invoked whenever we need to render the screen.
|
||||||
// We render the UI on this callback thread.
|
// We render the UI on this callback thread.
|
||||||
static void subghz_demo_render_callback(Canvas* canvas, void* ctx) {
|
static void subghz_demo_render_callback(Canvas* canvas, void* ctx) {
|
||||||
furi_assert(ctx);
|
furi_assert(ctx);
|
||||||
@ -256,7 +255,7 @@ static void subghz_demo_render_callback(Canvas* canvas, void* ctx) {
|
|||||||
// We increment our counter (wrapping back to 0 if it exceeds a 4 digit number.)
|
// We increment our counter (wrapping back to 0 if it exceeds a 4 digit number.)
|
||||||
static void subghz_demo_update_local_counter(DemoContext* demo_context) {
|
static void subghz_demo_update_local_counter(DemoContext* demo_context) {
|
||||||
DemoData* data = demo_context->data;
|
DemoData* data = demo_context->data;
|
||||||
|
|
||||||
// Increment the counter (which is supposed to be a 4 digit number for this app.)
|
// Increment the counter (which is supposed to be a 4 digit number for this app.)
|
||||||
data->localCounter++;
|
data->localCounter++;
|
||||||
if (data->localCounter >= 10000U) {
|
if (data->localCounter >= 10000U) {
|
||||||
@ -280,8 +279,7 @@ static void subghz_demo_update_remote_counter(DemoContext* demo_context, DemoEve
|
|||||||
// Our DemoEventReceivedTone handler invokes this method.
|
// Our DemoEventReceivedTone handler invokes this method.
|
||||||
// We play a quick (100ms) tone of the desired frequency.
|
// We play a quick (100ms) tone of the desired frequency.
|
||||||
static void subghz_demo_play_tone(DemoContext* demo_context, DemoEvent* event) {
|
static void subghz_demo_play_tone(DemoContext* demo_context, DemoEvent* event) {
|
||||||
DemoData* data = demo_context->data;
|
UNUSED(demo_context);
|
||||||
|
|
||||||
unsigned int frequency = event->number;
|
unsigned int frequency = event->number;
|
||||||
FURI_LOG_I(TAG, "Playing frequency %04u", frequency);
|
FURI_LOG_I(TAG, "Playing frequency %04u", frequency);
|
||||||
|
|
||||||
@ -425,67 +423,67 @@ int32_t subghz_demo_app(void* p) {
|
|||||||
do {
|
do {
|
||||||
if (furi_message_queue_get(demo_context->queue, &event, FuriWaitForever) == FuriStatusOk) {
|
if (furi_message_queue_get(demo_context->queue, &event, FuriWaitForever) == FuriStatusOk) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case DemoEventTypeKey:
|
case DemoEventTypeKey:
|
||||||
// Short press of OK button, queue DemoEventSendCounter event with the current count.
|
// Short press of OK button, queue DemoEventSendCounter event with the current count.
|
||||||
if(event.input.type == InputTypeShort && event.input.key == InputKeyOk) {
|
if(event.input.type == InputTypeShort && event.input.key == InputKeyOk) {
|
||||||
furi_mutex_acquire(demo_context->mutex, FuriWaitForever);
|
|
||||||
subghz_demo_send_count(demo_context);
|
|
||||||
furi_mutex_release(demo_context->mutex);
|
|
||||||
}
|
|
||||||
// Short press of UP button, queue DemoEventSendTone event.
|
|
||||||
else if(event.input.type == InputTypeShort && event.input.key == InputKeyUp) {
|
|
||||||
furi_mutex_acquire(demo_context->mutex, FuriWaitForever);
|
|
||||||
subghz_demo_send_tone(demo_context, 440U);
|
|
||||||
furi_mutex_release(demo_context->mutex);
|
|
||||||
}
|
|
||||||
// Long press of UP button, queue DemoEventSendTone event.
|
|
||||||
else if (event.input.type == InputTypeLong && event.input.key == InputKeyUp) {
|
|
||||||
furi_mutex_acquire(demo_context->mutex, FuriWaitForever);
|
|
||||||
subghz_demo_send_tone(demo_context, 880U);
|
|
||||||
furi_mutex_release(demo_context->mutex);
|
|
||||||
}
|
|
||||||
// Short press of back button exits the program.
|
|
||||||
else if(event.input.type == InputTypeShort && event.input.key == InputKeyBack) {
|
|
||||||
processing = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DemoEventTypeTick:
|
|
||||||
// Every timer tick we update the counter.
|
|
||||||
furi_mutex_acquire(demo_context->mutex, FuriWaitForever);
|
furi_mutex_acquire(demo_context->mutex, FuriWaitForever);
|
||||||
subghz_demo_update_local_counter(demo_context);
|
subghz_demo_send_count(demo_context);
|
||||||
furi_mutex_release(demo_context->mutex);
|
furi_mutex_release(demo_context->mutex);
|
||||||
break;
|
}
|
||||||
case DemoEventSendCounter:
|
// Short press of UP button, queue DemoEventSendTone event.
|
||||||
// Actually send the counter value to the other Flipper Zero.
|
else if(event.input.type == InputTypeShort && event.input.key == InputKeyUp) {
|
||||||
furi_mutex_acquire(demo_context->mutex, FuriWaitForever);
|
furi_mutex_acquire(demo_context->mutex, FuriWaitForever);
|
||||||
subghz_demo_broadcast_counter(demo_context, event.number);
|
subghz_demo_send_tone(demo_context, 440U);
|
||||||
furi_mutex_release(demo_context->mutex);
|
furi_mutex_release(demo_context->mutex);
|
||||||
break;
|
}
|
||||||
case DemoEventSendTone:
|
// Long press of UP button, queue DemoEventSendTone event.
|
||||||
// Actually send the frequency value to the other Flipper Zero.
|
else if (event.input.type == InputTypeLong && event.input.key == InputKeyUp) {
|
||||||
furi_mutex_acquire(demo_context->mutex, FuriWaitForever);
|
furi_mutex_acquire(demo_context->mutex, FuriWaitForever);
|
||||||
subghz_demo_broadcast_tone(demo_context, event.number);
|
subghz_demo_send_tone(demo_context, 880U);
|
||||||
furi_mutex_release(demo_context->mutex);
|
furi_mutex_release(demo_context->mutex);
|
||||||
break;
|
}
|
||||||
case DemoEventDataDetected:
|
// Short press of back button exits the program.
|
||||||
// Another Flipper sent us data! Process it, potentially queuing an event.
|
else if(event.input.type == InputTypeShort && event.input.key == InputKeyBack) {
|
||||||
subghz_demo_receive_data(demo_context);
|
processing = false;
|
||||||
break;
|
}
|
||||||
case DemoEventReceivedCounter:
|
break;
|
||||||
// Process the counter sent by the other Flipper Zero.
|
case DemoEventTypeTick:
|
||||||
furi_mutex_acquire(demo_context->mutex, FuriWaitForever);
|
// Every timer tick we update the counter.
|
||||||
subghz_demo_update_remote_counter(demo_context, &event);
|
furi_mutex_acquire(demo_context->mutex, FuriWaitForever);
|
||||||
furi_mutex_release(demo_context->mutex);
|
subghz_demo_update_local_counter(demo_context);
|
||||||
break;
|
furi_mutex_release(demo_context->mutex);
|
||||||
case DemoEventReceivedTone:
|
break;
|
||||||
// Process the tone sent by the other Flipper Zero.
|
case DemoEventSendCounter:
|
||||||
furi_mutex_acquire(demo_context->mutex, FuriWaitForever);
|
// Actually send the counter value to the other Flipper Zero.
|
||||||
subghz_demo_play_tone(demo_context, &event);
|
furi_mutex_acquire(demo_context->mutex, FuriWaitForever);
|
||||||
furi_mutex_release(demo_context->mutex);
|
subghz_demo_broadcast_counter(demo_context, event.number);
|
||||||
break;
|
furi_mutex_release(demo_context->mutex);
|
||||||
default:
|
break;
|
||||||
FURI_LOG_E(TAG, "Queue had unknown message type: %u", event.type);
|
case DemoEventSendTone:
|
||||||
break;
|
// Actually send the frequency value to the other Flipper Zero.
|
||||||
|
furi_mutex_acquire(demo_context->mutex, FuriWaitForever);
|
||||||
|
subghz_demo_broadcast_tone(demo_context, event.number);
|
||||||
|
furi_mutex_release(demo_context->mutex);
|
||||||
|
break;
|
||||||
|
case DemoEventDataDetected:
|
||||||
|
// Another Flipper sent us data! Process it, potentially queuing an event.
|
||||||
|
subghz_demo_receive_data(demo_context);
|
||||||
|
break;
|
||||||
|
case DemoEventReceivedCounter:
|
||||||
|
// Process the counter sent by the other Flipper Zero.
|
||||||
|
furi_mutex_acquire(demo_context->mutex, FuriWaitForever);
|
||||||
|
subghz_demo_update_remote_counter(demo_context, &event);
|
||||||
|
furi_mutex_release(demo_context->mutex);
|
||||||
|
break;
|
||||||
|
case DemoEventReceivedTone:
|
||||||
|
// Process the tone sent by the other Flipper Zero.
|
||||||
|
furi_mutex_acquire(demo_context->mutex, FuriWaitForever);
|
||||||
|
subghz_demo_play_tone(demo_context, &event);
|
||||||
|
furi_mutex_release(demo_context->mutex);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
FURI_LOG_E(TAG, "Queue had unknown message type: %u", event.type);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If message contains a sender name furi_string, free it.
|
// If message contains a sender name furi_string, free it.
|
||||||
@ -517,9 +515,9 @@ int32_t subghz_demo_app(void* p) {
|
|||||||
furi_string_free(demo_context->data->buffer);
|
furi_string_free(demo_context->data->buffer);
|
||||||
free(demo_context->data);
|
free(demo_context->data);
|
||||||
free(demo_context);
|
free(demo_context);
|
||||||
|
|
||||||
// Reenable charging.
|
// Reenable charging.
|
||||||
furi_hal_power_suppress_charge_exit();
|
furi_hal_power_suppress_charge_exit();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user