Switch ColorChord over to the new dev esp82xx.
This commit is contained in:
parent
bf3b8f3e56
commit
454ca08025
7 changed files with 257 additions and 143 deletions
|
@ -4,6 +4,7 @@
|
|||
#include <eagle_soc.h>
|
||||
#include "esp82xxutil.h"
|
||||
#include <DFT32.h>
|
||||
#include <settings.h>
|
||||
#include <embeddednf.h>
|
||||
#include <embeddedout.h>
|
||||
|
||||
|
@ -13,34 +14,21 @@ extern volatile uint16_t soundhead;
|
|||
|
||||
#define CONFIGURABLES 17 //(plus1)
|
||||
|
||||
extern uint8_t RootNoteOffset; //Set to define what the root note is. 0 = A.
|
||||
uint8_t gDFTIIR = 6;
|
||||
uint8_t gFUZZ_IIR_BITS = 1;
|
||||
uint8_t gFILTER_BLUR_PASSES = 2;
|
||||
uint8_t gSEMIBITSPERBIN = 3;
|
||||
uint8_t gMAX_JUMP_DISTANCE = 4;
|
||||
uint8_t gMAX_COMBINE_DISTANCE = 7;
|
||||
uint8_t gAMP_1_IIR_BITS = 4;
|
||||
uint8_t gAMP_2_IIR_BITS = 2;
|
||||
uint8_t gMIN_AMP_FOR_NOTE = 80;
|
||||
uint8_t gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR = 64;
|
||||
uint8_t gNOTE_FINAL_AMP = 12;
|
||||
uint8_t gNERF_NOTE_PORP = 15;
|
||||
uint8_t gUSE_NUM_LIN_LEDS = NUM_LIN_LEDS;
|
||||
uint8_t gCOLORCHORD_ACTIVE = 1;
|
||||
uint8_t gCOLORCHORD_OUTPUT_DRIVER = 0;
|
||||
|
||||
struct SaveLoad
|
||||
{
|
||||
uint8_t configs[CONFIGURABLES];
|
||||
uint8_t SaveLoadKey; //Must be 0xaa to be valid.
|
||||
} settings;
|
||||
|
||||
struct CCSettings CCS;
|
||||
|
||||
uint8_t gConfigDefaults[CONFIGURABLES] = { 0, 6, 1, 2, 3, 4, 7, 4, 2, 80, 64, 12, 15, NUM_LIN_LEDS, 1, 0, 0 };
|
||||
|
||||
uint8_t * gConfigurables[CONFIGURABLES] = { &RootNoteOffset, &gDFTIIR, &gFUZZ_IIR_BITS, &gFILTER_BLUR_PASSES,
|
||||
&gSEMIBITSPERBIN, &gMAX_JUMP_DISTANCE, &gMAX_COMBINE_DISTANCE, &gAMP_1_IIR_BITS,
|
||||
&gAMP_2_IIR_BITS, &gMIN_AMP_FOR_NOTE, &gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR, &gNOTE_FINAL_AMP,
|
||||
&gNERF_NOTE_PORP, &gUSE_NUM_LIN_LEDS, &gCOLORCHORD_ACTIVE, &gCOLORCHORD_OUTPUT_DRIVER, 0 };
|
||||
uint8_t * gConfigurables[CONFIGURABLES] = { &CCS.gROOT_NOTE_OFFSET, &CCS.gDFTIIR, &CCS.gFUZZ_IIR_BITS, &CCS.gFILTER_BLUR_PASSES,
|
||||
&CCS.gSEMIBITSPERBIN, &CCS.gMAX_JUMP_DISTANCE, &CCS.gMAX_COMBINE_DISTANCE, &CCS.gAMP_1_IIR_BITS,
|
||||
&CCS.gAMP_2_IIR_BITS, &CCS.gMIN_AMP_FOR_NOTE, &CCS.gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR, &CCS.gNOTE_FINAL_AMP,
|
||||
&CCS.gNERF_NOTE_PORP, &CCS.gUSE_NUM_LIN_LEDS, &CCS.gCOLORCHORD_ACTIVE, &CCS.gCOLORCHORD_OUTPUT_DRIVER, 0 };
|
||||
|
||||
char * gConfigurableNames[CONFIGURABLES] = { "gROOT_NOTE_OFFSET", "gDFTIIR", "gFUZZ_IIR_BITS", "gFILTER_BLUR_PASSES",
|
||||
"gSEMIBITSPERBIN", "gMAX_JUMP_DISTANCE", "gMAX_COMBINE_DISTANCE", "gAMP_1_IIR_BITS",
|
||||
|
@ -51,11 +39,24 @@ void ICACHE_FLASH_ATTR CustomStart( )
|
|||
{
|
||||
int i;
|
||||
spi_flash_read( 0x3D000, (uint32*)&settings, sizeof( settings ) );
|
||||
for( i = 0; i < CONFIGURABLES; i++ )
|
||||
if( settings.SaveLoadKey == 0xaa )
|
||||
{
|
||||
if( gConfigurables[i] )
|
||||
for( i = 0; i < CONFIGURABLES; i++ )
|
||||
{
|
||||
*gConfigurables[i] = settings.configs[i];
|
||||
if( gConfigurables[i] )
|
||||
{
|
||||
*gConfigurables[i] = settings.configs[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( i = 0; i < CONFIGURABLES; i++ )
|
||||
{
|
||||
if( gConfigurables[i] )
|
||||
{
|
||||
*gConfigurables[i] = gConfigDefaults[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,8 +106,8 @@ int ICACHE_FLASH_ATTR CustomCommand(char * buffer, int retsize, char *pusrdata,
|
|||
case 'l': case 'L': //LEDs
|
||||
{
|
||||
int i, it = 0;
|
||||
buffend += ets_sprintf( buffend, "CL\t%d\t", gUSE_NUM_LIN_LEDS );
|
||||
uint16_t toledsvals = gUSE_NUM_LIN_LEDS*3;
|
||||
buffend += ets_sprintf( buffend, "CL\t%d\t", USE_NUM_LIN_LEDS );
|
||||
uint16_t toledsvals = USE_NUM_LIN_LEDS*3;
|
||||
if( toledsvals > 600 ) toledsvals = 600;
|
||||
for( i = 0; i < toledsvals; i++ )
|
||||
{
|
||||
|
|
|
@ -15,9 +15,10 @@
|
|||
#include "ccconfig.h"
|
||||
#include <embeddednf.h>
|
||||
#include <embeddedout.h>
|
||||
#include <commonservices.h>
|
||||
#include "ets_sys.h"
|
||||
#include "gpio.h"
|
||||
|
||||
#include "settings.h"
|
||||
//#define PROFILE
|
||||
|
||||
#define PORT 7777
|
||||
|
@ -28,6 +29,7 @@
|
|||
#define procTaskPrio 0
|
||||
#define procTaskQueueLen 1
|
||||
|
||||
struct CCSettings CCS;
|
||||
static volatile os_timer_t some_timer;
|
||||
static struct espconn *pUdpServer;
|
||||
|
||||
|
@ -37,27 +39,26 @@ void ExitCritical();
|
|||
extern volatile uint8_t sounddata[HPABUFFSIZE];
|
||||
extern volatile uint16_t soundhead;
|
||||
uint16_t soundtail;
|
||||
extern uint8_t gCOLORCHORD_ACTIVE;
|
||||
static uint8_t hpa_running = 0;
|
||||
|
||||
static uint8_t hpa_running = 0;
|
||||
static uint8_t hpa_is_paused_for_wifi;
|
||||
void ICACHE_FLASH_ATTR CustomStart( );
|
||||
|
||||
void ICACHE_FLASH_ATTR user_rf_pre_init()
|
||||
{
|
||||
}
|
||||
|
||||
extern uint8_t gCOLORCHORD_OUTPUT_DRIVER;
|
||||
|
||||
//Call this once we've stacked together one full colorchord frame.
|
||||
static void NewFrame()
|
||||
{
|
||||
if( !gCOLORCHORD_ACTIVE ) return;
|
||||
if( !COLORCHORD_ACTIVE ) return;
|
||||
|
||||
//uint8_t led_outs[NUM_LIN_LEDS*3];
|
||||
int i;
|
||||
HandleFrameInfo();
|
||||
|
||||
switch( gCOLORCHORD_OUTPUT_DRIVER )
|
||||
switch( COLORCHORD_OUTPUT_DRIVER )
|
||||
{
|
||||
case 0:
|
||||
UpdateLinearLEDs();
|
||||
|
@ -72,56 +73,22 @@ static void NewFrame()
|
|||
}
|
||||
|
||||
os_event_t procTaskQueue[procTaskQueueLen];
|
||||
static uint8_t printed_ip = 0;
|
||||
uint32_t samp_iir = 0;
|
||||
int wf = 0;
|
||||
|
||||
//Tasks that happen all the time.
|
||||
|
||||
static void ICACHE_FLASH_ATTR HandleIPStuff()
|
||||
{
|
||||
//Idle Event.
|
||||
struct station_config wcfg;
|
||||
char stret[256];
|
||||
char *stt = &stret[0];
|
||||
struct ip_info ipi;
|
||||
|
||||
int stat = wifi_station_get_connect_status();
|
||||
|
||||
//printf( "STAT: %d %d\n", stat, wifi_get_opmode() );
|
||||
|
||||
if( stat == STATION_WRONG_PASSWORD || stat == STATION_NO_AP_FOUND || stat == STATION_CONNECT_FAIL )
|
||||
{
|
||||
wifi_set_opmode_current( 2 );
|
||||
stt += ets_sprintf( stt, "Connection failed: %d\n", stat );
|
||||
uart0_sendStr(stret);
|
||||
}
|
||||
|
||||
if( stat == STATION_GOT_IP && !printed_ip )
|
||||
{
|
||||
wifi_station_get_config( &wcfg );
|
||||
wifi_get_ip_info(0, &ipi);
|
||||
stt += ets_sprintf( stt, "STAT: %d\n", stat );
|
||||
stt += ets_sprintf( stt, "IP: %d.%d.%d.%d\n", (ipi.ip.addr>>0)&0xff,(ipi.ip.addr>>8)&0xff,(ipi.ip.addr>>16)&0xff,(ipi.ip.addr>>24)&0xff );
|
||||
stt += ets_sprintf( stt, "NM: %d.%d.%d.%d\n", (ipi.netmask.addr>>0)&0xff,(ipi.netmask.addr>>8)&0xff,(ipi.netmask.addr>>16)&0xff,(ipi.netmask.addr>>24)&0xff );
|
||||
stt += ets_sprintf( stt, "GW: %d.%d.%d.%d\n", (ipi.gw.addr>>0)&0xff,(ipi.gw.addr>>8)&0xff,(ipi.gw.addr>>16)&0xff,(ipi.gw.addr>>24)&0xff );
|
||||
stt += ets_sprintf( stt, "WCFG: /%s/%s/\n", wcfg.ssid, wcfg.password );
|
||||
uart0_sendStr(stret);
|
||||
printed_ip = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void procTask(os_event_t *events)
|
||||
{
|
||||
system_os_post(procTaskPrio, 0, 0 );
|
||||
|
||||
if( gCOLORCHORD_ACTIVE && !hpa_running )
|
||||
if( COLORCHORD_ACTIVE && !hpa_running )
|
||||
{
|
||||
ExitCritical();
|
||||
hpa_running = 1;
|
||||
}
|
||||
|
||||
if( !gCOLORCHORD_ACTIVE && hpa_running )
|
||||
if( !COLORCHORD_ACTIVE && hpa_running )
|
||||
{
|
||||
EnterCritical();
|
||||
hpa_running = 0;
|
||||
|
@ -152,7 +119,6 @@ static void procTask(os_event_t *events)
|
|||
if( events->sig == 0 && events->par == 0 )
|
||||
{
|
||||
CSTick( 0 );
|
||||
HandleIPStuff();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -161,6 +127,12 @@ static void procTask(os_event_t *events)
|
|||
static void ICACHE_FLASH_ATTR myTimer(void *arg)
|
||||
{
|
||||
CSTick( 1 );
|
||||
|
||||
if( hpa_is_paused_for_wifi && printed_ip )
|
||||
{
|
||||
StartHPATimer(); //Init the high speed ADC timer.
|
||||
hpa_running = 1;
|
||||
}
|
||||
// uart0_sendStr(".");
|
||||
// printf( "%d/%d\n",soundtail,soundhead );
|
||||
// printf( "%d/%d\n",soundtail,soundhead );
|
||||
|
@ -238,8 +210,16 @@ void ICACHE_FLASH_ATTR user_init(void)
|
|||
|
||||
InitColorChord(); //Init colorchord
|
||||
|
||||
StartHPATimer(); //Init the high speed ADC timer.
|
||||
hpa_running = 1;
|
||||
//Tricky: If we are in station mode, wait for that to get resolved before enabling the high speed timer.
|
||||
if( wifi_get_opmode() == 1 )
|
||||
{
|
||||
hpa_is_paused_for_wifi = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
StartHPATimer(); //Init the high speed ADC timer.
|
||||
hpa_running = 1;
|
||||
}
|
||||
|
||||
ws2812_init();
|
||||
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
//4 takes up more RAM per LED than 3.
|
||||
//3 has slightly more restrictve timing requirements.
|
||||
//4 has more DMA load when running.
|
||||
#define WS2812_THREE_SAMPLE
|
||||
|
||||
//#define WS2812_THREE_SAMPLE
|
||||
//#define WS2812_FOUR_SAMPLE
|
||||
|
||||
void ICACHE_FLASH_ATTR ws2812_init();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue