Skip to content

Commit

Permalink
add status led remove print statements
Browse files Browse the repository at this point in the history
Signed-off-by: Noah Huetter <[email protected]>
  • Loading branch information
huettern committed May 17, 2020
1 parent 570247e commit 60f3293
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 11 deletions.
85 changes: 77 additions & 8 deletions firmware/src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: Noah Huetter
* @Date: 2020-04-15 11:16:05
* @Last Modified by: Noah Huetter
* @Last Modified time: 2020-05-17 17:01:28
* @Last Modified time: 2020-05-17 19:16:38
*/
#include "app.h"
#include <stdlib.h>
Expand Down Expand Up @@ -35,7 +35,7 @@
/**
* @brief Edison state machine settings
*/
#define EDI_LOC_TIMEOUT 4000 // [ms] to wait for location after hotword
#define EDI_LOC_TIMEOUT 5000 // [ms] to wait for location after hotword

#define EDI_WAKEWORD "edison" // on which keyword edison should wake and transition to hot

Expand Down Expand Up @@ -319,6 +319,7 @@ int8_t appMicMfccInfereContinuous (uint8_t *args)
// netInBufOff += in_x*in_y;

// report
mainSetPrintfUart(&huart1);
printf("pred: [ ");
for(tmp32 = 0; tmp32 < AI_NET_OUTSIZE; tmp32++)
{
Expand All @@ -342,6 +343,7 @@ int8_t appMicMfccInfereContinuous (uint8_t *args)
ledSet(0);
}
printf("\n");
mainSetPrintfUart(&huart4);

if(netOutFilt[0] > TRUE_THRESHOLD) LED2_ORA();
else LED2_BLU();
Expand All @@ -355,9 +357,9 @@ int8_t appMicMfccInfereContinuous (uint8_t *args)
// if(netInBufOff > 12*in_x*in_y) doAbort = true;

// run FSM
mainSetPrintfUart(&huart1);
edisonFSM(netOutFilt, &predMax, &predMaxIdx); // preds, max, idx
mainSetPrintfUart(&huart4);
edisonFSM(netOutFilt, &predMax, &predMaxIdx); // preds, max, idx
mainSetPrintfUart(&huart1);
}

// stop sampling
Expand Down Expand Up @@ -720,6 +722,28 @@ static void edisonFSM(float* predictions, float* predMax, uint32_t* predMaxIdx)
static edisonLocation_t * loc;
static edisonValue_t * val;

static uint8_t brAnimIdx;
// breath animation of status led
static animationBreath_t brAnim;
brAnim.start[0] = 255;
brAnim.start[1] = 86;
brAnim.start[2] = 2;
brAnim.stop[0] = 0;
brAnim.stop[1] = 0;
brAnim.stop[2] = 0;
brAnim.speed = 0.02;
brAnim.ledsOneHot = 1<<4;
// fade animation of status led
static animationFade_t statFadeAnim;
statFadeAnim.start[0] = 0;
statFadeAnim.start[1] = 0;
statFadeAnim.start[2] = 0;
statFadeAnim.stop[0] = 0;
statFadeAnim.stop[1] = 20;
statFadeAnim.stop[2] = 0;
statFadeAnim.speed = 0.01;
statFadeAnim.ledsOneHot = 1<<4;

