Reformat document with VSCode.
This commit is contained in:
parent
9d123a5963
commit
69f7ee770d
@ -57,9 +57,10 @@ 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.
|
// Some parameters are only used by some events.
|
||||||
unsigned int number; // This data is specific to DemoEventSendCounter/DemoEventReceivedCounter/DemoEventSendTone/DemoEventReceivedTone.
|
InputEvent input;
|
||||||
FuriString* senderName; // This data is specific to DemoEventReceivedCounter/DemoEventReceivedTone.
|
unsigned int number;
|
||||||
|
FuriString* senderName;
|
||||||
} 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,
|
||||||
@ -129,7 +130,8 @@ static void subghz_demo_receive_data(DemoContext* instance) {
|
|||||||
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);
|
||||||
@ -138,7 +140,8 @@ static void subghz_demo_receive_data(DemoContext* instance) {
|
|||||||
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};
|
DemoEvent event = {
|
||||||
|
.type = DemoEventReceivedCounter, .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 counter message. >%s<", message);
|
FURI_LOG_W(TAG, "Failed to parse counter message. >%s<", message);
|
||||||
@ -147,11 +150,13 @@ static void subghz_demo_receive_data(DemoContext* instance) {
|
|||||||
|
|
||||||
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);
|
||||||
@ -241,11 +246,13 @@ static void subghz_demo_render_callback(Canvas* canvas, void* ctx) {
|
|||||||
|
|
||||||
furi_string_printf(data->buffer, "%04u", localCounter);
|
furi_string_printf(data->buffer, "%04u", localCounter);
|
||||||
canvas_set_font(canvas, FontSecondary);
|
canvas_set_font(canvas, FontSecondary);
|
||||||
canvas_draw_str_aligned(canvas, 64, 42, AlignCenter, AlignTop, furi_string_get_cstr(data->buffer));
|
canvas_draw_str_aligned(
|
||||||
|
canvas, 64, 42, AlignCenter, AlignTop, furi_string_get_cstr(data->buffer));
|
||||||
|
|
||||||
if(remoteCounter < 10000U) {
|
if(remoteCounter < 10000U) {
|
||||||
furi_string_printf(data->buffer, "Received %04u", remoteCounter);
|
furi_string_printf(data->buffer, "Received %04u", remoteCounter);
|
||||||
canvas_draw_str_aligned(canvas, 64, 52, AlignCenter, AlignTop, furi_string_get_cstr(data->buffer));
|
canvas_draw_str_aligned(
|
||||||
|
canvas, 64, 52, AlignCenter, AlignTop, furi_string_get_cstr(data->buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
furi_mutex_release(demo_context->mutex);
|
furi_mutex_release(demo_context->mutex);
|
||||||
@ -302,7 +309,8 @@ static void subghz_demo_broadcast(DemoContext* demo_context, FuriString* buffer)
|
|||||||
// Make sure our message will fit into a packet; if not truncate it.
|
// Make sure our message will fit into a packet; if not truncate it.
|
||||||
size_t length = strlen((char*)message);
|
size_t length = strlen((char*)message);
|
||||||
if(length > MESSAGE_MAX_LEN) {
|
if(length > MESSAGE_MAX_LEN) {
|
||||||
FURI_LOG_E(TAG, "Outgoing message bigger than %d bytes! >%s<", MESSAGE_MAX_LEN, (char*)message);
|
FURI_LOG_E(
|
||||||
|
TAG, "Outgoing message bigger than %d bytes! >%s<", MESSAGE_MAX_LEN, (char*)message);
|
||||||
|
|
||||||
// Add \r\n(null) to the end of the 0-indexed string.
|
// Add \r\n(null) to the end of the 0-indexed string.
|
||||||
message[MESSAGE_MAX_LEN - 1] = 0;
|
message[MESSAGE_MAX_LEN - 1] = 0;
|
||||||
@ -327,7 +335,14 @@ static void subghz_demo_broadcast_counter(DemoContext* demo_context, unsigned in
|
|||||||
FURI_LOG_I(TAG, "Sending counter %04u", counterToSend);
|
FURI_LOG_I(TAG, "Sending counter %04u", counterToSend);
|
||||||
|
|
||||||
// The message for a counter with value 42 should look like... "SGDEMO:CA0042:YourFlip\r\n"
|
// The message for a counter with value 42 should look like... "SGDEMO:CA0042:YourFlip\r\n"
|
||||||
furi_string_printf(data->buffer, "%s%c%c%04u:%s\r\n", SUBGHZ_GAME_NAME, DemoRfPurposeCounter, MAJOR_VERSION, counterToSend, furi_hal_version_get_name_ptr());
|
furi_string_printf(
|
||||||
|
data->buffer,
|
||||||
|
"%s%c%c%04u:%s\r\n",
|
||||||
|
SUBGHZ_GAME_NAME,
|
||||||
|
DemoRfPurposeCounter,
|
||||||
|
MAJOR_VERSION,
|
||||||
|
counterToSend,
|
||||||
|
furi_hal_version_get_name_ptr());
|
||||||
|
|
||||||
subghz_demo_broadcast(demo_context, data->buffer);
|
subghz_demo_broadcast(demo_context, data->buffer);
|
||||||
}
|
}
|
||||||
@ -340,7 +355,14 @@ static void subghz_demo_broadcast_tone(DemoContext* demo_context, unsigned int f
|
|||||||
FURI_LOG_I(TAG, "Sending frequency %04u", frequency);
|
FURI_LOG_I(TAG, "Sending frequency %04u", frequency);
|
||||||
|
|
||||||
// The message for a frequency of 440 should look like... "SGDEMO:TA440:YourFlip\r\n"
|
// The message for a frequency of 440 should look like... "SGDEMO:TA440:YourFlip\r\n"
|
||||||
furi_string_printf(data->buffer, "%s%c%c%u:%s\r\n", SUBGHZ_GAME_NAME, DemoRfPurposeTone, MAJOR_VERSION, frequency, furi_hal_version_get_name_ptr());
|
furi_string_printf(
|
||||||
|
data->buffer,
|
||||||
|
"%s%c%c%u:%s\r\n",
|
||||||
|
SUBGHZ_GAME_NAME,
|
||||||
|
DemoRfPurposeTone,
|
||||||
|
MAJOR_VERSION,
|
||||||
|
frequency,
|
||||||
|
furi_hal_version_get_name_ptr());
|
||||||
|
|
||||||
subghz_demo_broadcast(demo_context, data->buffer);
|
subghz_demo_broadcast(demo_context, data->buffer);
|
||||||
}
|
}
|
||||||
@ -414,7 +436,8 @@ int32_t subghz_demo_app(void* p) {
|
|||||||
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||||
|
|
||||||
// Update the screen fairly frequently (every 250 milliseconds.)
|
// Update the screen fairly frequently (every 250 milliseconds.)
|
||||||
FuriTimer* timer = furi_timer_alloc(subghz_demo_tick_callback, FuriTimerTypePeriodic, demo_context->queue);
|
FuriTimer* timer =
|
||||||
|
furi_timer_alloc(subghz_demo_tick_callback, FuriTimerTypePeriodic, demo_context->queue);
|
||||||
furi_timer_start(timer, 250);
|
furi_timer_start(timer, 250);
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
|
Loading…
Reference in New Issue
Block a user