added periodic resending, free memory readout, rgb callibration.
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
# This is the CMakeCache file.
|
# This is the CMakeCache file.
|
||||||
# For build in directory: /home/philipp/Programming/RGBcontroller
|
# For build in directory: /home/philipp/Programming/avr/RGBcontroller
|
||||||
# It was generated by CMake: /usr/bin/cmake
|
# It was generated by CMake: /usr/bin/cmake
|
||||||
# You can edit this file to change values found and used by cmake.
|
# You can edit this file to change values found and used by cmake.
|
||||||
# If you do not want to change any of the values, simply exit the editor.
|
# If you do not want to change any of the values, simply exit the editor.
|
||||||
@ -138,6 +138,12 @@ CMAKE_OBJCOPY:FILEPATH=/bin/objcopy
|
|||||||
//Path to a program.
|
//Path to a program.
|
||||||
CMAKE_OBJDUMP:FILEPATH=/bin/objdump
|
CMAKE_OBJDUMP:FILEPATH=/bin/objdump
|
||||||
|
|
||||||
|
//Value Computed by CMake
|
||||||
|
CMAKE_PROJECT_DESCRIPTION:STATIC=
|
||||||
|
|
||||||
|
//Value Computed by CMake
|
||||||
|
CMAKE_PROJECT_HOMEPAGE_URL:STATIC=
|
||||||
|
|
||||||
//Value Computed by CMake
|
//Value Computed by CMake
|
||||||
CMAKE_PROJECT_NAME:STATIC=rgbcontroller
|
CMAKE_PROJECT_NAME:STATIC=rgbcontroller
|
||||||
|
|
||||||
@ -219,10 +225,10 @@ PORT_SPEED:STRING=57600
|
|||||||
PROGRAMMER:STRING=stk500v1
|
PROGRAMMER:STRING=stk500v1
|
||||||
|
|
||||||
//Value Computed by CMake
|
//Value Computed by CMake
|
||||||
rgbcontroller_BINARY_DIR:STATIC=/home/philipp/Programming/RGBcontroller
|
rgbcontroller_BINARY_DIR:STATIC=/home/philipp/Programming/avr/RGBcontroller
|
||||||
|
|
||||||
//Value Computed by CMake
|
//Value Computed by CMake
|
||||||
rgbcontroller_SOURCE_DIR:STATIC=/home/philipp/Programming/RGBcontroller
|
rgbcontroller_SOURCE_DIR:STATIC=/home/philipp/Programming/avr/RGBcontroller
|
||||||
|
|
||||||
|
|
||||||
########################
|
########################
|
||||||
@ -232,13 +238,13 @@ rgbcontroller_SOURCE_DIR:STATIC=/home/philipp/Programming/RGBcontroller
|
|||||||
//ADVANCED property for variable: CMAKE_AR
|
//ADVANCED property for variable: CMAKE_AR
|
||||||
CMAKE_AR-ADVANCED:INTERNAL=1
|
CMAKE_AR-ADVANCED:INTERNAL=1
|
||||||
//This is the directory where this CMakeCache.txt was created
|
//This is the directory where this CMakeCache.txt was created
|
||||||
CMAKE_CACHEFILE_DIR:INTERNAL=/home/philipp/Programming/RGBcontroller
|
CMAKE_CACHEFILE_DIR:INTERNAL=/home/philipp/Programming/avr/RGBcontroller
|
||||||
//Major version of cmake used to create the current loaded cache
|
//Major version of cmake used to create the current loaded cache
|
||||||
CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3
|
CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3
|
||||||
//Minor version of cmake used to create the current loaded cache
|
//Minor version of cmake used to create the current loaded cache
|
||||||
CMAKE_CACHE_MINOR_VERSION:INTERNAL=12
|
CMAKE_CACHE_MINOR_VERSION:INTERNAL=13
|
||||||
//Patch version of cmake used to create the current loaded cache
|
//Patch version of cmake used to create the current loaded cache
|
||||||
CMAKE_CACHE_PATCH_VERSION:INTERNAL=3
|
CMAKE_CACHE_PATCH_VERSION:INTERNAL=2
|
||||||
//ADVANCED property for variable: CMAKE_COLOR_MAKEFILE
|
//ADVANCED property for variable: CMAKE_COLOR_MAKEFILE
|
||||||
CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1
|
CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1
|
||||||
//Path to CMake executable.
|
//Path to CMake executable.
|
||||||
@ -307,7 +313,7 @@ CMAKE_GENERATOR_PLATFORM:INTERNAL=
|
|||||||
CMAKE_GENERATOR_TOOLSET:INTERNAL=
|
CMAKE_GENERATOR_TOOLSET:INTERNAL=
|
||||||
//Source directory with the top level CMakeLists.txt file for this
|
//Source directory with the top level CMakeLists.txt file for this
|
||||||
// project
|
// project
|
||||||
CMAKE_HOME_DIRECTORY:INTERNAL=/home/philipp/Programming/RGBcontroller
|
CMAKE_HOME_DIRECTORY:INTERNAL=/home/philipp/Programming/avr/RGBcontroller
|
||||||
//Install .so files without execute permission.
|
//Install .so files without execute permission.
|
||||||
CMAKE_INSTALL_SO_NO_EXE:INTERNAL=0
|
CMAKE_INSTALL_SO_NO_EXE:INTERNAL=0
|
||||||
//ADVANCED property for variable: CMAKE_LINKER
|
//ADVANCED property for variable: CMAKE_LINKER
|
||||||
@ -337,7 +343,7 @@ CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1
|
|||||||
//ADVANCED property for variable: CMAKE_RANLIB
|
//ADVANCED property for variable: CMAKE_RANLIB
|
||||||
CMAKE_RANLIB-ADVANCED:INTERNAL=1
|
CMAKE_RANLIB-ADVANCED:INTERNAL=1
|
||||||
//Path to CMake installation.
|
//Path to CMake installation.
|
||||||
CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.12
|
CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.13
|
||||||
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS
|
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS
|
||||||
CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1
|
CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1
|
||||||
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG
|
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG
|
||||||
|
@ -98,7 +98,15 @@ void W433DataReciver::interrupt()
|
|||||||
{
|
{
|
||||||
uint16_t elapsedTime = polarity*(((*_timerOverflowRegister & 0x01) ? *_timerRegister+(UINT16_MAX - previousTime) : *_timerRegister - previousTime)/TICKS_PER_US);
|
uint16_t elapsedTime = polarity*(((*_timerOverflowRegister & 0x01) ? *_timerRegister+(UINT16_MAX - previousTime) : *_timerRegister - previousTime)/TICKS_PER_US);
|
||||||
|
|
||||||
if(elapsedTime < SMALL_TIME/4) return;
|
if(elapsedTime < DISCARD_TIME)
|
||||||
|
{
|
||||||
|
if(timesBufferIndex > 0 && elapsedTime + timesBuffer[timesBufferIndex-1] < LARGE_TIME+LARGE_TIME_TOLERANCE)
|
||||||
|
{
|
||||||
|
previousTime = *_timerRegister - elapsedTime - abs(timesBuffer[timesBufferIndex-1]);
|
||||||
|
--timesBufferIndex;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
previousTime = *_timerRegister;
|
previousTime = *_timerRegister;
|
||||||
*_timerOverflowRegister = *_timerOverflowRegister | 0x01;
|
*_timerOverflowRegister = *_timerOverflowRegister | 0x01;
|
||||||
|
@ -17,9 +17,10 @@ private:
|
|||||||
static constexpr uint16_t SYNC_TIME = 800;
|
static constexpr uint16_t SYNC_TIME = 800;
|
||||||
static constexpr uint16_t LARGE_TIME = 2000;
|
static constexpr uint16_t LARGE_TIME = 2000;
|
||||||
static constexpr uint16_t SMALL_TIME = 500;
|
static constexpr uint16_t SMALL_TIME = 500;
|
||||||
static constexpr uint8_t SYNC_TIME_TOLERANCE = SYNC_TIME*0.15;
|
static constexpr uint8_t SYNC_TIME_TOLERANCE = SYNC_TIME*0.20;
|
||||||
static constexpr uint8_t LARGE_TIME_TOLERANCE = LARGE_TIME*0.15;
|
static constexpr uint16_t LARGE_TIME_TOLERANCE = LARGE_TIME*0.30;
|
||||||
static constexpr uint8_t SMALL_TIME_TOLERANCE = SMALL_TIME*0.15;
|
static constexpr uint8_t SMALL_TIME_TOLERANCE = SMALL_TIME*0.30;
|
||||||
|
static constexpr uint8_t DISCARD_TIME = SMALL_TIME*0.3;
|
||||||
static constexpr uint16_t TICKS_PER_US = (F_CPU) / (1000000*CLOCK_DEVIDER) ;
|
static constexpr uint16_t TICKS_PER_US = (F_CPU) / (1000000*CLOCK_DEVIDER) ;
|
||||||
static constexpr uint8_t signature = 0xA5;
|
static constexpr uint8_t signature = 0xA5;
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ uint16_t WirelessRelay::getId()
|
|||||||
|
|
||||||
bool WirelessRelay::getExpectedState()
|
bool WirelessRelay::getExpectedState()
|
||||||
{
|
{
|
||||||
return _state;//_state;
|
return _state;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* WirelessRelay::getName()
|
char* WirelessRelay::getName()
|
||||||
@ -104,6 +104,11 @@ void WirelessRelay::init( const uint16_t id, char nameIn[])
|
|||||||
_id=id;
|
_id=id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WirelessRelay::resend()
|
||||||
|
{
|
||||||
|
_state ? on() : off();
|
||||||
|
}
|
||||||
|
|
||||||
WirelessRelay::WirelessRelay(const uint16_t id, char nameIn[])
|
WirelessRelay::WirelessRelay(const uint16_t id, char nameIn[])
|
||||||
{
|
{
|
||||||
init(id, nameIn);
|
init(id, nameIn);
|
||||||
|
@ -23,7 +23,6 @@ private:
|
|||||||
public:
|
public:
|
||||||
WirelessRelay(const uint16_t id, char nameIn[]);
|
WirelessRelay(const uint16_t id, char nameIn[]);
|
||||||
WirelessRelay();
|
WirelessRelay();
|
||||||
void setTimeout(uint64_t timeout);
|
|
||||||
void init(const uint16_t id, char nameIn[]);
|
void init(const uint16_t id, char nameIn[]);
|
||||||
void on();
|
void on();
|
||||||
void off();
|
void off();
|
||||||
@ -31,5 +30,6 @@ public:
|
|||||||
void setName(char* name);
|
void setName(char* name);
|
||||||
uint16_t getId();
|
uint16_t getId();
|
||||||
bool getExpectedState();
|
bool getExpectedState();
|
||||||
|
void resend();
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
75
main.cpp
75
main.cpp
@ -9,6 +9,7 @@
|
|||||||
#include "rgbled.h"
|
#include "rgbled.h"
|
||||||
#include "eeprom.h"
|
#include "eeprom.h"
|
||||||
#include "bitrep.h"
|
#include "bitrep.h"
|
||||||
|
#include "watchdog.h"
|
||||||
#include "staticvector.h"
|
#include "staticvector.h"
|
||||||
#include "W433DataReciver.h"
|
#include "W433DataReciver.h"
|
||||||
|
|
||||||
@ -22,12 +23,25 @@ char buffer[SNPRINTF_BUFFER_SIZE];
|
|||||||
|
|
||||||
SVector<WirelessRelay, MAX_RELAYS> relays;
|
SVector<WirelessRelay, MAX_RELAYS> relays;
|
||||||
|
|
||||||
|
bool sensorsPaused = false;
|
||||||
|
|
||||||
|
static volatile bool resendNow = false;
|
||||||
|
static volatile uint8_t resendCounter = 0;
|
||||||
|
static bool resendEnabled = false;
|
||||||
|
|
||||||
ISR(PCINT1_vect)
|
ISR(PCINT1_vect)
|
||||||
{
|
{
|
||||||
W433DataReciver::staticInterrupt();
|
W433DataReciver::staticInterrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sensorsPaused = false;
|
ISR(WDT_vect)
|
||||||
|
{
|
||||||
|
if(++resendCounter > 225)
|
||||||
|
{
|
||||||
|
resendCounter = 0;
|
||||||
|
if(resendEnabled)resendNow = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline static void printHelp(Serial* serial)
|
inline static void printHelp(Serial* serial)
|
||||||
{
|
{
|
||||||
@ -37,9 +51,11 @@ inline static void printHelp(Serial* serial)
|
|||||||
relay add [id] [name] : Add Wireless Relay.\n\
|
relay add [id] [name] : Add Wireless Relay.\n\
|
||||||
relay delete : Delete last Relay.\n\
|
relay delete : Delete last Relay.\n\
|
||||||
relay [on/off] [nn] : Turn on/off nth relay.\n\
|
relay [on/off] [nn] : Turn on/off nth relay.\n\
|
||||||
|
relay resend [on/off] : Turn on/off periodic auto resend.\n\
|
||||||
state : Get machine readable state.\n\
|
state : Get machine readable state.\n\
|
||||||
erase : Erase epprom.\n\
|
erase : Erase epprom.\n\
|
||||||
dump : Dump epprom.\n\
|
dump : Dump epprom.\n\
|
||||||
|
free : show free ram.\n\
|
||||||
pause : pause sensor output.\n\
|
pause : pause sensor output.\n\
|
||||||
resume : resume sensor output.\n\
|
resume : resume sensor output.\n\
|
||||||
rgb fade [on/off] : turn Colorfade on or off.\n\
|
rgb fade [on/off] : turn Colorfade on or off.\n\
|
||||||
@ -52,8 +68,16 @@ inline static void printHelp(Serial* serial)
|
|||||||
aux set [VAL] : Set PWM value.\n"));
|
aux set [VAL] : Set PWM value.\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int freeRAM()
|
||||||
|
{
|
||||||
|
extern int __heap_start, *__brkval;
|
||||||
|
int v;
|
||||||
|
return (int) &v - (__brkval == 0 ? (int) &__heap_start: (int) __brkval);
|
||||||
|
}
|
||||||
|
|
||||||
void save()
|
void save()
|
||||||
{
|
{
|
||||||
|
EEPROM_write_char(4, resendEnabled);
|
||||||
EEPROM_write_class< SVector<WirelessRelay, MAX_RELAYS> > (RELAY_VECTOR_EEPROM_ADDR, relays);
|
EEPROM_write_class< SVector<WirelessRelay, MAX_RELAYS> > (RELAY_VECTOR_EEPROM_ADDR, relays);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,6 +88,7 @@ void loadRGB(RgbLed* rgbled)
|
|||||||
|
|
||||||
void load()
|
void load()
|
||||||
{
|
{
|
||||||
|
resendEnabled = EEPROM_read_char(4);
|
||||||
EEPROM_read_class< SVector<WirelessRelay, MAX_RELAYS> > (RELAY_VECTOR_EEPROM_ADDR, &relays);
|
EEPROM_read_class< SVector<WirelessRelay, MAX_RELAYS> > (RELAY_VECTOR_EEPROM_ADDR, &relays);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,16 +147,16 @@ void relayDispatch(SVector<WirelessRelay, MAX_RELAYS>* relays, Pwm16b* auxPwm, c
|
|||||||
char* token = strtok(NULL, " \n");
|
char* token = strtok(NULL, " \n");
|
||||||
if( token != NULL)
|
if( token != NULL)
|
||||||
{
|
{
|
||||||
uint8_t selected = strtol(token, nullptr, 10);;
|
uint8_t selected = strtol(token, nullptr, 10);
|
||||||
if (selected < relays->count())
|
if (selected < relays->count())
|
||||||
{
|
{
|
||||||
relays->at(selected).on();
|
relays->at(selected).on();
|
||||||
|
|
||||||
writeRelayState(serial, &relays->at(selected), selected);
|
writeRelayState(serial, &relays->at(selected), selected);
|
||||||
}
|
}
|
||||||
else serial->write(PSTR("No sutch Relay\n"));
|
else serial->write_p(PSTR("No sutch Relay\n"));
|
||||||
}
|
}
|
||||||
else serial->write(PSTR("Usage: relay on [nn]\n"));
|
else serial->write_p(PSTR("Usage: relay on [nn]\n"));
|
||||||
}
|
}
|
||||||
else if( strcmp(token, "off") == 0 )
|
else if( strcmp(token, "off") == 0 )
|
||||||
{
|
{
|
||||||
@ -145,14 +170,27 @@ void relayDispatch(SVector<WirelessRelay, MAX_RELAYS>* relays, Pwm16b* auxPwm, c
|
|||||||
|
|
||||||
writeRelayState(serial, &relays->at(selected), selected);
|
writeRelayState(serial, &relays->at(selected), selected);
|
||||||
}
|
}
|
||||||
else serial->write(PSTR("No sutch Relay\n"));
|
else serial->write_p(PSTR("No sutch Relay\n"));
|
||||||
}
|
}
|
||||||
else serial->write(PSTR("Usage: relay off [nn]\n"));
|
else serial->write_p(PSTR("Usage: relay off [nn]\n"));
|
||||||
|
}
|
||||||
|
else if( strcmp(token, "resend") == 0 )
|
||||||
|
{
|
||||||
|
char* token = strtok(NULL, " \n");
|
||||||
|
serial->write_p(PSTR("Resend every 30 min is "));
|
||||||
|
if( token != NULL )
|
||||||
|
{
|
||||||
|
serial->write_p(PSTR("now "));
|
||||||
|
if(strcmp(token, "on") == 0) resendEnabled = true;
|
||||||
|
else resendEnabled = false;
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
resendEnabled ? serial->write_p(PSTR("enabled.\n")) : serial->write_p(PSTR("disabled.\n")) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
serial->write(token);
|
serial->write(token);
|
||||||
serial->write_p(PSTR(" is not a valid subcommand: relay [add/delete/list/on/off]\n"));
|
serial->write_p(PSTR(" is not a valid subcommand: relay [add/delete/on/off]\n"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,6 +353,12 @@ void serialDispatch(Serial* serial, SVector<WirelessRelay, MAX_RELAYS>* relays,
|
|||||||
}
|
}
|
||||||
serial->putChar('\n');
|
serial->putChar('\n');
|
||||||
}
|
}
|
||||||
|
else if(strcmp(token, "free") == 0)
|
||||||
|
{
|
||||||
|
serial->write_p(PSTR("Free Ram: "));
|
||||||
|
serial->write(freeRAM());
|
||||||
|
serial->write_p(PSTR(" Bytes.\n"));
|
||||||
|
}
|
||||||
else if(strcmp(token, "help") == 0)
|
else if(strcmp(token, "help") == 0)
|
||||||
{
|
{
|
||||||
printHelp(serial);
|
printHelp(serial);
|
||||||
@ -328,7 +372,7 @@ void serialDispatch(Serial* serial, SVector<WirelessRelay, MAX_RELAYS>* relays,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void temperaturePacketRecived(uint32_t data, void* userData)
|
void sensorPacketRecived(uint32_t data, void* userData)
|
||||||
{
|
{
|
||||||
if(!sensorsPaused)
|
if(!sensorsPaused)
|
||||||
{
|
{
|
||||||
@ -353,6 +397,8 @@ void temperaturePacketRecived(uint32_t data, void* userData)
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
wdt_set(WDTO_8S);
|
||||||
|
|
||||||
DDRB = (1 << PB5) | ( 1 << PB1);
|
DDRB = (1 << PB5) | ( 1 << PB1);
|
||||||
DDRD = (1 << PD3) | (1 << PD5)| (1 << PD6);
|
DDRD = (1 << PD3) | (1 << PD5)| (1 << PD6);
|
||||||
|
|
||||||
@ -378,9 +424,9 @@ int main()
|
|||||||
|
|
||||||
setBit(&PCICR, PCIE1, true);
|
setBit(&PCICR, PCIE1, true);
|
||||||
setBit(&PCMSK1, PCINT8, true);
|
setBit(&PCMSK1, PCINT8, true);
|
||||||
W433DataReciver reciver(&PINC, PC0, &TCNT1, &TIFR1, &temperaturePacketRecived, reinterpret_cast<void*>(&serial));
|
W433DataReciver reciver(&PINC, PC0, &TCNT1, &TIFR1, &sensorPacketRecived, reinterpret_cast<void*>(&serial));
|
||||||
|
|
||||||
serial.write_p(PSTR("RGBController v0.9 starting\n"));
|
serial.write_p(PSTR("RGBController v1.0 starting\n"));
|
||||||
|
|
||||||
load();
|
load();
|
||||||
|
|
||||||
@ -422,6 +468,15 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(resendNow)
|
||||||
|
{
|
||||||
|
for(uint16_t i = 0; i < relays.count(); i++)
|
||||||
|
{
|
||||||
|
relays[i].resend();
|
||||||
|
_delay_ms(100);
|
||||||
|
}
|
||||||
|
resendNow = false;
|
||||||
|
}
|
||||||
_delay_ms(2);
|
_delay_ms(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
rgbled.cpp
25
rgbled.cpp
@ -5,9 +5,9 @@ RgbLed::RgbLed( Pwm8b* pwmA, Pwm8b* pwmB ): _pwmA(pwmA), _pwmB(pwmB) {}
|
|||||||
void RgbLed::setSolidColor( const uint8_t r, const uint8_t g, const uint8_t b)
|
void RgbLed::setSolidColor( const uint8_t r, const uint8_t g, const uint8_t b)
|
||||||
{
|
{
|
||||||
_pattern=0;
|
_pattern=0;
|
||||||
_targetR = r;
|
_targetR = applyCal(r, calRed);
|
||||||
_targetG = g;
|
_targetG = applyCal(g, calGreen);
|
||||||
_targetB = b;
|
_targetB = applyCal(b, calBlue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RgbLed::setPreset( const uint8_t preset)
|
void RgbLed::setPreset( const uint8_t preset)
|
||||||
@ -106,6 +106,25 @@ void RgbLed::setFade(bool fade)
|
|||||||
_fade=fade;
|
_fade=fade;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t RgbLed::applyCal(uint16_t value, const uint16_t* cal)
|
||||||
|
{
|
||||||
|
uint16_t calValue;
|
||||||
|
if(value < 128) calValue = cal[0] + ((cal[1] - cal[0])*(value/8))/16;
|
||||||
|
else calValue = cal[1] + ((cal[2] - cal[1])*((value-128)/8))/16;
|
||||||
|
|
||||||
|
return (value*calValue)/1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RgbLed::adjustHeadroom(uint8_t& r, uint8_t& g, uint8_t& b, const uint8_t lumina)
|
||||||
|
{
|
||||||
|
uint8_t postCalLumina = ((uint16_t)r+g+b)/3;
|
||||||
|
while(postCalLumina < lumina && r < 255 && g < 255 && b < 255)
|
||||||
|
{
|
||||||
|
if(r > 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void RgbLed::patternStep()
|
void RgbLed::patternStep()
|
||||||
{
|
{
|
||||||
if(_pattern == 1)
|
if(_pattern == 1)
|
||||||
|
10
rgbled.h
10
rgbled.h
@ -7,9 +7,11 @@ private:
|
|||||||
Pwm8b* _pwmA;
|
Pwm8b* _pwmA;
|
||||||
Pwm8b* _pwmB;
|
Pwm8b* _pwmB;
|
||||||
|
|
||||||
static constexpr uint16_t calBlue[] = {1000, 1000, 1000};
|
static constexpr uint16_t calRed[] = {650, 650, 650};
|
||||||
static constexpr uint16_t calGreen[] = {1000, 1000, 1000};
|
static constexpr uint16_t calGreen[] = {1000, 1000, 1000};
|
||||||
static constexpr uint16_t calRed[] = {1000, 1000, 1000};
|
static constexpr uint16_t calBlue[] = {200, 250, 300};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t _pattern = 0;
|
uint8_t _pattern = 0;
|
||||||
|
|
||||||
@ -26,6 +28,10 @@ private:
|
|||||||
|
|
||||||
void patternStep();
|
void patternStep();
|
||||||
|
|
||||||
|
uint16_t getCalValue();
|
||||||
|
uint8_t applyCal(uint16_t value, const uint16_t* cal);
|
||||||
|
void adjustHeadroom(uint8_t& r, uint8_t& g, uint8_t& b, const uint8_t lumina);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RgbLed( Pwm8b* pwmA, Pwm8b* pwmB );
|
RgbLed( Pwm8b* pwmA, Pwm8b* pwmB );
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user