Changeset - 17740c77dca1
[Not reviewed]
default
0 4 0
Ethan Zonca - 17 months ago 2024-01-15 14:03:50
ez@ethanzonca.com
Display updates
4 files changed with 31 insertions and 7 deletions:
0 comments (0 inline, 0 general)
main/display.c
Show inline comments
 
@@ -458,24 +458,27 @@ void display_slider()
 
    lv_obj_t *slider = lv_slider_create(lv_scr_act());
 
    lv_obj_set_x(slider, 0);
 
    lv_obj_set_y(slider, -40);
 
    lv_obj_set_align(slider, LV_ALIGN_CENTER);
 
    lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
 

	
 
    /*Create a label below the slider*/
 
    slider_label = lv_label_create(lv_scr_act());
 
    lv_label_set_text(slider_label, "0%");
 
    lv_obj_align_to(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
 
}
 

	
 

	
 

	
 

	
 
static void slider_event_cb(lv_event_t *e)
 
{
 
    lv_obj_t *slider = lv_event_get_target(e);
 
    char buf[8];
 
    lv_snprintf(buf, sizeof(buf), "%d%%", (int)lv_slider_get_value(slider));
 
    lv_label_set_text(slider_label, buf);
 
    lv_obj_align_to(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
 
}
 

	
 
void get_img_color()
 
{
 
    lv_color_t pixel_color = lv_img_buf_get_px_color(&red_square, 50, 50, lv_color_make(0, 0, 0));
 
@@ -488,36 +491,46 @@ bool bsp_display_lock(uint32_t timeout_m
 
    BSP_NULL_CHECK(lvgl_mux, NULL);
 
    const TickType_t timeout_ticks = (timeout_ms == 0) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms);
 
    return xSemaphoreTake(lvgl_mux, timeout_ticks) == pdTRUE;
 
}
 

	
 
void bsp_display_unlock(void)
 
{
 
    BSP_NULL_CHECK(lvgl_mux, NULL);
 
    xSemaphoreGive(lvgl_mux);
 
}
 

	
 

	
 

	
 

	
 
lv_obj_t *label;
 
void display_update_text(char* str)
 
{
 
    bsp_display_lock(0);
 
    lv_label_set_text(label, str);
 
    bsp_display_unlock();
 
}
 

	
 

	
 
void display_process(void)
 
{
 
    
 
    bsp_display_lock(0);
 

	
 
    lv_obj_t *label = lv_label_create(lv_scr_act());
 
    lv_label_set_text(label, "Yup");
 
    // lv_obj_align_to(label, lv_scr_act(), LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
 

	
 

	
 
    // display_slider();
 
    //Call one at a time to see examples
 
    display_meter();
 
    // display_image();
 
    // display_window();
 
    //display_dropdown();
 

	
 
    
 
    bsp_display_unlock();
 
    while(1){}
 
}
 

	
 

	
 

	
 

	
 

	
main/display.h
Show inline comments
 
@@ -65,16 +65,17 @@ void display_red_square();
 
void display_dropdown();
 

	
 
void get_img_color();
 

	
 
void bsp_display_unlock(void);
 
bool bsp_display_lock(uint32_t timeout_ms);
 

	
 

	
 

	
 

	
 

	
 
void display_init(void);
 
void display_update_text(char* string);
 
void display_process(void);
 

	
 

	
 
#endif
 
\ No newline at end of file
main/main.c
Show inline comments
 
@@ -27,28 +27,30 @@ void app_main(void)
 
{
 
    // Initialize usb-cdc interface
 
    usb_cdc_init();
 

	
 
    // 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);
 

	
 
    // Initialize display
 
    display_init();
 
    display_process();
 

	
 
    vTaskDelay(1000 / portTICK_PERIOD_MS);
 

	
 
    // Connect to wifi
 
    //wifi_init();
 
    wifi_init();
 

	
 
    // Initialize canbus
 
    //can_init();
 

	
 
    // Initialize display
 
    display_init();
 

	
 
    while(1)
 
    {
 
        display_process();
 
    }
 

	
 
}
main/wifi.c
Show inline comments
 
//
 
// wifi
 
//
 

	
 
#include "wifi.h"
 
#include "esp_wifi.h"
 
#include "esp_event.h"
 
#include "esp_log.h"
 
#include "lwip/err.h"
 
#include "lwip/sys.h"
 
#include "display.h"
 

	
 

	
 
// Private variables
 

	
 
// FreeRTOS event group to signal when we are connected
 
static EventGroupHandle_t s_wifi_event_group;
 
static const char *TAG = "wifi station";
 
static int s_retry_num = 0;
 

	
 

	
 
// Handler for wifi events
 
static void __event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
 
{
 
    if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
 
        esp_wifi_connect();
 
    }
 
    else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) 
 
    {
 
        if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) 
 
        {
 
            esp_wifi_connect();
 
            s_retry_num++;
 
            ESP_LOGI(TAG, "retry to connect to the AP");
 
            display_update_text("AP Connect Retry");
 

	
 
        } 
 
        else 
 
        {
 
            xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
 
        }
 
        ESP_LOGI(TAG,"connect to the AP fail");
 
        display_update_text("AP Connect Fail");
 
        
 
    } 
 
    else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) 
 
    {
 
        ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
 
        ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
 
        char out[128] = {0};
 
        snprintf(out, 128, "Got IP " IPSTR, IP2STR(&event->ip_info.ip));
 
        display_update_text(out);
 
        s_retry_num = 0;
 
        xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
 
    }
 
}
 

	
 

	
 
// Initialize wifi and connect to network
 
void wifi_init(void)
 
{
 
    s_wifi_event_group = xEventGroupCreate();
 

	
 
    ESP_ERROR_CHECK(esp_netif_init());
0 comments (0 inline, 0 general)