Added finer brightness control

This commit is contained in:
Markus Koch 2017-04-23 19:12:44 +02:00
parent 7052f556b6
commit 7e48259420
1 changed files with 17 additions and 8 deletions

View File

@ -45,6 +45,12 @@ const uint8_t PROGMEM gamma8[] = {
177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213, 177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 }; 215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };
const uint8_t PROGMEM gammaBright[] = {
0, 1, 2, 3, 6, 10, 14,
18, 26, 31, 38, 46, 54, 66,
76, 89, 104, 128, 150, 180, 240,
250, 280, 340};
struct cRGB led[LEDS_PER_SLOT]; struct cRGB led[LEDS_PER_SLOT];
USB_PUBLIC uchar usbFunctionSetup(uchar data[8]) USB_PUBLIC uchar usbFunctionSetup(uchar data[8])
@ -119,7 +125,8 @@ void keyboard(void) {
enum enum_state state = IDLE; enum enum_state state = IDLE;
enum enum_state next_state = IDLE; enum enum_state next_state = IDLE;
uint8_t i; uint8_t i;
uint8_t factor = 1; uint16_t factor = 1;
uint8_t brightness = 1;
uint8_t key = 0; uint8_t key = 0;
uint16_t loadAddress; uint16_t loadAddress;
uint16_t loadCount; uint16_t loadCount;
@ -149,7 +156,7 @@ void keyboard(void) {
LED_PORT &= ~(1 << LED_RED); LED_PORT &= ~(1 << LED_RED);
LED_PORT |= (1 << LED_GREEN); LED_PORT |= (1 << LED_GREEN);
factor = eeprom_read_byte(IEE_ADDR_DEFAULT_BRIGHTNESS); brightness = eeprom_read_byte(IEE_ADDR_DEFAULT_BRIGHTNESS);
change_block = eeprom_read_byte(IEE_ADDR_DEFAULT_BLOCK); change_block = eeprom_read_byte(IEE_ADDR_DEFAULT_BLOCK);
for (;;) { /* main event loop */ for (;;) { /* main event loop */
@ -184,15 +191,15 @@ void keyboard(void) {
if (key > 12) { /* Special key */ if (key > 12) { /* Special key */
switch (key) { switch (key) {
case KEY_BRIGHTNESS_UP: case KEY_BRIGHTNESS_UP:
factor = (factor <= 1 ? 1 : factor - 1); brightness = (brightness <= 0 ? 0 : brightness - 1);
break; break;
case KEY_BRIGHTNESS_DOWN: case KEY_BRIGHTNESS_DOWN:
factor = (factor > 30 ? 30 : factor + 1); brightness = (brightness >= 21 ? 21 : brightness + 1);
break; break;
case KEY_SF_1: case KEY_SF_1:
break; break;
case KEY_SF_2: /* Save current as default */ case KEY_SF_2: /* Save current as default */
eeprom_write_byte(IEE_ADDR_DEFAULT_BRIGHTNESS, factor); eeprom_write_byte(IEE_ADDR_DEFAULT_BRIGHTNESS, brightness);
eeprom_write_byte(IEE_ADDR_DEFAULT_BLOCK, current_block); eeprom_write_byte(IEE_ADDR_DEFAULT_BLOCK, current_block);
break; break;
default: default:
@ -214,15 +221,17 @@ void keyboard(void) {
loadCount = LEDS_PER_SLOT; loadCount = LEDS_PER_SLOT;
state = LOAD; state = LOAD;
case LOAD: case LOAD:
factor = pgm_read_byte(&gammaBright[brightness]);
factor = 256 + factor * 25;
led[LEDS_PER_SLOT - loadCount].r = EEReadByte(loadAddress++); led[LEDS_PER_SLOT - loadCount].r = EEReadByte(loadAddress++);
//led[LEDS_PER_SLOT - loadCount].r = (int)pgm_read_byte(&gamma8[led[LEDS_PER_SLOT - loadCount].r]); //led[LEDS_PER_SLOT - loadCount].r = (int)pgm_read_byte(&gamma8[led[LEDS_PER_SLOT - loadCount].r]);
led[LEDS_PER_SLOT - loadCount].r = led[LEDS_PER_SLOT - loadCount].r / factor; led[LEDS_PER_SLOT - loadCount].r = (uint8_t) ((uint16_t) ((uint16_t) ((uint16_t) (led[LEDS_PER_SLOT - loadCount].r) << 8) / factor));
led[LEDS_PER_SLOT - loadCount].g = EEReadByte(loadAddress++); led[LEDS_PER_SLOT - loadCount].g = EEReadByte(loadAddress++);
////led[LEDS_PER_SLOT - loadCount].g = (int)pgm_read_byte(&gamma8[led[LEDS_PER_SLOT - loadCount].g]); ////led[LEDS_PER_SLOT - loadCount].g = (int)pgm_read_byte(&gamma8[led[LEDS_PER_SLOT - loadCount].g]);
led[LEDS_PER_SLOT - loadCount].g = led[LEDS_PER_SLOT - loadCount].g / factor; led[LEDS_PER_SLOT - loadCount].g = (uint8_t) ((uint16_t) ((uint16_t) ((uint16_t) (led[LEDS_PER_SLOT - loadCount].g) << 8) / factor));
led[LEDS_PER_SLOT - loadCount].b = EEReadByte(loadAddress++); led[LEDS_PER_SLOT - loadCount].b = EEReadByte(loadAddress++);
//led[LEDS_PER_SLOT - loadCount].b = (int)pgm_read_byte(&gamma8[led[LEDS_PER_SLOT - loadCount].b]); //led[LEDS_PER_SLOT - loadCount].b = (int)pgm_read_byte(&gamma8[led[LEDS_PER_SLOT - loadCount].b]);
led[LEDS_PER_SLOT - loadCount].b = led[LEDS_PER_SLOT - loadCount].b / factor; led[LEDS_PER_SLOT - loadCount].b = (uint8_t) ((uint16_t) ((uint16_t) ((uint16_t) (led[LEDS_PER_SLOT - loadCount].b) << 8) / factor));
if (!--loadCount) { if (!--loadCount) {
state = RENDER; state = RENDER;
loadCount = LEDS_PER_SLOT; loadCount = LEDS_PER_SLOT;