Commit 295b7dbd authored by natalie's avatar natalie 💜
Browse files

Revamp LED brightness

parent 57887e32
......@@ -16,7 +16,7 @@ static const char* TAG = "LedDrv";
volatile uint8_t led_pwm[16];
volatile uint8_t LedDrv_States[16];
volatile uint8_t LedDrv_States_ULatch[3];
volatile uint8_t LedDrv_Brightness = 0x40;
volatile uint8_t LedDrv_Brightness = 0x00;
const uint8_t led_curve_lut[256] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
......@@ -37,6 +37,8 @@ const uint8_t led_curve_lut[256] = {
0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF
};
const uint8_t global_bright_lut[11] = {0, 0x01, 0x05, 0x0b, 0x17, 0x2c, 0x4f, 0x7c, 0xaa, 0xce, 0xff};
#if defined HWVER_PORTABLE
const uint8_t led_channel_assignment[] = {
//FM 1-6
......@@ -130,6 +132,19 @@ bool LedDrv_Update() {
return ret;
}
void LedDrv_UpdateBrightness() {
assert(LedDrv_Brightness < sizeof(global_bright_lut));
if (!I2cMgr_Seize(false, pdMS_TO_TICKS(1000))) {
ESP_LOGE(TAG, "Couldn't seize bus !!");
return;
}
LedDrv_WriteRegister(0, 0x0a, global_bright_lut[LedDrv_Brightness]);
LedDrv_WriteRegister(1, 0x0a, global_bright_lut[LedDrv_Brightness]);
I2cMgr_Release(false);
}
bool LedDrv_Setup() {
ESP_LOGI(TAG, "Setting up");
......@@ -157,10 +172,6 @@ bool LedDrv_Setup() {
I2cMgr_Release(false);
return false;
}
if (!LedDrv_WriteRegister(i, 0x0a, LedDrv_Brightness)) { //GRPPWM
I2cMgr_Release(false);
return false;
}
if (!LedDrv_WriteRegister(i, 0x0c, 0xff)) { //LEDOUT0
I2cMgr_Release(false);
return false;
......@@ -178,18 +189,8 @@ bool LedDrv_Setup() {
I2cMgr_Release(false);
LedDrv_UpdateBrightness();
ESP_LOGI(TAG, "OK !!");
return true;
}
void LedDrv_UpdateBrightness() {
if (!I2cMgr_Seize(false, pdMS_TO_TICKS(1000))) {
ESP_LOGE(TAG, "Couldn't seize bus !!");
return;
}
LedDrv_WriteRegister(0, 0x0a, LedDrv_Brightness);
LedDrv_WriteRegister(1, 0x0a, LedDrv_Brightness);
I2cMgr_Release(false);
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@
extern volatile uint8_t LedDrv_States[16];
extern volatile uint8_t LedDrv_Brightness;
extern volatile uint8_t LedDrv_States_ULatch[3];
extern const uint8_t global_bright_lut[17];
bool LedDrv_Setup();
bool LedDrv_Update();
......
......@@ -40,7 +40,7 @@ static void opts_pitchupdate() {
static bool loaded[OPTION_COUNT];
//last used: 14
//last used: 15
const option_t Options[OPTION_COUNT] = {
{
0x0001,
......@@ -118,14 +118,14 @@ const option_t Options[OPTION_COUNT] = {
opts_mutingupdate
},
{
0x0004,
0x0015,
"LED brightness",
"Overall LED brightness",
OPTION_CATEGORY_LEDS,
OPTION_TYPE_NUMERIC,
OPTION_SUBTYPE_BRIGHTNESS,
&LedDrv_Brightness, //
0x40,
&LedDrv_Brightness,
5,
LedDrv_UpdateBrightness,
LedDrv_UpdateBrightness
},
......@@ -416,7 +416,26 @@ static uint8_t loadoptionsfile(const char *filename) {
}
}
if (!found) {
ESP_LOGW(TAG, "skipping unknown option uid %d", uid);
if (uid == 0x0004) { //old led brightness, new is 0015
//find the nearest new brightness setting to the old one
uint8_t newval = 0;
for (uint8_t j=0;j<sizeof(global_bright_lut);j++) {
if (global_bright_lut[j] > v) break;
newval = j;
}
ESP_LOGW(TAG, "Remapping old LED brightness %d to new value %d (%d)", v, newval, global_bright_lut[newval]);
for (uint8_t j=0;j<OPTION_COUNT;j++) {
if (Options[j].uid == 0x0015) {
if (Options[j].var != NULL) *(volatile uint8_t*)Options[j].var = newval;
if (Options[j].cb_initial != NULL) Options[j].cb_initial();
loaded[j] = true;
break;
}
}
OptionsMgr_Touch();
} else {
ESP_LOGW(TAG, "skipping unknown option uid %d", uid);
}
}
}
fclose(f);
......
......@@ -63,9 +63,17 @@ static void displayvalue(char *buf, bool def) {
case OPTION_TYPE_NUMERIC:
switch (Options[Options_OptId].subtype) {
case OPTION_SUBTYPE_NONE:
case OPTION_SUBTYPE_BRIGHTNESS: //this one will go away as soon as the LUT exists
sprintf(buf, "%d", val);
break;
case OPTION_SUBTYPE_BRIGHTNESS:
if (val == 0) {
strcpy(buf, "Off");
} else if (val == 10) {
strcpy(buf, "Max");
} else {
sprintf(buf, "%d", val);
}
break;
case OPTION_SUBTYPE_LOOPS:
if (val == 255) {
strcpy(buf, "Infinite");
......@@ -215,7 +223,6 @@ static void changevalue(bool inc) {
case OPTION_TYPE_NUMERIC:
switch (Options[Options_OptId].subtype) {
case OPTION_SUBTYPE_NONE:
case OPTION_SUBTYPE_BRIGHTNESS:
if (inc) {
if (*var < 255) {
*var += 1;
......@@ -226,6 +233,17 @@ static void changevalue(bool inc) {
}
}
break;
case OPTION_SUBTYPE_BRIGHTNESS:
if (inc) {
if (*var < 10) {
*var += 1;
}
} else {
if (*var > 0) {
*var -= 1;
}
}
break;
case OPTION_SUBTYPE_FADELENGTH:
if (inc) {
if (*var < 10) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment