diff options
author | RobotMan2412 <julian@scheffers.net> | 2022-06-08 19:26:34 +0200 |
---|---|---|
committer | RobotMan2412 <julian@scheffers.net> | 2022-06-08 19:26:34 +0200 |
commit | 668c03d4b05360bfef5395ee894b26ebae85a869 (patch) | |
tree | 9962583597678ce4d66cbe7dc360001906a78f63 /main/main.c | |
parent | c3d3ee6c96eec222e61549a0e192e55effbdcc2d (diff) | |
download | mch2022-668c03d4b05360bfef5395ee894b26ebae85a869.tar.gz mch2022-668c03d4b05360bfef5395ee894b26ebae85a869.tar.bz2 mch2022-668c03d4b05360bfef5395ee894b26ebae85a869.zip |
Make the demo feature the buttons a bit and add more color.
Diffstat (limited to 'main/main.c')
-rw-r--r-- | main/main.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/main/main.c b/main/main.c index 0257429..f7edfef 100644 --- a/main/main.c +++ b/main/main.c @@ -11,13 +11,13 @@ #include "freertos/queue.h" #include "esp_system.h" -static pax_buf_t pax_buffer; +static pax_buf_t buf; xQueueHandle buttonQueue; static const char *TAG = "mch2022-demo-app"; void disp_flush() { - ili9341_write(get_ili9341(), pax_buffer.buf); + ili9341_write(get_ili9341(), buf.buf); } void app_main() { @@ -27,12 +27,28 @@ void app_main() { buttonQueue = get_rp2040()->queue; // Init GFX. - pax_buf_init(&pax_buffer, NULL, 320, 240, PAX_BUF_16_565RGB); + pax_buf_init(&buf, NULL, 320, 240, PAX_BUF_16_565RGB); - // Show some hello world. - pax_background(&pax_buffer, 0xffff00ff); - disp_flush(); - - // Just wait. - while (1) vTaskDelay(10000); + while (1) { + // Pick a random background color. + int hue = esp_random() & 255; + pax_col_t col = pax_col_hsv(hue, 255 /*saturation*/, 255 /*brighness*/); + + // Show some random color hello world. + pax_background(&buf, col); + char *text = "Hello, World!"; + const pax_font_t *font = pax_get_font("saira condensed"); + pax_vec1_t dims = pax_text_size(font, font->default_size, text); + pax_draw_text( + &buf, 0xff000000, font, font->default_size, + (buf.width - dims.x) / 2.0, + (buf.height - dims.y) / 2.0, + text + ); + disp_flush(); + + // Await any button press and do another cycle. + rp2040_input_message_t message; + xQueueReceive(buttonQueue, &message, portMAX_DELAY); + } } |