Changeset - 64275d7d6618
[Not reviewed]
default
0 5 0
Ethan Zonca - 9 months ago 2024-09-03 20:32:26
ez@ethanzonca.com
More LED work, etc
5 files changed with 137 insertions and 41 deletions:
0 comments (0 inline, 0 general)
main/display_gui.c
Show inline comments
 
@@ -3,50 +3,45 @@
 
//
 

	
 
#include "display_gui.h"
 
#include "display.h"
 
#include "esp_lvgl_port.h"
 
#include "esp_err.h"
 
#include "esp_log.h"
 
#include "esp_check.h"
 
#include "freertos/FreeRTOS.h"
 
#include "freertos/task.h"
 

	
 

	
 

	
 

	
 
static lv_obj_t *ui_Screen1;
 
static lv_obj_t *ui_redsquare;
 

	
 
static lv_obj_t *meter;
 
static lv_meter_indicator_t *meter_indic1;
 

	
 
static lv_obj_t *ue_img_logo;
 
static lv_obj_t *esp_img_logo;
 
static lv_obj_t *label;
 

	
 

	
 
static lv_obj_t *ui_Dropdown2;
 

	
 
LV_IMG_DECLARE(ue_logo)
 
LV_IMG_DECLARE(esp_logo)
 
LV_IMG_DECLARE(red_square)
 

	
 

	
 
void display_gui_homescreen(void)
 
{
 

	
 
    // Actually create homescreen widgets
 

	
 
    
 
    // Create homescreen widgets
 
    display_lock(0);
 

	
 
    label = lv_label_create(lv_scr_act());
 
    lv_label_set_text(label, "Boot Complete");
 
    // lv_obj_align_to(label, lv_scr_act(), LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
 

	
 
        // 14
 
        // 20
 
        // 24
 
        // 28
 
        // montserrat
 

	
 
@@ -61,32 +56,35 @@ void display_gui_homescreen(void)
 
    // display_image();
 
    // display_window();
 
    //display_dropdown();
 

	
 
    display_unlock();
 
}
 

	
 

	
 
// TODO: make a display task that listens for messages from a queue that change visual elements
 
uint32_t value = 0;
 
void display_gui_process(void)
 
{
 
    
 
    display_lock(0);
 
    for(;;)
 
    {
 
        display_lock(0);
 

	
 
    //set_value(meter_indic1, value);
 
    
 
    //value = (value + 1) % 100;
 
        //set_value(meter_indic1, value);
 
        
 
        //value = (value + 1) % 100;
 

	
 
    display_unlock();
 
        display_unlock();
 
        vTaskDelay(pdMS_TO_TICKS(100));
 
    }
 

	
 
}
 

	
 

	
 

	
 

	
 

	
 

	
 

	
 

	
 

	
 

	
main/ledstrip.c
Show inline comments
 
@@ -2,37 +2,37 @@
 
#include "freertos/FreeRTOS.h"
 
#include "freertos/task.h"
 
#include "led_strip.h"
 
#include "esp_log.h"
 
#include "esp_err.h"
 
#include "ledstrip.h"
 
#include "esp_log.h"
 

	
 

	
 

	
 
// Settings
 
#define LED_STRIP_GPIO  11
 
#define LED_STRIP_NUM_LEDS 150
 
#define LED_STRIP_NUM_LEDS 250
 
#define LED_STRIP_RMT_FREQ_HZ  (10 * 1000 * 1000)
 
static const char *TAG = "ledstrip";
 

	
 

	
 
// Private Prototypes
 
static uint8_t process_effect_rainbow();
 
static uint8_t process_effect_singlechase();
 

	
 
static uint8_t process_effect_rainbow(void);
 
static uint8_t process_effect_singlechase(void);
 
static uint8_t process_effect_cauldron(void);
 

	
 
// Private variables
 
static led_strip_handle_t led_strip;
 
static effect_t current_effect = EFFECT_NONE;
 
static led_mode_t mode = LEDMODE_AUTO;
 

	
 
// Initialize WS2812 strip
 
void ledstrip_init(void)
 
{
 
    // LED strip general initialization, according to your led board design
 
    led_strip_config_t strip_config = {
 
        .strip_gpio_num = LED_STRIP_GPIO,
 
        .max_leds = LED_STRIP_NUM_LEDS,
 
        .led_pixel_format = LED_PIXEL_FORMAT_GRB,
 
        .led_model = LED_MODEL_WS2812,
 
        .flags.invert_out = false,
 
    };
 
@@ -51,61 +51,83 @@ void ledstrip_init(void)
 

	
 

	
 
// From OSC for testing
 
static float modifier = 0.0;
 
void ledstrip_set_modifier(float frac)
 
{
 
    modifier = frac;
 
}
 

	
 

	
 
void ledstrip_set_effect(effect_t effect)
 
{
 
  mode = LEDMODE_AUTO;
 
  current_effect = effect;
 
}
 

	
 

	
 
// Set entire strip to RGB value
 
void ledstrip_set(uint32_t r, uint32_t g, uint32_t b)
 
{
 
    mode = LEDMODE_MANUAL;
 
    for (int i = 0; i < LED_STRIP_NUM_LEDS; i++) {
 
        ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, i, r, g, b));
 
        ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, i, g, r, b));
 
    }
 
    led_strip_refresh(led_strip);
 
}
 

	
 
// Run effect and refresh strip
 
void ledstrip_refresh(void)
 
{
 
  switch(current_effect)
 
  for(;;)
 
  {
 

	
 
    case EFFECT_RAINBOW:
 
    if(mode == LEDMODE_MANUAL)
 
    {
 
      if(process_effect_rainbow() & 0x01)
 
        led_strip_refresh(led_strip);
 
    } break;
 
    
 
    case EFFECT_SINGLECHASE:
 
        // do nothing
 
    }
 

	
 
    else
 
    {
 
      if(process_effect_singlechase() & 0x01)
 
        led_strip_refresh(led_strip);
 
    } break;
 
      switch(current_effect)
 
      {
 

	
 
        case EFFECT_RAINBOW:
 
        {
 
          if(process_effect_rainbow() & 0x01)
 
            led_strip_refresh(led_strip);
 
        } break;
 
        
 
        case EFFECT_SINGLECHASE:
 
        {
 
          if(process_effect_singlechase() & 0x01)
 
            led_strip_refresh(led_strip);
 
        } break;
 

	
 
    case EFFECT_NONE:
 
    default:
 
    {
 
      ledstrip_set(10,10,10);
 
      led_strip_refresh(led_strip);
 
    } break;
 
        case EFFECT_CAULDRON:
 
        {
 
          if(process_effect_cauldron() & 0x01)
 
            led_strip_refresh(led_strip);
 
        } break;
 

	
 
        case EFFECT_NONE:
 
        default:
 
        {
 
          ledstrip_set(10,10,10);
 
          led_strip_refresh(led_strip);
 
        } break;
 
      }
 
    }
 

	
 
    // TODO: DelayUntil
 
    vTaskDelay(pdMS_TO_TICKS(10));
 
  }
 
}
 

	
 

	
 

	
 

	
 

	
 

	
 

	
 

	
 

	
 
static uint8_t   effect = -1;
 
@@ -113,25 +135,25 @@ static uint8_t   effects = 120;
 
static uint16_t  effStep;
 
static unsigned long effStart;
 

	
 
static void __reset(void)
 
{
 
    effStep = 0;
 
    effect = (effect + 1) % effects;
 
    effStart = xTaskGetTickCount() * portTICK_PERIOD_MS;
 
}
 

	
 

	
 

	
 
