Add throttle level indicator led mode

This commit is contained in:
Goebish 2014-09-19 01:09:59 +02:00
parent 0b4f5804bc
commit b83e7b42b7
4 changed files with 28 additions and 3 deletions

View File

@ -74,3 +74,9 @@ float degreesToRadians(int16_t degrees)
return degrees * RAD;
}
int scaleRange(int x, int srcMin, int srcMax, int destMin, int destMax) {
long int a = ((long int) destMax - (long int) destMin) * ((long int) x - (long int) srcMin);
long int b = (long int) srcMax - (long int) srcMin;
return ((a / b) - (destMax - destMin)) + destMax;
}

View File

@ -48,3 +48,4 @@ void devPush(stdev_t *dev, float x);
float devVariance(stdev_t *dev);
float devStandardDeviation(stdev_t *dev);
float degreesToRadians(int16_t degrees);
int scaleRange(int x, int srcMin, int srcMax, int destMin, int destMax);

View File

@ -136,13 +136,14 @@ static const uint8_t directionMappings[DIRECTION_COUNT] = {
LED_DIRECTION_DOWN
};
static const char functionCodes[] = { 'I', 'W', 'F', 'A' };
static const char functionCodes[] = { 'I', 'W', 'F', 'A', 'T' };
#define FUNCTION_COUNT (sizeof(functionCodes) / sizeof(functionCodes[0]))
static const uint16_t functionMappings[FUNCTION_COUNT] = {
LED_FUNCTION_INDICATOR,
LED_FUNCTION_WARNING,
LED_FUNCTION_FLIGHT_MODE,
LED_FUNCTION_ARM_STATE
LED_FUNCTION_ARM_STATE,
LED_FUNCTION_THROTTLE
};
// grid offsets
@ -599,6 +600,21 @@ void applyLedIndicatorLayer(uint8_t indicatorFlashState)
}
}
void applyLedThrottleLayer()
{
const ledConfig_t *ledConfig;
uint8_t ledIndex;
for (ledIndex = 0; ledIndex < ledCount; ledIndex++) {
ledConfig = &ledConfigs[ledIndex];
if(ledConfig->flags & LED_FUNCTION_THROTTLE) {
int hue = scaleRange(rcCommand[THROTTLE], PWM_RANGE_MIN, PWM_RANGE_MAX, hsv_lightBlue.h, hsv_red.h);
hsvColor_t color = {hue , 0 , 255};
setLedHsv(ledIndex, &color);
}
}
}
static uint8_t frameCounter = 0;
static uint8_t previousRow;
@ -666,6 +682,7 @@ void updateLedStrip(void)
// LAYER 1
applyLedModeLayer();
applyLedThrottleLayer();
// LAYER 2

View File

@ -43,7 +43,8 @@ typedef enum {
LED_FUNCTION_INDICATOR = (1 << 6),
LED_FUNCTION_WARNING = (1 << 7),
LED_FUNCTION_FLIGHT_MODE = (1 << 8),
LED_FUNCTION_ARM_STATE = (1 << 9)
LED_FUNCTION_ARM_STATE = (1 << 9),
LED_FUNCTION_THROTTLE = (1 << 10)
} ledFlag_e;
typedef struct ledConfig_s {