issue #2 - unused var gives errors in latest SDK

This commit is contained in:
Derek Jamison 2023-03-04 10:06:26 -05:00
parent b6fef49575
commit 9d123a5963

View File

@ -127,47 +127,47 @@ static void subghz_demo_receive_data(DemoContext* instance) {
unsigned int number;
char senderName[9];
switch (purpose) {
case DemoRfPurposeCounter:
// 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) {
// IMPORTANT: The code processing the event needs to furi_string_free the senderName!
FuriString* name = furi_string_alloc();
furi_string_set(name, senderName);
// The counter is supposed to be a 4 digit number.
if (number >= 10000U) {
FURI_LOG_W(TAG, "Number was >= 10000U. >%s<", message);
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);
case DemoRfPurposeCounter:
// 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) {
// IMPORTANT: The code processing the event needs to furi_string_free the senderName!
FuriString* name = furi_string_alloc();
furi_string_set(name, senderName);
// The counter is supposed to be a 4 digit number.
if (number >= 10000U) {
FURI_LOG_W(TAG, "Number was >= 10000U. >%s<", message);
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);
}
break;
case DemoRfPurposeTone:
// 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) {
// IMPORTANT: The code processing the event needs to furi_string_free the senderName!
FuriString* name = furi_string_alloc();
furi_string_set(name, senderName);
DemoEvent event = {.type = DemoEventReceivedTone, .number = number, .senderName = name};
furi_message_queue_put(instance->queue, &event, FuriWaitForever);
} else {
FURI_LOG_W(TAG, "Failed to parse tone message. >%s<", message);
}
case DemoRfPurposeTone:
// 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) {
// IMPORTANT: The code processing the event needs to furi_string_free the senderName!
FuriString* name = furi_string_alloc();
furi_string_set(name, senderName);
DemoEvent event = {.type = DemoEventReceivedTone, .number = number, .senderName = name};
furi_message_queue_put(instance->queue, &event, FuriWaitForever);
} else {
FURI_LOG_W(TAG, "Failed to parse tone message. >%s<", message);
}
break;
// Add parsing for other messages here.
default:
if (version <= MAJOR_VERSION) {
// 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);
} else {
// 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);
}
default:
if (version <= MAJOR_VERSION) {
// 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);
} else {
// 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);
}
break;
}
} else {
@ -211,7 +211,6 @@ static void subghz_demo_send_count(void* ctx) {
static void subghz_demo_send_tone(void* ctx, unsigned int frequency) {
furi_assert(ctx);
DemoContext* demo_context = ctx;
DemoData* data = demo_context->data;
FuriMessageQueue* queue = demo_context->queue;
DemoEvent event = {.type = DemoEventSendTone, .number = frequency};
furi_message_queue_put(queue, &event, FuriWaitForever);
@ -280,8 +279,7 @@ static void subghz_demo_update_remote_counter(DemoContext* demo_context, DemoEve
// Our DemoEventReceivedTone handler invokes this method.
// We play a quick (100ms) tone of the desired frequency.
static void subghz_demo_play_tone(DemoContext* demo_context, DemoEvent* event) {
DemoData* data = demo_context->data;
UNUSED(demo_context);
unsigned int frequency = event->number;
FURI_LOG_I(TAG, "Playing frequency %04u", frequency);
@ -425,67 +423,67 @@ int32_t subghz_demo_app(void* p) {
do {
if (furi_message_queue_get(demo_context->queue, &event, FuriWaitForever) == FuriStatusOk) {
switch (event.type) {
case DemoEventTypeKey:
// Short press of OK button, queue DemoEventSendCounter event with the current count.
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.
case DemoEventTypeKey:
// Short press of OK button, queue DemoEventSendCounter event with the current count.
if(event.input.type == InputTypeShort && event.input.key == InputKeyOk) {
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);
break;
case DemoEventSendCounter:
// Actually send the counter value to the other Flipper Zero.
}
// 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_broadcast_counter(demo_context, event.number);
subghz_demo_send_tone(demo_context, 440U);
furi_mutex_release(demo_context->mutex);
break;
case DemoEventSendTone:
// Actually send the frequency value to the other Flipper Zero.
}
// 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_broadcast_tone(demo_context, event.number);
subghz_demo_send_tone(demo_context, 880U);
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;
}
// 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);
subghz_demo_update_local_counter(demo_context);
furi_mutex_release(demo_context->mutex);
break;
case DemoEventSendCounter:
// Actually send the counter value to the other Flipper Zero.
furi_mutex_acquire(demo_context->mutex, FuriWaitForever);
subghz_demo_broadcast_counter(demo_context, event.number);
furi_mutex_release(demo_context->mutex);
break;
case DemoEventSendTone:
// 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.