Reduced cap touch sampling to fix performance

This commit is contained in:
jonsampson 2019-10-12 22:46:50 -04:00
parent 243aabc8fa
commit 14c76cc985

View file

@ -2,6 +2,7 @@
#include "globals.h" #include "globals.h"
static uint32_t lastTouchSample;
static uint32_t lastBehaviorChange; static uint32_t lastBehaviorChange;
static uint32_t lastWave; static uint32_t lastWave;
@ -10,6 +11,7 @@ static int currentBehavior = 0;
static int colorIndex = 0; static int colorIndex = 0;
const uint32_t SAMPLE_TIME = 50000; const uint32_t SAMPLE_TIME = 50000;
const uint32_t TOUCH_SAMPLE_TIME = SAMPLE_TIME * 15;
static uint8_t currentStep = 100; static uint8_t currentStep = 100;
static int direction = -3; static int direction = -3;
static uint32_t lastColorShift; static uint32_t lastColorShift;
@ -50,6 +52,10 @@ void setGradientPixelColor(uint16_t ledPosition, uint16_t step, float redRatio,
arcada.pixels.setPixelColor(ledPosition, red, green, blue); arcada.pixels.setPixelColor(ledPosition, red, green, blue);
} }
void stepGreenBlackGradient(uint16_t ledPosition, uint16_t step) {
setGradientPixelColor(ledPosition, step, 0, 1, 0);
}
void stepOrangeBlackGradient(uint16_t ledPosition, uint16_t step) { void stepOrangeBlackGradient(uint16_t ledPosition, uint16_t step) {
setGradientPixelColor(ledPosition, step, 1, 0.64453125, 0); setGradientPixelColor(ledPosition, step, 1, 0.64453125, 0);
} }
@ -233,28 +239,31 @@ void changeBehavior(int newBehavior, uint32_t timeOfChange) {
} }
void user_setup(void) { void user_setup(void) {
lastBehaviorChange, lastWave, lastColorShift, lastRainbowColorShift = micros(); lastBehaviorChange, lastWave, lastColorShift, lastRainbowColorShift, lastTouchSample = micros();
arcada.pixels.setBrightness(255); arcada.pixels.setBrightness(255);
advanceHalloweenGradients(); advanceHalloweenGradients();
changeBehavior(0, micros()); changeBehavior(0, micros());
} }
void user_loop(void) { void user_loop(void) {
uint8_t pressed_buttons = arcada.readButtons();
uint8_t justpressed_buttons = arcada.justPressedButtons();
uint32_t elapsedSince = micros(); uint32_t elapsedSince = micros();
if (justpressed_buttons & ARCADA_BUTTONMASK_UP){ if(elapsedSince - lastTouchSample > TOUCH_SAMPLE_TIME) {
changeBehavior(0, elapsedSince); lastTouchSample = elapsedSince;
} uint8_t pressed_buttons = arcada.readButtons();
else if(justpressed_buttons & ARCADA_BUTTONMASK_DOWN) { uint8_t justpressed_buttons = arcada.justPressedButtons();
changeBehavior(1, elapsedSince);
} if (justpressed_buttons & ARCADA_BUTTONMASK_UP){
else if(justpressed_buttons & ARCADA_BUTTONMASK_LEFT) { changeBehavior(0, elapsedSince);
changeBehavior(2, elapsedSince); }
} else if(justpressed_buttons & ARCADA_BUTTONMASK_DOWN) {
else if(justpressed_buttons & ARCADA_BUTTONMASK_RIGHT) { changeBehavior(1, elapsedSince);
changeBehavior(3, elapsedSince); }
else if(justpressed_buttons & ARCADA_BUTTONMASK_LEFT) {
changeBehavior(2, elapsedSince);
}
else if(justpressed_buttons & ARCADA_BUTTONMASK_RIGHT) {
changeBehavior(3, elapsedSince);
}
} }
if (elapsedSince - lastWave > SAMPLE_TIME) { if (elapsedSince - lastWave > SAMPLE_TIME) {