Skip to content

Commit 6635f45

Browse files
committed
Lora frequency error on LoRa information page
1 parent 5b06b10 commit 6635f45

3 files changed

Lines changed: 32 additions & 10 deletions

File tree

components/usb-host/src/hid_keyboard.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,11 @@ static void inject_keyboard_event_inner(char ascii, char ascii_shift, char const
382382
? ((modifiers & BSP_INPUT_MODIFIER_SHIFT) ? utf8_shift_alt : utf8_alt)
383383
: ((modifiers & BSP_INPUT_MODIFIER_SHIFT) ? utf8_shift : utf8);
384384
bsp_input_event_t event = {
385-
.type = INPUT_EVENT_TYPE_KEYBOARD,
386-
.args_keyboard.ascii = value_ascii,
387-
.args_keyboard.utf8 = value_utf8,
388-
.args_keyboard.modifiers = modifiers,
385+
.type = INPUT_EVENT_TYPE_KEYBOARD,
386+
.args_keyboard.ascii = value_ascii,
387+
.args_keyboard.modifiers = modifiers,
389388
};
389+
strlcpy(event.args_keyboard.utf8, value_utf8, sizeof(event.args_keyboard.utf8));
390390
bsp_input_inject_event(&event);
391391
printf("Keyboard %02x with modifiers %02" PRIx32 "\r\n", value_ascii, modifiers);
392392
}

main/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies:
99
nicolaielectronics/tanmatsu-wifi: "^1.2.0"
1010
badgeteam/terminal-emulator: "^0.0.4"
1111
badgeteam/badgelink: "^0.2.0"
12-
nicolaielectronics/tanmatsu-lora: "^0.3.0"
12+
nicolaielectronics/tanmatsu-lora: "^0.4.3"
1313
nicolaielectronics/tanmatsu-addon: "^0.0.1"
1414
nicolaielectronics/tanmatsu-settings: "^1.1.0"
1515
nicolaielectronics/scd4x: "^0.0.1"

main/menu/lora_information.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "lora_information.h"
2+
#include <math.h>
23
#include <string.h>
34
#include "bsp/device.h"
45
#include "bsp/input.h"
@@ -36,7 +37,8 @@ extern lora_handle_t* lora_get_handle(void);
3637
#define TEXT_SIZE 9
3738
#endif
3839

39-
static void render(bool partial, bool icons, size_t num_packets, lora_protocol_lora_packet_t* packets) {
40+
static void render(bool partial, bool icons, size_t num_packets, lora_protocol_lora_packet_t* packets,
41+
float frequency_error, float frequency_error_avg) {
4042
pax_buf_t* buffer = display_get_buffer();
4143
gui_theme_t* theme = get_theme();
4244

@@ -136,6 +138,10 @@ static void render(bool partial, bool icons, size_t num_packets, lora_protocol_l
136138
config.low_data_rate_optimization ? "Yes" : "No");
137139
pax_draw_text(buffer, theme->palette.color_foreground, TEXT_FONT, TEXT_SIZE, position.x0,
138140
position.y0 + (TEXT_SIZE + 2) * (line++), text_buffer);
141+
snprintf(text_buffer, sizeof(text_buffer), "Frequency error : %0.2f Hz (avg. %0.2f Hz)", frequency_error,
142+
frequency_error_avg);
143+
pax_draw_text(buffer, theme->palette.color_foreground, TEXT_FONT, TEXT_SIZE, position.x0,
144+
position.y0 + (TEXT_SIZE + 2) * (line++), text_buffer);
139145

140146
if (status.errors & SX126X_ERROR_RC64K_CALIB_ERR)
141147
pax_draw_text(buffer, 0xFFFF0000, TEXT_FONT, TEXT_SIZE, position.x0,
@@ -206,7 +212,11 @@ void menu_lora_information(void) {
206212

207213
lora_protocol_lora_packet_t lora_packets[10] = {0};
208214

209-
render(false, true, (sizeof(lora_packets) / sizeof(lora_protocol_lora_packet_t)) - 1, lora_packets);
215+
render(false, true, (sizeof(lora_packets) / sizeof(lora_protocol_lora_packet_t)) - 1, lora_packets, 0, 0);
216+
217+
float frequency_error = 0;
218+
double frequency_error_accumulator = 0;
219+
uint32_t frequency_error_count = 0;
210220

211221
while (1) {
212222
bool received = false;
@@ -216,8 +226,12 @@ void menu_lora_information(void) {
216226
for (size_t i = 1; i < sizeof(lora_packets) / sizeof(lora_protocol_lora_packet_t); i++) {
217227
memcpy(&lora_packets[i - 1], &lora_packets[i], sizeof(lora_protocol_lora_packet_t));
218228
}
219-
printf("Received LoRa packet: length: %d, data: ",
220-
lora_packets[sizeof(lora_packets) / sizeof(lora_protocol_lora_packet_t) - 1].length);
229+
lora_get_frequency_error(lora_get_handle(), &frequency_error);
230+
frequency_error_accumulator += frequency_error;
231+
frequency_error_count++;
232+
printf("Received LoRa packet: length: %d, frequency error: %0.2f, data: ",
233+
lora_packets[sizeof(lora_packets) / sizeof(lora_protocol_lora_packet_t) - 1].length,
234+
frequency_error);
221235
for (size_t j = 0;
222236
j < lora_packets[sizeof(lora_packets) / sizeof(lora_protocol_lora_packet_t) - 1].length &&
223237
j < sizeof(lora_packets[sizeof(lora_packets) / sizeof(lora_protocol_lora_packet_t) - 1].data);
@@ -238,6 +252,10 @@ void menu_lora_information(void) {
238252
case BSP_INPUT_NAVIGATION_KEY_F1:
239253
case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_B:
240254
return;
255+
case BSP_INPUT_NAVIGATION_KEY_F5:
256+
frequency_error_accumulator = 0;
257+
frequency_error_count = 0;
258+
break;
241259
case BSP_INPUT_NAVIGATION_KEY_F6:
242260
test_tx();
243261
break;
@@ -252,6 +270,10 @@ void menu_lora_information(void) {
252270
}
253271
}
254272

255-
render(true, true, (sizeof(lora_packets) / sizeof(lora_protocol_lora_packet_t)) - 1, lora_packets);
273+
double frequency_error_avg =
274+
frequency_error_count > 0 ? (float)(frequency_error_accumulator / (double)(frequency_error_count)) : NAN;
275+
276+
render(true, true, (sizeof(lora_packets) / sizeof(lora_protocol_lora_packet_t)) - 1, lora_packets,
277+
frequency_error, frequency_error_avg);
256278
}
257279
}

0 commit comments

Comments
 (0)