Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Core/Inc/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define DP_FONT_SMALL u8g2_font_6x10_tr
#define DP_FONT_LARGE u8g2_font_logisoso16_tr
#define DP_FONT_MEDIUM u8g2_font_NokiaLargeBold_tr
#define ERROR_SCREEN_MS 5000

void drawSplashScreen(void);
void drawStartupScreen();
Expand All @@ -15,7 +16,7 @@ void drawMeasurement(uint32_t baseline, uint32_t new, uint32_t latency);
void drawAverage(uint32_t latencies_us[], float mean_ms, float sd_ms);
void drawMainMenuInline();
void drawParamsMenu(uint8_t index);
void drawError(char *error);
void drawError(char *head, char *l1, char *l2);
void drawGraphInline(uint32_t latencies_us[]);
void drawJigglerScreen(uint8_t countdown);
void drawFlashScreen(uint8_t progress);
Expand Down
1 change: 1 addition & 0 deletions Core/Inc/display_assets.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extern const unsigned char menu_selection_bitmap[];
extern const unsigned char menu_selection_2x_bitmap[];
extern const unsigned char cogwheel_bitmap[];
extern const unsigned char external_bitmap[];
extern const unsigned char warning_bitmap[];

extern const unsigned char left_bitmap[];
extern const unsigned char right_bitmap[];
Expand Down
2 changes: 1 addition & 1 deletion Core/Inc/measure.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

uint32_t readADC();
uint32_t readAveragedADC();
void measure(uint32_t latencies_us[]);
int8_t measure(uint32_t latencies_us[]);
void computeStatsMs(uint32_t latencies_us[], float *mean_ms, float *sd_ms);
26 changes: 22 additions & 4 deletions Core/Src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,31 @@ void drawAverage(uint32_t latencies_us[], float mean_ms, float sd_ms) {
u8g2_SendBuffer(&u8g2);
}

