added code to read color sequences from file

- if there is a FLAME.RGB file on the dataflash it will use this
  file to read tuples of three bytes as color values
- if this file doesn't exist, use nickname hashing
This commit is contained in:
bsx 2011-12-17 20:39:53 +01:00
parent 0e0f2439be
commit b576a255b9
1 changed files with 28 additions and 10 deletions

View File

@ -9,6 +9,8 @@
#include "basic/config.h" #include "basic/config.h"
#include "basic/xxtea.h" #include "basic/xxtea.h"
#include "filesystem/util.h"
#define FLAME_I2C_WRITE 0xC6 #define FLAME_I2C_WRITE 0xC6
#define FLAME_I2C_READ 0xC7 #define FLAME_I2C_READ 0xC7
@ -70,11 +72,25 @@ uint8_t flameRGBMode = FLAME_OFF;
uint8_t flameRGBI2Cpwm = 0; uint8_t flameRGBI2Cpwm = 0;
uint8_t flameRGBTicks = 0; uint8_t flameRGBTicks = 0;
uint8_t rgbData[24];
uint8_t rgbDataSize = 0;
uint8_t rgbDataOffset = 0;
void setFlameRGBPWM() { void setFlameRGBPWM() {
flameRGBSetI2C(FLAME_I2C_CR_GRPPWM, flameRGBI2Cpwm); // set pwm flameRGBSetI2C(FLAME_I2C_CR_GRPPWM, flameRGBI2Cpwm); // set pwm
} }
void setFlameRGBColor() { void setFlameRGBColor() {
if (rgbDataSize > 2) {
flameRGBSetI2C(FLAME_I2C_CR_PWM0, rgbData[rgbDataOffset]);
flameRGBSetI2C(FLAME_I2C_CR_PWM3, rgbData[rgbDataOffset + 1]);
flameRGBSetI2C(FLAME_I2C_CR_PWM2, rgbData[rgbDataOffset + 2]);
if (rgbDataSize >= rgbDataOffset + 5) {
rgbDataOffset += 3;
} else {
rgbDataOffset = 0;
}
} else {
// generate a hash from the nickname // generate a hash from the nickname
uint32_t hash[4]; uint32_t hash[4];
uint32_t const key[4] = {0xcfd97ebc, 0x21117b45, 0x7193727, 0xa336f4d6}; uint32_t const key[4] = {0xcfd97ebc, 0x21117b45, 0x7193727, 0xa336f4d6};
@ -85,6 +101,7 @@ void setFlameRGBColor() {
flameRGBSetI2C(FLAME_I2C_CR_PWM2, hash[2] % 255); flameRGBSetI2C(FLAME_I2C_CR_PWM2, hash[2] % 255);
flameRGBSetI2C(FLAME_I2C_CR_PWM3, hash[3] % 255); flameRGBSetI2C(FLAME_I2C_CR_PWM3, hash[3] % 255);
} }
}
void tick_flame_rgb(void) { // every 10ms void tick_flame_rgb(void) { // every 10ms
static char night=0; static char night=0;
@ -115,6 +132,7 @@ void tick_flame_rgb(void) { // every 10ms
if (isNight()) { if (isNight()) {
flameRGBTicks = 0; flameRGBTicks = 0;
flameRGBMode = FLAME_UP; flameRGBMode = FLAME_UP;
push_queue(&setFlameRGBColor);
} }
} }
@ -170,7 +188,7 @@ void init_flame_rgb(void) {
flameRGBSetI2C(FLAME_I2C_CR_GRPPWM, 0x00); // overall dimming flameRGBSetI2C(FLAME_I2C_CR_GRPPWM, 0x00); // overall dimming
push_queue(&setFlameRGBColor); rgbDataSize = readTextFile("FLAME.RGB", rgbData, 24);
enableConfig(CFG_TYPE_FLAME,1); enableConfig(CFG_TYPE_FLAME,1);
} }