22#include "bsp/input.h"
33#include "bsp/led.h"
44#include "common/display.h"
5+ #include "common/theme.h"
56#include "esp_err.h"
67#include "esp_log.h"
78#include "freertos/idf_additions.h"
1415#include "pax_matrix.h"
1516#include "pax_text.h"
1617#include "pax_types.h"
18+ #include "shapes/pax_misc.h"
1719
1820static const char * TAG = "nametag" ;
1921
20- // #include "shapes/pax_misc.h"
22+ static bool flip = false;
23+ static pax_buf_t nametag_pax_buf = {0 };
24+ static pax_buf_t nametag_pax_buf_converted = {0 };
2125
22- #if defined(CONFIG_BSP_TARGET_TANMATSU ) || defined(CONFIG_BSP_TARGET_KONSOOL ) || \
23- defined(CONFIG_BSP_TARGET_HACKERHOTEL_2026 )
24- #define FOOTER_LEFT ((gui_element_icontext_t[]){{get_icon(ICON_ESC), "/"}, {get_icon(ICON_F1), "Back"}}), 2
25- #define FOOTER_RIGHT NULL, 0
26- #elif defined(CONFIG_BSP_TARGET_MCH2022 )
27- #define FOOTER_LEFT NULL, 0
28- #define FOOTER_RIGHT NULL, 0
29- #else
30- #define FOOTER_LEFT NULL, 0
31- #define FOOTER_RIGHT NULL, 0
32- #endif
33-
34- pax_buf_t nametag_pax_buf = {0 };
35- // void* nametag_buffer = NULL;
26+ static pax_buf_t test_a = {0 };
27+ static pax_buf_t test_b = {0 };
28+ static pax_buf_t test_c = {0 };
3629
3730static bool load_nametag (void ) {
38- /*nametag_buffer = heap_caps_calloc(1, 800 * 480 * 4, MALLOC_CAP_SPIRAM);
39- if (nametag_buffer == NULL) {
40- ESP_LOGE(TAG, "Failed to allocate memory for nametag");
41- return false;
42- }*/
4331 FILE * fd = fopen ("/sd/nametag.png" , "rb" );
4432 if (fd == NULL ) {
4533 fd = fopen ("/int/nametag.png" , "rb" );
@@ -50,18 +38,22 @@ static bool load_nametag(void) {
5038 return false;
5139 }
5240 }
53- // pax_buf_init(&nametag_pax_buf, &nametag_buffer, 800, 480, PAX_BUF_32_8888ARGB);
54- if (!pax_decode_png_fd (& nametag_pax_buf , fd , PAX_BUF_32_8888ARGB , 0 )) { // CODEC_FLAG_EXISTING)) {
41+ if (!pax_decode_png_fd (& nametag_pax_buf , fd , PAX_BUF_32_8888ARGB , 0 )) {
5542 ESP_LOGE (TAG , "Failed to decode png file" );
56- // free(nametag_buffer);
57- // nametag_buffer = NULL;
5843 return false;
5944 }
45+
46+ // pax_buf_init(&nametag_pax_buf_converted, NULL, nametag_pax_buf.width, nametag_pax_buf.height, PAX_BUF_16_565RGB);
47+ // pax_background(&nametag_pax_buf_converted, 0xFFFFFFFF);
48+ // pax_draw_image(&nametag_pax_buf_converted, &nametag_pax_buf, 0, 0);
49+
6050 fclose (fd );
6151 return true;
6252}
6353
6454static void render_nametag (pax_buf_t * buffer ) {
55+ pax_buf_set_orientation (& nametag_pax_buf , flip ? PAX_O_ROT_HALF : PAX_O_UPRIGHT );
56+ pax_background (buffer , 0xFFFFFFFF );
6557 pax_draw_image (buffer , & nametag_pax_buf , 0 , 0 );
6658 display_blit_buffer (buffer );
6759}
@@ -94,7 +86,36 @@ static void set_led_color(uint8_t led, uint32_t color) {
9486 led_buffer [led * 3 + 2 ] = (color >> 0 ) & 0xFF ; // B
9587}
9688
97- void menu_nametag (pax_buf_t * buffer , gui_theme_t * theme ) {
89+ void menu_nametag (void ) {
90+ pax_buf_t * buffer = display_get_buffer ();
91+ gui_theme_t * theme = get_theme ();
92+
93+ ///
94+
95+ pax_buf_init (& test_a , NULL , pax_buf_get_width (buffer ), pax_buf_get_height (buffer ), PAX_BUF_32_8888ARGB );
96+ pax_background (& test_a , 0xFFFF0000 );
97+ pax_buf_init (& test_b , NULL , pax_buf_get_width (buffer ), pax_buf_get_height (buffer ), PAX_BUF_24_888RGB );
98+ pax_background (& test_b , 0xFF00FF00 );
99+ pax_buf_init (& test_c , NULL , pax_buf_get_width (buffer ), pax_buf_get_height (buffer ), PAX_BUF_16_565RGB );
100+ pax_background (& test_c , 0xFF0000FF );
101+
102+ while (1 ) {
103+ printf ("A\r\n" );
104+ pax_draw_image (buffer , & test_a , 0 , 0 );
105+ display_blit_buffer (buffer );
106+ vTaskDelay (pdMS_TO_TICKS (200 ));
107+ printf ("B\r\n" );
108+ pax_draw_image (buffer , & test_b , 0 , 0 );
109+ display_blit_buffer (buffer );
110+ vTaskDelay (pdMS_TO_TICKS (200 ));
111+ printf ("C\r\n" );
112+ pax_draw_image (buffer , & test_c , 0 , 0 );
113+ display_blit_buffer (buffer );
114+ vTaskDelay (pdMS_TO_TICKS (200 ));
115+ }
116+
117+ ///
118+
98119 QueueHandle_t input_event_queue = NULL ;
99120 ESP_ERROR_CHECK (bsp_input_get_queue (& input_event_queue ));
100121
@@ -123,9 +144,8 @@ void menu_nametag(pax_buf_t* buffer, gui_theme_t* theme) {
123144 case BSP_INPUT_NAVIGATION_KEY_ESC :
124145 case BSP_INPUT_NAVIGATION_KEY_F1 :
125146 case BSP_INPUT_NAVIGATION_KEY_GAMEPAD_B :
126- // free(nametag_buffer);
127- // nametag_buffer = NULL;
128147 pax_buf_destroy (& nametag_pax_buf );
148+ pax_buf_destroy (& nametag_pax_buf_converted );
129149 set_led_color (0 , 0x000000 );
130150 set_led_color (1 , 0x000000 );
131151 set_led_color (2 , 0x000000 );
@@ -134,6 +154,10 @@ void menu_nametag(pax_buf_t* buffer, gui_theme_t* theme) {
134154 set_led_color (5 , 0x000000 );
135155 bsp_led_write (led_buffer , sizeof (led_buffer ));
136156 return ;
157+ case BSP_INPUT_NAVIGATION_KEY_F2 :
158+ flip = !flip ;
159+ render_nametag (buffer );
160+ break ;
137161 default :
138162 break ;
139163 }
0 commit comments