mch2022-template-app/main/button_test.c

131 lines
5.9 KiB
C
Raw Normal View History

2022-06-03 03:59:42 +00:00
#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;
2022-06-04 14:20:10 +00:00
bool btn_joy_down_green = false;
bool btn_joy_up_green = false;
bool btn_joy_left_green = false;
bool btn_joy_right_green = false;
bool btn_joy_press_green = false;
bool btn_home_green = false;
bool btn_menu_green = false;
bool btn_select_green = false;
bool btn_start_green = false;
bool btn_accept_green = false;
bool btn_back_green = false;
2022-06-03 03:59:42 +00:00
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;
2022-06-04 14:20:10 +00:00
if (value) btn_joy_down_green = true;
2022-06-03 03:59:42 +00:00
break;
case RP2040_INPUT_JOYSTICK_UP:
btn_joy_up = value;
2022-06-04 14:20:10 +00:00
if (value) btn_joy_up_green = true;
2022-06-03 03:59:42 +00:00
break;
case RP2040_INPUT_JOYSTICK_LEFT:
btn_joy_left = value;
2022-06-04 14:20:10 +00:00
if (value) btn_joy_left_green = true;
2022-06-03 03:59:42 +00:00
break;
case RP2040_INPUT_JOYSTICK_RIGHT:
btn_joy_right = value;
2022-06-04 14:20:10 +00:00
if (value) btn_joy_right_green = true;
2022-06-03 03:59:42 +00:00
break;
case RP2040_INPUT_JOYSTICK_PRESS:
btn_joy_press = value;
2022-06-04 14:20:10 +00:00
if (value) btn_joy_press_green = true;
2022-06-03 03:59:42 +00:00
break;
case RP2040_INPUT_BUTTON_HOME:
btn_home = value;
2022-06-04 14:20:10 +00:00
if (value) btn_home_green = true;
2022-06-03 03:59:42 +00:00
break;
case RP2040_INPUT_BUTTON_MENU:
btn_menu = value;
2022-06-04 14:20:10 +00:00
if (value) btn_menu_green = true;
2022-06-03 03:59:42 +00:00
break;
case RP2040_INPUT_BUTTON_SELECT:
btn_select = value;
2022-06-04 14:20:10 +00:00
if (value) btn_select_green = true;
2022-06-03 03:59:42 +00:00
break;
case RP2040_INPUT_BUTTON_START:
btn_start = value;
2022-06-04 14:20:10 +00:00
if (value) btn_start_green = true;
2022-06-03 03:59:42 +00:00
break;
case RP2040_INPUT_BUTTON_ACCEPT:
btn_accept = value;
2022-06-04 14:20:10 +00:00
if (value) btn_accept_green = true;
2022-06-03 03:59:42 +00:00
break;
case RP2040_INPUT_BUTTON_BACK:
btn_back = value;
2022-06-04 14:20:10 +00:00
if (value) btn_back_green = true;
2022-06-03 03:59:42 +00:00
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");
2022-06-04 14:20:10 +00:00
pax_draw_text(pax_buffer, btn_joy_down_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*1, buffer);
2022-06-03 03:59:42 +00:00
snprintf(buffer, sizeof(buffer), "JOY UP %s", btn_joy_up ? "PRESSED" : "released");
2022-06-04 14:20:10 +00:00
pax_draw_text(pax_buffer, btn_joy_up_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*2, buffer);
2022-06-03 03:59:42 +00:00
snprintf(buffer, sizeof(buffer), "JOY LEFT %s", btn_joy_left ? "PRESSED" : "released");
2022-06-04 14:20:10 +00:00
pax_draw_text(pax_buffer, btn_joy_right_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*3, buffer);
2022-06-03 03:59:42 +00:00
snprintf(buffer, sizeof(buffer), "JOY RIGHT %s", btn_joy_right ? "PRESSED" : "released");
2022-06-04 14:20:10 +00:00
pax_draw_text(pax_buffer, btn_joy_left_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*4, buffer);
2022-06-03 03:59:42 +00:00
snprintf(buffer, sizeof(buffer), "JOY PRESS %s", btn_joy_press ? "PRESSED" : "released");
2022-06-04 14:20:10 +00:00
pax_draw_text(pax_buffer, btn_joy_press_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*5, buffer);
2022-06-03 03:59:42 +00:00
snprintf(buffer, sizeof(buffer), "BTN HOME %s", btn_home ? "PRESSED" : "released");
2022-06-04 14:20:10 +00:00
pax_draw_text(pax_buffer, btn_home_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*6, buffer);
2022-06-03 03:59:42 +00:00
snprintf(buffer, sizeof(buffer), "BTN MENU %s", btn_menu ? "PRESSED" : "released");
2022-06-04 14:20:10 +00:00
pax_draw_text(pax_buffer, btn_menu_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*7, buffer);
2022-06-03 03:59:42 +00:00
snprintf(buffer, sizeof(buffer), "BTN SELECT %s", btn_select ? "PRESSED" : "released");
2022-06-04 14:20:10 +00:00
pax_draw_text(pax_buffer, btn_select_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*8, buffer);
2022-06-03 03:59:42 +00:00
snprintf(buffer, sizeof(buffer), "BTN START %s", btn_start ? "PRESSED" : "released");
2022-06-04 14:20:10 +00:00
pax_draw_text(pax_buffer, btn_start_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*9, buffer);
2022-06-03 03:59:42 +00:00
snprintf(buffer, sizeof(buffer), "BTN A %s", btn_accept ? "PRESSED" : "released");
2022-06-04 14:20:10 +00:00
pax_draw_text(pax_buffer, btn_accept_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*10, buffer);
2022-06-03 03:59:42 +00:00
snprintf(buffer, sizeof(buffer), "BTN B %s", btn_back ? "PRESSED" : "released");
2022-06-04 14:20:10 +00:00
pax_draw_text(pax_buffer, btn_back_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*11, buffer);
2022-06-03 03:59:42 +00:00
ili9341_write(ili9341, pax_buffer->buf);
render = false;
}
if (btn_home && btn_start) {
quit = true;
}
}
}