Skip to content

Commit b4558b0

Browse files
committed
Fix show fail safe for error
- Shows a fail safe text when a device is connected which is later on overwritten - Allows to show that a device is not supported in the case of an error
1 parent 226d9cd commit b4558b0

File tree

4 files changed

+43
-38
lines changed

4 files changed

+43
-38
lines changed

src/gfx_main.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,20 @@ void gfx_task(void)
469469
gfx_set_device_label(usb_host_get_manuf_string(),
470470
usb_host_get_product_string(),
471471
usb_host_get_vidpid_string());
472-
gfx_set_byte_offsets_text();
472+
473+
// Fail safe text in the case there is an error
474+
lv_checkbox_set_text(hid_offsets_label, "DEVICE IS NOT SUPPORTED");
475+
lv_obj_align_to(hid_offsets_label, productname_label, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 5);
473476
break;
474477

475478
case GFX_EVENT_HID_DEVICE_DISCONNECTED:
476479
gfx_set_device_label("", "No USB device connected", "");
477480
gfx_set_byte_offsets_text();
478481
break;
482+
483+
case GFX_EVENT_HID_DEVICE_READY:
484+
gfx_set_byte_offsets_text();
485+
break;
479486
}
480487

481488
// free event memory
@@ -496,3 +503,14 @@ void gfx_set_trigger_ready(bool state)
496503
lv_obj_clear_state(trigger_ready_cb, LV_STATE_CHECKED);
497504
}
498505
}
506+
507+
void gfx_send_event(gfx_event_t type, int32_t value)
508+
{
509+
// Send a message to the gfx thread, to refresh the device info
510+
struct gfx_event *evt;
511+
evt = osPoolAlloc(gfxevt_pool); // Allocate memory for the message
512+
evt->type = type;
513+
evt->value = value;
514+
515+
osMessagePut(msgQGfxTask, (uint32_t)evt, 0U);
516+
}

src/gfx_main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ typedef enum gfx_event_type {
2929
GFX_EVENT_MEASUREMENT,
3030
GFX_EVENT_HID_DEVICE_CONNECTED,
3131
GFX_EVENT_HID_DEVICE_DISCONNECTED,
32+
GFX_EVENT_HID_DEVICE_READY,
3233
} gfx_event_t;
3334

3435
struct gfx_event {
@@ -41,5 +42,6 @@ void gfx_task(void);
4142
void gfx_set_device_label(const char * manufacturer, const char * productname, const char *vidpid);
4243
void gfx_set_trigger_ready(bool state);
4344
void gfx_set_byte_offsets_text();
45+
void gfx_send_event(gfx_event_t type, int32_t value);
4446

4547
#endif //XLAT_F7_FW_GFX_H

src/usb/usb_host.c

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,36 +70,31 @@ static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id)
7070
case HOST_USER_SELECT_CONFIGURATION:
7171
break;
7272

73-
case HOST_USER_DISCONNECTION: {
73+
case HOST_USER_DISCONNECTION:
7474
// Clear offsets
7575
xlat_clear_locations();
76-
// Send a message to the gfx thread, to refresh the device info
77-
struct gfx_event *evt;
78-
evt = osPoolAlloc(gfxevt_pool); // Allocate memory for the message
79-
evt->type = GFX_EVENT_HID_DEVICE_DISCONNECTED;
80-
evt->value = 0;
81-
osMessagePut(msgQGfxTask, (uint32_t)evt, 0U);
76+
77+
gfx_send_event(GFX_EVENT_HID_DEVICE_DISCONNECTED, 0);
8278
break;
79+
80+
case HOST_USER_CLASS_SELECTED:
81+
case HOST_USER_NO_SUPPORTED_CLASS: {
82+
// Compose vidpid string
83+
uint16_t vid = phost->device.DevDesc.idVendor;
84+
uint16_t pid = phost->device.DevDesc.idProduct;
85+
memset(vidpid_string, 0, sizeof(vidpid_string));
86+
snprintf(vidpid_string, sizeof(vidpid_string), "0x%04X:%04X", vid, pid);
87+
vidpid_string[sizeof(vidpid_string) - 1] = '\0';
88+
89+
gfx_send_event(GFX_EVENT_HID_DEVICE_CONNECTED, 0);
90+
break;
8391
}
8492

85-
case HOST_USER_NO_SUPPORTED_CLASS:
86-
case HOST_USER_CLASS_ACTIVE: {
87-
// Compose vidpid string
88-
uint16_t vid = phost->device.DevDesc.idVendor;
89-
uint16_t pid = phost->device.DevDesc.idProduct;
90-
printf("USB device connected: 0x%04X:%04X\n", vid, pid);
91-
memset(vidpid_string, 0, sizeof(vidpid_string));
92-
snprintf(vidpid_string, sizeof(vidpid_string), "0x%04X:%04X", vid, pid);
93-
vidpid_string[sizeof(vidpid_string) - 1] = '\0';
94-
95-
// Send a message to the gfx thread, to refresh the device info
96-
struct gfx_event *evt;
97-
evt = osPoolAlloc(gfxevt_pool); // Allocate memory for the message
98-
evt->type = GFX_EVENT_HID_DEVICE_CONNECTED;
99-
evt->value = 0;
100-
osMessagePut(msgQGfxTask, (uint32_t)evt, 0U);
93+
case HOST_USER_CLASS_ACTIVE:
94+
printf("USB device ready\n");
95+
96+
gfx_send_event(GFX_EVENT_HID_DEVICE_READY, 0);
10197
break;
102-
}
10398

10499
case HOST_USER_CONNECTION:
105100
default:
@@ -136,4 +131,4 @@ char * usb_host_get_manuf_string(void)
136131
char * usb_host_get_vidpid_string(void)
137132
{
138133
return vidpid_string;
139-
}
134+
}

src/xlat.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,7 @@ static int calculate_gpio_to_usb_time(void)
267267

268268
xlat_add_latency_measurement(us, LATENCY_GPIO_TO_USB);
269269

270-
// send a message to the gfx thread, to refresh the plot
271-
struct gfx_event *evt;
272-
evt = osPoolAlloc(gfxevt_pool); // Allocate memory for the message
273-
evt->type = GFX_EVENT_MEASUREMENT;
274-
evt->value = us;
275-
osMessagePut(msgQGfxTask, (uint32_t)evt, 0U);
270+
gfx_send_event(GFX_EVENT_MEASUREMENT, us);
276271

277272
return 0;
278273
}
@@ -760,12 +755,7 @@ void xlat_parse_hid_descriptor(uint8_t *desc, size_t desc_size)
760755
// Find click and motion data offsets
761756
check_offsets();
762757

763-
// Send a message to the gfx thread, to refresh the device info
764-
struct gfx_event *evt;
765-
evt = osPoolAlloc(gfxevt_pool); // Allocate memory for the message
766-
evt->type = GFX_EVENT_HID_DEVICE_CONNECTED;
767-
evt->value = 0;
768-
osMessagePut(msgQGfxTask, (uint32_t)evt, 0U);
758+
gfx_send_event(GFX_EVENT_HID_DEVICE_CONNECTED, 0);
769759
}
770760

771761
hid_data_location_t * xlat_get_button_location(void)

0 commit comments

Comments
 (0)