edited comments in main.c

This commit is contained in:
Tim Becker 2022-07-11 09:54:18 +02:00
parent 820f3c52b2
commit 1a4af14e33

View file

@ -5,14 +5,18 @@
* CONDITIONS OF ANY KIND, either express or implied.
*/
// This file contains a simple Hello World app which you can base you own
// native Badge apps on.
#include "main.h"
static pax_buf_t buf;
xQueueHandle buttonQueue;
#include <esp_log.h>
static const char *TAG = "mch2022-demo-app";
// Updates the screen with the last drawing.
// Updates the screen with the latest buffer.
void disp_flush() {
ili9341_write(get_ili9341(), buf.buf);
}
@ -24,20 +28,26 @@ void exit_to_launcher() {
}
void app_main() {
// Init the screen, the I2C and the SPI busses.
ESP_LOGI(TAG, "Welcome to the template app!");
// Initialize the screen, the I2C and the SPI busses.
bsp_init();
// Init the RP2040 (responsible for buttons among other important things).
// Initialize the RP2040 (responsible for buttons, etc).
bsp_rp2040_init();
// This queue is used to await button presses.
// This queue is used to receive button presses.
buttonQueue = get_rp2040()->queue;
// Init graphics for the screen.
// Initialize graphics for the screen.
pax_buf_init(&buf, NULL, 320, 240, PAX_BUF_16_565RGB);
// Init NVS.
// Initialize NVS.
nvs_flash_init();
// Init (but not connect to) WiFi.
// Initialize WiFi. This doesn't connect to Wifi yet.
wifi_init();
while (1) {
@ -45,37 +55,44 @@ void app_main() {
int hue = esp_random() & 255;
pax_col_t col = pax_col_hsv(hue, 255 /*saturation*/, 255 /*brighness*/);
// Show some random color hello world.
// Draw the background with aforementioned random color.
// Greet the World in front of a random background color!
// Fill the background with the random color.
pax_background(&buf, col);
// This text is shown on screen.
char *text = "Hello, World!";
// Pick the font to draw in (this is the only one that looks nice this big).
char *text = "Hello, MCH2022!";
// Pick the font (Saira is the only one that looks nice in this size).
const pax_font_t *font = pax_font_saira_condensed;
// Determine how large the text is so it can be centered.
// Determine how the text dimensions so we can display it centered on
// screen.
pax_vec1_t dims = pax_text_size(font, font->default_size, text);
// Use info to draw the centered text.
// Draw the centered text.
pax_draw_text(
// Buffer to draw to.
&buf, 0xff000000,
// Font and size to use.
font, font->default_size,
&buf, // Buffer to draw to.
0xff000000, // color
font, font->default_size, // Font and size to use.
// Position (top left corner) of the app.
(buf.width - dims.x) / 2.0,
(buf.height - dims.y) / 2.0,
// The text to be shown.
// The text to be rendered.
text
);
// Draws the entire graphics buffer to the screen.
disp_flush();
// Await any button press and do another cycle.
// Wait for button presses and do another cycle.
// Structure used to receive data.
rp2040_input_message_t message;
// Await forever (because of portMAX_DELAY), a button press.
// Wait forever for a button press (because of portMAX_DELAY)
xQueueReceive(buttonQueue, &message, portMAX_DELAY);
// Is the home button currently pressed?
// Which button is currently pressed?
if (message.input == RP2040_INPUT_BUTTON_HOME && message.state) {
// If home is pressed, exit to launcher.
exit_to_launcher();