mirror of
https://github.com/badgeteam/mch2022-template-app.git
synced 2024-12-22 15:16:35 +00:00
Add button test
This commit is contained in:
parent
5ff7e84997
commit
e2fc23eed3
4 changed files with 122 additions and 1 deletions
|
@ -23,6 +23,7 @@ idf_component_register(
|
|||
"test_common.c"
|
||||
"factory_test.c"
|
||||
"animation.c"
|
||||
"button_test.c"
|
||||
INCLUDE_DIRS "."
|
||||
"include"
|
||||
"menus"
|
||||
|
|
106
main/button_test.c
Normal file
106
main/button_test.c
Normal file
|
@ -0,0 +1,106 @@
|
|||
#include <stdio.h>
|
||||
#include <sdkconfig.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <freertos/queue.h>
|
||||
#include "ili9341.h"
|
||||
#include "pax_gfx.h"
|
||||
#include "rp2040.h"
|
||||
|
||||
void test_buttons(xQueueHandle buttonQueue, pax_buf_t* pax_buffer, ILI9341* ili9341) {
|
||||
bool render = true;
|
||||
bool quit = false;
|
||||
|
||||
bool btn_joy_down = false;
|
||||
bool btn_joy_up = false;
|
||||
bool btn_joy_left = false;
|
||||
bool btn_joy_right = false;
|
||||
bool btn_joy_press = false;
|
||||
bool btn_home = false;
|
||||
bool btn_menu = false;
|
||||
bool btn_select = false;
|
||||
bool btn_start = false;
|
||||
bool btn_accept = false;
|
||||
bool btn_back = false;
|
||||
|
||||
while (!quit) {
|
||||
rp2040_input_message_t buttonMessage = {0};
|
||||
if (xQueueReceive(buttonQueue, &buttonMessage, 16 / portTICK_PERIOD_MS) == pdTRUE) {
|
||||
uint8_t pin = buttonMessage.input;
|
||||
bool value = buttonMessage.state;
|
||||
render = true;
|
||||
switch(pin) {
|
||||
case RP2040_INPUT_JOYSTICK_DOWN:
|
||||
btn_joy_down = value;
|
||||
break;
|
||||
case RP2040_INPUT_JOYSTICK_UP:
|
||||
btn_joy_up = value;
|
||||
break;
|
||||
case RP2040_INPUT_JOYSTICK_LEFT:
|
||||
btn_joy_left = value;
|
||||
break;
|
||||
case RP2040_INPUT_JOYSTICK_RIGHT:
|
||||
btn_joy_right = value;
|
||||
break;
|
||||
case RP2040_INPUT_JOYSTICK_PRESS:
|
||||
btn_joy_press = value;
|
||||
break;
|
||||
case RP2040_INPUT_BUTTON_HOME:
|
||||
btn_home = value;
|
||||
break;
|
||||
case RP2040_INPUT_BUTTON_MENU:
|
||||
btn_menu = value;
|
||||
break;
|
||||
case RP2040_INPUT_BUTTON_SELECT:
|
||||
btn_select = value;
|
||||
break;
|
||||
case RP2040_INPUT_BUTTON_START:
|
||||
btn_start = value;
|
||||
break;
|
||||
case RP2040_INPUT_BUTTON_ACCEPT:
|
||||
btn_accept = value;
|
||||
break;
|
||||
case RP2040_INPUT_BUTTON_BACK:
|
||||
btn_back = value;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (render) {
|
||||
pax_noclip(pax_buffer);
|
||||
pax_background(pax_buffer, 0x325aa8);
|
||||
pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*0, "Press HOME + START to exit");
|
||||
char buffer[64];
|
||||
snprintf(buffer, sizeof(buffer), "JOY DOWN %s", btn_joy_down ? "PRESSED" : "released");
|
||||
pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*1, buffer);
|
||||
snprintf(buffer, sizeof(buffer), "JOY UP %s", btn_joy_up ? "PRESSED" : "released");
|
||||
pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*2, buffer);
|
||||
snprintf(buffer, sizeof(buffer), "JOY LEFT %s", btn_joy_left ? "PRESSED" : "released");
|
||||
pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*3, buffer);
|
||||
snprintf(buffer, sizeof(buffer), "JOY RIGHT %s", btn_joy_right ? "PRESSED" : "released");
|
||||
pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*4, buffer);
|
||||
snprintf(buffer, sizeof(buffer), "JOY PRESS %s", btn_joy_press ? "PRESSED" : "released");
|
||||
pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*5, buffer);
|
||||
snprintf(buffer, sizeof(buffer), "BTN HOME %s", btn_home ? "PRESSED" : "released");
|
||||
pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*6, buffer);
|
||||
snprintf(buffer, sizeof(buffer), "BTN MENU %s", btn_menu ? "PRESSED" : "released");
|
||||
pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*7, buffer);
|
||||
snprintf(buffer, sizeof(buffer), "BTN SELECT %s", btn_select ? "PRESSED" : "released");
|
||||
pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*8, buffer);
|
||||
snprintf(buffer, sizeof(buffer), "BTN START %s", btn_start ? "PRESSED" : "released");
|
||||
pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*9, buffer);
|
||||
snprintf(buffer, sizeof(buffer), "BTN A %s", btn_accept ? "PRESSED" : "released");
|
||||
pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*10, buffer);
|
||||
snprintf(buffer, sizeof(buffer), "BTN B %s", btn_back ? "PRESSED" : "released");
|
||||
pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*11, buffer);
|
||||
ili9341_write(ili9341, pax_buffer->buf);
|
||||
render = false;
|
||||
}
|
||||
|
||||
if (btn_home && btn_start) {
|
||||
quit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
9
main/include/button_test.h
Normal file
9
main/include/button_test.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include <stdio.h>
|
||||
#include <sdkconfig.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <freertos/queue.h>
|
||||
#include "ili9341.h"
|
||||
#include "pax_gfx.h"
|
||||
|
||||
void test_buttons(xQueueHandle buttonQueue, pax_buf_t* pax_buffer, ILI9341* ili9341);
|
|
@ -21,6 +21,7 @@
|
|||
#include "file_browser.h"
|
||||
#include "fpga_test.h"
|
||||
#include "animation.h"
|
||||
#include "button_test.h"
|
||||
|
||||
extern const uint8_t dev_png_start[] asm("_binary_dev_png_start");
|
||||
extern const uint8_t dev_png_end[] asm("_binary_dev_png_end");
|
||||
|
@ -32,7 +33,8 @@ typedef enum action {
|
|||
ACTION_FPGA_TEST,
|
||||
ACTION_FILE_BROWSER,
|
||||
ACTION_FILE_BROWSER_INT,
|
||||
ACTION_ANIMATION
|
||||
ACTION_ANIMATION,
|
||||
ACTION_BUTTON_TEST
|
||||
} menu_dev_action_t;
|
||||
|
||||
void render_dev_help(pax_buf_t* pax_buffer) {
|
||||
|
@ -65,6 +67,7 @@ void menu_dev(xQueueHandle buttonQueue, pax_buf_t* pax_buffer, ILI9341* ili9341)
|
|||
menu_insert_item(menu, "File browser (SD card)", NULL, (void*) ACTION_FILE_BROWSER, -1);
|
||||
menu_insert_item(menu, "File browser (internal)", NULL, (void*) ACTION_FILE_BROWSER_INT, -1);
|
||||
menu_insert_item(menu, "Animation", NULL, (void*) ACTION_ANIMATION, -1);
|
||||
menu_insert_item(menu, "Button test", NULL, (void*) ACTION_BUTTON_TEST, -1);
|
||||
|
||||
bool render = true;
|
||||
menu_dev_action_t action = ACTION_NONE;
|
||||
|
@ -125,6 +128,8 @@ void menu_dev(xQueueHandle buttonQueue, pax_buf_t* pax_buffer, ILI9341* ili9341)
|
|||
file_browser(buttonQueue, pax_buffer, ili9341, "/internal");
|
||||
} else if (action == ACTION_ANIMATION) {
|
||||
display_animation(pax_buffer, ili9341);
|
||||
} else if (action == ACTION_BUTTON_TEST) {
|
||||
test_buttons(buttonQueue, pax_buffer, ili9341);
|
||||
} else if (action == ACTION_BACK) {
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue