Changeset - 45c4b4d15fc5
[Not reviewed]
default
0 4 0
Ethan Zonca - 8 months ago 2024-09-28 13:14:57
ez@ethanzonca.com
Add squeeze sensing. Update chase to only do one rep.
4 files changed with 22 insertions and 6 deletions:
0 comments (0 inline, 0 general)
main/CMakeLists.txt
Show inline comments
 
idf_component_register(SRCS "main.c" "wifi.c" "usb_cdc.c" "can.c" "display.c" "display_gui.c" "osc_control.c" "ledstrip.c"
 
idf_component_register(SRCS "main.c" "wifi.c" "usb_cdc.c" "can.c" "display.c" "display_gui.c" "osc_control.c" "ledstrip.c" "squeeze.c"
 
                       INCLUDE_DIRS .)
main/ledstrip.c
Show inline comments
 
@@ -77,50 +77,55 @@ void ledstrip_set(uint32_t r, uint32_t g
 

	
 
// Run effect and refresh strip
 
void ledstrip_refresh(void)
 
{
 
  for(;;)
 
  {
 
    if(mode == LEDMODE_MANUAL)
 
    {
 
        // do nothing
 
    }
 

	
 
    else
 
    {
 
      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)
 
          uint8_t ret = process_effect_singlechase();
 
          if(ret & 0x01)
 
            led_strip_refresh(led_strip);
 
          // Chase complete, return to manual mode
 
          if(ret & 0x02)
 
            current_effect = EFFECT_NONE;
 

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

	
 

	
 

	
 
@@ -172,49 +177,52 @@ static uint8_t process_effect_rainbow(vo
 
    }
 
  }
 
  if(effStep >= 60) {__reset(); return 0x03; }
 
  else effStep++;
 
  return 0x01;
 
}
 

	
 

	
 

	
 
static uint32_t countloc = 0;
 
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)));
 
    }
 
    else
 
      ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, j, 0,0,0));
 
  }
 
  countloc = (countloc + 1) % LED_STRIP_NUM_LEDS;
 

	
 
  return 0x01;
 
  if(countloc == 0)
 
    return 0b11;
 
  else
 
    return 0b01;
 
}
 

	
 

	
 

	
 

	
 
//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
 
  {
main/main.c
Show inline comments
 
//
 
// Protofusion ESP32S3 Template
 
//
 

	
 
#include <stdint.h>
 
#include "freertos/FreeRTOS.h"
 
#include "freertos/task.h"
 
#include "freertos/event_groups.h"
 
#include "esp_system.h"
 
#include "esp_event.h"
 
#include "esp_log.h"
 
#include "nvs_flash.h"
 
#include "sdkconfig.h"
 
#include "osc_control.h"
 
#include "wifi.h"
 
// #include "usb_cdc.h"
 
#include "can.h"
 
#include "display.h"
 
#include "squeeze.h"
 
#include "ledstrip.h"
 
#include "display_gui.h"
 

	
 

	
 
// Private variables
 
static const char *TAG = "main";
 

	
 

	
 
// Application entry point
 
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_gui_homescreen();
 

	
 
    // Connect to wifi
 
    wifi_init();
 

	
 
    ledstrip_init();
 

	
 

	
 
    // Initialize OSC
 
    osc_init();
 

	
 
    squeeze_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)
 
    {
 
        vTaskDelay(pdMS_TO_TICKS(100));
 
    }
 

	
 
}
main/osc_control.c
Show inline comments
 
@@ -50,68 +50,74 @@ static bool callback(const char *topic, 
 
  char out[512] = {0};
 
  snprintf(out, 128, "topic: %s\nformat: %s\n", topic, format);
 

	
 
  for (size_t i = 0; i < strlen(format); i++) 
 
  {
 
    switch (format[i])
 
    {
 
      case 'i':
 
      {
 
        snprintf(out+strlen(out), 128-strlen(out), "Value: %ld", values[i].i);
 
        ESP_LOGI(TAG, "==> i: %ld", values[i].i);
 
        if(strcmp(topic, "/led_effect") == 0)
 
        {
 
          ledstrip_set_effect(values[i].i);
 
        }
 
      } break;
 

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

	
 
      case 'f':
 
      {
 
        if(values[i].f > 1.0)
 
          values[i].f = 1.0;
 
        if(values[i].f < 0.0)
 
          values[i].f = 0.0;
 

	
 
        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);
 
          ledstrip_set(g_man, r_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);
 
          ledstrip_set(g_man, r_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);
 
          ledstrip_set(g_man, r_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;
 

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

	
 
    }
 
  }
 

	
 
  display_update_text(out);
 

	
0 comments (0 inline, 0 general)