void drawError(char *error) {
u8g2_ClearBuffer(&u8g2);
void drawError(char *head, char *l1, char *l2) {

u8g2_SetFont(&u8g2, DP_FONT_LARGE);
u8g2_DrawStr(&u8g2, 10, 50, error);
u8g2_SetDrawColor(&u8g2, 2);
u8g2_DrawBox(&u8g2, 2, 45, 123, 39);

u8g2_SetDrawColor(&u8g2, 1);

u8g2_DrawXBM(&u8g2, 1, 44, 126, 42, menu_selection_2x_bitmap);

u8g2_SetFont(&u8g2, DP_FONT_MEDIUM);

uint8_t w = u8g2_GetStrWidth(&u8g2, head);
u8g2_DrawStr(&u8g2, 69 - (w / 2), 59, head);

u8g2_DrawXBM(&u8g2, 7, 57, 16, 16, warning_bitmap);

u8g2_SetFont(&u8g2, DP_FONT_SMALL);
w = u8g2_GetStrWidth(&u8g2, l1);
u8g2_DrawStr(&u8g2, 69 - (w / 2), 70, l1);
w = u8g2_GetStrWidth(&u8g2, l2);
u8g2_DrawStr(&u8g2, 69 - (w / 2), 80, l2);

u8g2_SendBuffer(&u8g2);

HAL_Delay(ERROR_SCREEN_MS);
}

void drawJigglerScreen(uint8_t countdown) {
Expand Down
4 changes: 4 additions & 0 deletions Core/Src/display_assets.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ const unsigned char external_bitmap[] = {
0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00};
const unsigned char left_bitmap[] = {0x04, 0x06, 0x07, 0x06, 0x04};
const unsigned char right_bitmap[] = {0x01, 0x03, 0x07, 0x03, 0x01};
const unsigned char warning_bitmap[] = {
0x00, 0x00, 0x80, 0x01, 0x40, 0x02, 0x40, 0x02, 0x20, 0x04, 0x90,
0x09, 0x90, 0x09, 0x88, 0x11, 0x88, 0x11, 0x84, 0x21, 0x02, 0x40,
0x82, 0x41, 0x81, 0x81, 0x01, 0x80, 0xfe, 0x7f, 0x00, 0x00};
const unsigned char sensor_bitmap[] = {
0xe0, 0x03, 0x18, 0x0c, 0xe4, 0x13, 0x12, 0x24, 0xc9, 0x49, 0x25,
0x52, 0x95, 0x54, 0xc5, 0x51, 0x60, 0x03, 0xc0, 0x01, 0x80, 0x00,
Expand Down
5 changes: 2 additions & 3 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ void updateADCChannel() {
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
HAL_GPIO_WritePin(ERR_LED_GPIO_Port, ERR_LED_Pin, GPIO_PIN_SET);
drawError("ADC Channel error!");
HAL_Delay(2000);
drawError("HAL Error!", "Could not", "set ADC channel.");
HAL_GPIO_WritePin(ERR_LED_GPIO_Port, ERR_LED_Pin, GPIO_PIN_RESET);
}
}
Expand All @@ -237,7 +236,7 @@ void menuRoutine() {
if (paramMenuIndex == EXIT) {
if (saveToFlash() != FLASH_OK) {
HAL_GPIO_WritePin(ERR_LED_GPIO_Port, ERR_LED_Pin, GPIO_PIN_SET);
drawError("Flash error!");
drawError("Flash error!", "Could not", "save to flash.");
HAL_Delay(2000);
HAL_GPIO_WritePin(ERR_LED_GPIO_Port, ERR_LED_Pin, GPIO_PIN_RESET);
}
Expand Down
6 changes: 4 additions & 2 deletions Core/Src/measure.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int8_t measure(uint32_t latencies_us[]) {
} else {
int8_t error = startMouseAction();
if (error) {
return;
return error;
}
}

Expand All @@ -69,7 +69,7 @@ int8_t measure(uint32_t latencies_us[]) {
} else {
int8_t error = stopMouseAction();
if (error) {
return;
return error;
}
}

Expand All @@ -84,6 +84,8 @@ int8_t measure(uint32_t latencies_us[]) {
break;
}
}

return 0;
}

/**
Expand Down
38 changes: 19 additions & 19 deletions Core/Src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@

/**
* @brief Triggers a mouse action based on the current menu index.
* @details To be used as the first action within a latency measurement.
* Depending on `mainMenuIndex`, either clicks mouse1 or moves by 127px x, 127px y. It waits for the USB HID interface to be ready.
* If a timeout occurs (6 seconds), it triggers an error state by flashing the error LED and displaying a message.
* @details To be used as the first action within a latency measurement.
* Depending on `mainMenuIndex`, either clicks mouse1 or moves by 127px x, 127px
* y. It waits for the USB HID interface to be ready. If a timeout occurs (6
* seconds), it triggers an error state by flashing the error LED and displaying
* a message.
* @return int8_t Error code
*/
int8_t startMouseAction() {
Expand All @@ -30,8 +32,7 @@ int8_t startMouseAction() {
tud_task();
if (TIM2->CNT > 6000000) {
HAL_GPIO_WritePin(ERR_LED_GPIO_Port, ERR_LED_Pin, GPIO_PIN_SET);
drawError("USB timeout. Connected?");
HAL_Delay(2000);
drawError("USB timeout", "Check USB", "connection");
HAL_GPIO_WritePin(ERR_LED_GPIO_Port, ERR_LED_Pin, GPIO_PIN_RESET);
return 1;
}
Expand All @@ -45,11 +46,11 @@ int8_t startMouseAction() {
/**
* @brief Generates a random mouse movement report and sends it via USB HID.
*
* @details The mouse report contains random X and Y coordinates ranging from -3 to 3 pixels.
* The function waits for the USB HID interface to become ready. If a timeout occurs
* (6 seconds), it triggers an error state by turning on the error LED,
* displaying a message, and delaying before returning.
* Upon successful transmission, it flashes the info LED to indicate completion.
* @details The mouse report contains random X and Y coordinates ranging from -3
* to 3 pixels. The function waits for the USB HID interface to become ready. If
* a timeout occurs (6 seconds), it triggers an error state by turning on the
* error LED, displaying a message, and delaying before returning. Upon
* successful transmission, it flashes the info LED to indicate completion.
*/
void randomMouseMove() {
hid_mouse_report_t report = {
Expand All @@ -63,8 +64,7 @@ void randomMouseMove() {
tud_task();
if (TIM2->CNT > 6000000) {
HAL_GPIO_WritePin(ERR_LED_GPIO_Port, ERR_LED_Pin, GPIO_PIN_SET);
drawError("USB timeout. Connected?");
HAL_Delay(2000);
drawError("USB timeout", "Check USB", "connection");
HAL_GPIO_WritePin(ERR_LED_GPIO_Port, ERR_LED_Pin, GPIO_PIN_RESET);
return;
}
Expand All @@ -80,11 +80,12 @@ void randomMouseMove() {
/**
* @brief Resets mouse state by sending HID input
*
* @details To be used after measurement with @ref startMouseAction is finished.
* Depending on `mainMenuIndex`, sets `buttons` to 0 for a releasing or `x` and `y` to -127 for a move back to
* the original position. It waits for the USB HID interface to be ready.
* If a timeout occurs (6 seconds), it triggers an error state by flashing the error LED and displaying a message.
* Finally, it sends the report.
* @details To be used after measurement with @ref startMouseAction is finished.
* Depending on `mainMenuIndex`, sets `buttons` to 0 for a releasing or `x` and
* `y` to -127 for a move back to the original position. It waits for the USB
* HID interface to be ready. If a timeout occurs (6 seconds), it triggers an
* error state by flashing the error LED and displaying a message. Finally, it
* sends the report.
* @return int8_t Error code
*/
int8_t stopMouseAction() {
Expand All @@ -100,8 +101,7 @@ int8_t stopMouseAction() {
tud_task();
if (TIM2->CNT > 6000000) {
HAL_GPIO_WritePin(ERR_LED_GPIO_Port, ERR_LED_Pin, GPIO_PIN_SET);
drawError("USB timeout. Connected?");
HAL_Delay(2000);
drawError("USB timeout", "Check USB", "connection");
HAL_GPIO_WritePin(ERR_LED_GPIO_Port, ERR_LED_Pin, GPIO_PIN_RESET);
return 1;
}
Expand Down