// time since last FSM call
uint32_t tickNow = __HAL_TIM_GET_COUNTER(&htim1);
if(tickNow > tickOld) dt = MAIN_TIM1_TICK_US*(tickNow-tickOld);
Expand Down Expand Up @@ -784,7 +808,7 @@ static void edisonFSM(float* predictions, float* predMax, uint32_t* predMaxIdx)
}
}
}
else if (hotTimeout > EDI_LOC_TIMEOUT)
if (hotTimeout > EDI_LOC_TIMEOUT)
{
// timeout occured, transition to idle
nextState = EDI_IDLE;
Expand All @@ -808,7 +832,7 @@ static void edisonFSM(float* predictions, float* predMax, uint32_t* predMaxIdx)
}
}
}
else if (hotTimeout > EDI_LOC_TIMEOUT)
if (hotTimeout > EDI_LOC_TIMEOUT)
{
// timeout occured, transition to idle
nextState = EDI_IDLE;
Expand All @@ -818,6 +842,7 @@ static void edisonFSM(float* predictions, float* predMax, uint32_t* predMaxIdx)
case EDI_SET:
// set location to required value
loc->color.value = val->color.value;
printf("%s %s\n", loc->name, val->name);
animationFade_t anim;
uint32_t colorOld = ledGetColorRgb(loc->ledIdx);
anim.start[0] = (colorOld>>24)&0xff;
Expand All @@ -828,7 +853,7 @@ static void edisonFSM(float* predictions, float* predMax, uint32_t* predMaxIdx)
anim.stop[2] = loc->color.rgbw.b;
anim.speed = 0.01;
anim.ledsOneHot = 1<<loc->ledIdx;
printf("onehot %d start: %f %f %f stop: %f %f %f\n", anim.ledsOneHot, anim.start[0], anim.start[1], anim.start[2], anim.stop[0], anim.stop[1], anim.stop[2]);
// printf("onehot %d start: %f %f %f stop: %f %f %f\n", anim.ledsOneHot, anim.start[0], anim.start[1], anim.start[2], anim.stop[0], anim.stop[1], anim.stop[2]);
(void)ledStartFadeAnimation(&anim);

// ledSetColorRgb(loc->ledIdx, loc->color.value);
Expand All @@ -841,9 +866,53 @@ static void edisonFSM(float* predictions, float* predMax, uint32_t* predMaxIdx)
Error_Handler();
}

// state transition
// state transition -> change state led
if(nextState != ediState)
{
if (nextState == EDI_IDLE)
{
if( (ediState == EDI_HOT) || (ediState == EDI_LOC) )
{
ledStopAnimation(brAnimIdx);
ledSetColor(4, 0, 20, 0); ledUpdate(0);
}
if( (ediState == EDI_RESET) ) ledSetColor(4, 0, 20, 0); ledUpdate(0);
}
if (nextState == EDI_HOT)
{
// ledSetColor(4, 166, 44, 0); ledUpdate(0);
brAnim.start[0] = 64;
brAnim.start[1] = 23;
brAnim.start[2] = 1;
brAnimIdx = ledStartBreathAnimation(&brAnim);
}
if (nextState == EDI_LOC)
{
ledStopAnimation(brAnimIdx);
brAnim.start[0] = 1;
brAnim.start[1] = 30;
brAnim.start[2] = 42;
brAnimIdx = ledStartBreathAnimation(&brAnim);
// ledSetColor(4, 3, 121, 168); ledUpdate(0);
// ledSetColor(4, 255, 86, 2); ledUpdate(0);
}
if (nextState == EDI_SET)
{
ledStopAnimation(brAnimIdx);
if(val->color.rgbw.r || val->color.rgbw.g || val->color.rgbw.b)
{
statFadeAnim.start[0] = 0;
statFadeAnim.start[1] = 80;
statFadeAnim.start[2] = 0;
}
else
{
statFadeAnim.start[0] = 80;
statFadeAnim.start[1] = 0;
statFadeAnim.start[2] = 0;
}
(void)ledStartFadeAnimation(&statFadeAnim);
}
}
ediState = nextState;
}
Expand Down
5 changes: 3 additions & 2 deletions firmware/src/io/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: Noah Huetter
* @Date: 2020-05-14 21:05:15
* @Last Modified by: Noah Huetter
* @Last Modified time: 2020-05-17 16:29:56
* @Last Modified time: 2020-05-17 19:27:43
*
* WS2811 code adapted from https://github.com/MaJerle/stm32-ws2812b-tim-pwm-dma/blob/master/Src/main.c
*/
Expand Down Expand Up @@ -358,6 +358,7 @@ uint8_t ledStartBreathAnimation(animationBreath_t *anim)
void ledStopAnimation(uint8_t idx)
{
animations[idx].running = 0;
if(animations[idx].anim) free(animations[idx].anim);
}

/**
Expand Down Expand Up @@ -659,7 +660,7 @@ void ledAnimationCallback(void)
for(idx = 0; idx < MAX_NUM_ANIMATIONS; idx++)
{
if(animations[idx].running)
{
{
animations[idx].running = animations[idx].handle(animations[idx].anim);
update = 1;
}
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: Noah Huetter
* @Date: 2020-04-13 13:49:34
* @Last Modified by: Noah Huetter
* @Last Modified time: 2020-05-17 18:21:46
* @Last Modified time: 2020-05-17 18:58:40
*/

#include "main.h"
Expand Down

0 comments on commit 60f3293

Please sign in to comment.