esp-project/main/main.c

92 lines
1.9 KiB
C
Raw Permalink Normal View History

2025-01-10 00:44:15 +01:00
#include <stdio.h>
#include <stdlib.h>
2025-01-09 19:28:30 +01:00
#include "nvs_flash.h"
#include "esp_log.h"
#include "lwip/err.h"
#include "lwip/sys.h"
#include "esp_system.h"
#include "esp_err.h"
2025-01-10 00:44:15 +01:00
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/event_groups.h"
#include "driver/gpio.h"
#include "lvgl.h"
#include "sdkconfig.h"
#include "lcd.h"
#include "wifi_connect.h"
bool color = false;
2025-01-09 19:28:30 +01:00
static const char *TAG = "Main";
2025-01-10 00:44:15 +01:00
void example_lvgl_demo_ui(lv_obj_t *scr);
static void touch_event(lv_event_t *e)
2025-01-09 19:28:30 +01:00
{
2025-01-10 00:44:15 +01:00
uint8_t n = rand()%0xff;
2025-01-09 19:28:30 +01:00
2025-01-10 00:44:15 +01:00
if (e->code == LV_EVENT_CLICKED)
{
lv_obj_t *label = (lv_obj_t*)e->user_data;
if ( ! color) {
lv_obj_set_style_text_color(label, lv_color_hex(0xFFFFFF), 0);
color = true;
}
else {
lv_obj_set_style_text_color(label, lv_color_hex(0x000000), 0);
color = false;
2025-01-09 19:28:30 +01:00
}
2025-01-10 00:44:15 +01:00
}
}
2025-01-09 19:28:30 +01:00
2025-01-10 00:44:15 +01:00
void app_main(void)
{
ESP_ERROR_CHECK(LCDInit());
lv_obj_t *scr = lv_disp_get_scr_act(NULL);
lv_obj_set_style_bg_color(scr,lv_palette_main(LV_PALETTE_GREEN),LV_PART_MAIN);
lv_obj_t *label= lv_label_create(scr);
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_style_text_color(label, lv_color_hex(0x123456), 0);
//lv_obj_set_style_text_color(label, LV_COLOR_MAKE16(0xff, 0x00, 0x00), 0);
lv_label_set_text_static(label, "TheGame");
lv_obj_add_event_cb(scr, touch_event, LV_EVENT_CLICKED, label);
//
// turn on lcd backlight, to prevent displaying noise
//
gpio_set_level(LCD_PIN_BK_LIGHT, LCD_BK_LIGHT_ON_LEVEL);
//
// run the Espressif logo demo
//
//example_lvgl_demo_ui(scr);
//Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
wifi_init_sta();
ESP_LOGI(TAG,"End of main");
2025-01-09 19:28:30 +01:00
}