static uint8_t process_effect_rainbow() {
 
static uint8_t process_effect_rainbow(void) {
 
    // Strip ID: 0 - Effect: Rainbow - LEDS: 120
 
    // Steps: 60 - Delay: 20
 
    // Colors: 3 (255.0.0, 0.255.0, 0.0.255)
 
    // Options: rainbowlen=60, toLeft=true, 
 
  if((xTaskGetTickCount() * portTICK_PERIOD_MS) - effStart < 20 * (effStep)) return 0x00;
 
  float factor1, factor2;
 
  uint16_t ind;
 
  for(uint16_t j=0;j<LED_STRIP_NUM_LEDS;j++) {
 
    ind = effStep + j * 1;
 
    switch((int)((ind % 60) / 20)) {
 
      case 0: factor1 = 1.0 - ((float)(ind % 60 - 0 * 20) / 20);
 
              factor2 = (float)((int)(ind - 0) % 60) / 20;
 
@@ -148,30 +170,79 @@ static uint8_t process_effect_rainbow() 
 
              ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, j, modifier * 0 * factor1 + 255 * factor2, modifier * 0 * factor1 + 0 * factor2, modifier * 255 * factor1 + 0 * factor2));
 
              break;
 
    }
 
  }
 
  if(effStep >= 60) {__reset(); return 0x03; }
 
  else effStep++;
 
  return 0x01;
 
}
 

	
 

	
 

	
 
static uint32_t countloc = 0;
 
static uint8_t process_effect_singlechase() {
 
static uint8_t process_effect_singlechase(void) {
 
  if((xTaskGetTickCount() * portTICK_PERIOD_MS) - effStart < 20 * (effStep)) return 0x00;
 

	
 
  float intensity = (float)countloc / (float)LED_STRIP_NUM_LEDS;
 
  for(uint16_t j=0;j<LED_STRIP_NUM_LEDS;j++) {
 
    if(j == countloc)
 
    {
 
      ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, j, 255, 255 * (1.0-intensity), 255 * (1.0-intensity)));
 
      ESP_LOGI(TAG, "Friggn intensity %f", intensity);
 
    }
 
    else
 
      ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, j, 0,0,0));
 
  }
 
  countloc = (countloc + 1) % LED_STRIP_NUM_LEDS;
 

	
 
  return 0x01;
 
}
 

	
 

	
 

	
 

	
 
//127, 122
 

	
 
// static uint32_t countloc = 0;
 
float intensity = 1.0f;
 
uint8_t intensity_up = 0;
 
uint8_t modmod = 0;
 
uint32_t last_modmod = 0;
 

	
 
static uint8_t process_effect_cauldron(void) {
 
  if((xTaskGetTickCount() * portTICK_PERIOD_MS) - effStart < 20 * (effStep)) return 0x00;
 

	
 
  if(intensity_up)
 
  {
 
    intensity += 0.01f;
 
    if(intensity > 0.98f)
 
      intensity_up = 0;
 
  }
 
  else
 
  {
 
    intensity -= 0.01f;
 
    if(intensity < 0.7f)
 
      intensity_up = 1;
 
  }
 
  // ESP_LOGI(TAG, "Friggn intensity %f", intensity);
 

	
 
  if((xTaskGetTickCount() * portTICK_PERIOD_MS) - last_modmod > 25)
 
  {
 
    last_modmod = (xTaskGetTickCount() * portTICK_PERIOD_MS);
 
    modmod +=1;
 
  }
 

	
 
  for(uint16_t j=0;j<LED_STRIP_NUM_LEDS;j++) {
 
    
 
      float posmod = (float)((j)%10) / 5.0f;
 
      posmod /= 1.0;
 
      posmod += 0.0;
 
        // ESP_LOGI(TAG, "Friggn intensity %f", posmod);
 

	
 

	
 
      ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, j, 255 * (intensity), 120 * (intensity) * posmod, 0));
 
    
 
    //  ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, j, 0,0,0));
 
  }
 
  //countloc = (countloc + 1) % LED_STRIP_NUM_LEDS;
 

	
 
  return 0x01;
 
}
main/ledstrip.h
Show inline comments
 
#ifndef _LED_STRIPPER_H
 
#define _LED_STRIPPER_H
 

	
 

	
 
typedef enum _effect {
 
  EFFECT_NONE = 0,
 
  EFFECT_RAINBOW,
 
  EFFECT_SINGLECHASE,
 
  EFFECT_CAULDRON,
 
} effect_t;
 

	
 
typedef enum _mode_led {
 
  LEDMODE_AUTO = 0,
 
  LEDMODE_MANUAL = 1,
 
} led_mode_t;
 

	
 

	
 
void ledstrip_init(void);
 
void ledstrip_set(uint32_t r, uint32_t g, uint32_t b);
 
void ledstrip_set_modifier(float frac);
 
void ledstrip_set_effect(effect_t effect);
 
void ledstrip_refresh(void);
 
#endif
 
\ No newline at end of file
main/main.c
Show inline comments
 
@@ -46,21 +46,23 @@ void app_main(void)
 
    wifi_init();
 

	
 
    ledstrip_init();
 

	
 

	
 
    // Initialize OSC
 
    osc_init();
 

	
 

	
 
    // Initialize canbus
 
    //can_init();
 

	
 
    // Start tasks
 
    xTaskCreatePinnedToCore(ledstrip_refresh,    "ledstrip_refresh", 4096, NULL, 10, NULL, 1);
 
    xTaskCreatePinnedToCore(display_gui_process, "display_gui_process", 4096, NULL, 10, NULL, 1);
 

	
 

	
 
    while(1)
 
    {
 
        display_gui_process();
 
        ledstrip_refresh();
 
        vTaskDelay(pdMS_TO_TICKS(10));
 
        vTaskDelay(pdMS_TO_TICKS(100));
 
    }
 

	
 
}
main/osc_control.c
Show inline comments
 
@@ -27,24 +27,28 @@ static void sender()
 

	
 
  for(;;) {
 
    // delay
 
    vTaskDelay(1000 / portTICK_PERIOD_MS);
 

	
 
    // send messages
 
    for (size_t i = 0; i < 2; i++) {
 
      esp_osc_send(&client, &targets[i], "test", "ihfdsb", 42, (int64_t)84, 3.14f, 6.28, "foo", 3, "bar");
 
    }
 
  }
 
}
 

	
 
static uint8_t r_man = 0;
 
static uint8_t g_man = 0;
 
static uint8_t b_man = 0;
 

	
 

	
 
static bool callback(const char *topic, const char *format, esp_osc_value_t *values)
 
{
 
  // log message
 
  ESP_LOGI(TAG, "got message: %s (%s)", topic, format);
 

	
 

	
 
  char out[512] = {0};
 
  snprintf(out, 128, "topic: %s\nformat: %s\n", topic, format);
 

	
 
  for (size_t i = 0; i < strlen(format); i++) 
 
  {
 
@@ -64,24 +68,39 @@ static bool callback(const char *topic, 
 
      {
 
        ESP_LOGI(TAG, "==> h: %lld", values[i].h);
 
      }  break;
 

	
 
      case 'f':
 
      {
 
        snprintf(out+strlen(out), 128-strlen(out), "Value: %f", values[i].f);
 
        ESP_LOGI(TAG, "==> f: %f", values[i].f);
 
        if(strcmp(topic, "/led_modifier") == 0)
 
        {
 
          ledstrip_set_modifier(values[i].f);
 
        }
 
        else if(strcmp(topic, "/led_manual_r") == 0)
 
        {
 
          r_man = values[i].f * 255.0;
 
          ledstrip_set(r_man, g_man, b_man);
 
        }
 
        else if(strcmp(topic, "/led_manual_g") == 0)
 
        {
 
          g_man = values[i].f * 255.0;
 
          ledstrip_set(r_man, g_man, b_man);
 
        }
 
        else if(strcmp(topic, "/led_manual_b") == 0)
 
        {
 
          b_man = values[i].f * 255.0;
 
          ledstrip_set(r_man, g_man, b_man);
 
        }
 
      } break;
 

	
 
      case 'd':
 
      {
 
        ESP_LOGI(TAG, "==> d: %f", values[i].d);
 
      } break;
 

	
 
      case 's':
 
      {
 
        ESP_LOGI(TAG, "==> s: %s", values[i].s);
 
      }  break;
 

	
0 comments (0 inline, 0 general)