minor UI and adaptive lighting tweaks
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
#include "pico/multicore.h"
|
#include "pico/multicore.h"
|
||||||
@@ -13,7 +14,7 @@
|
|||||||
|
|
||||||
static absolute_time_t lastSend;
|
static absolute_time_t lastSend;
|
||||||
static absolute_time_t lastRead;
|
static absolute_time_t lastRead;
|
||||||
static uint16_t adc_value = 0;
|
static uint8_t adc_value = 0;
|
||||||
static bool mute = false;
|
static bool mute = false;
|
||||||
|
|
||||||
static unsigned char buf[BUF_SIZE];
|
static unsigned char buf[BUF_SIZE];
|
||||||
@@ -144,7 +145,7 @@ static struct key key_list[NUM_KEYS] =
|
|||||||
void get_light() {
|
void get_light() {
|
||||||
// get ADC reading from LDR every 500ms
|
// get ADC reading from LDR every 500ms
|
||||||
if ( absolute_time_diff_us(lastRead, get_absolute_time()) >= 500000) {
|
if ( absolute_time_diff_us(lastRead, get_absolute_time()) >= 500000) {
|
||||||
adc_value = adc_read();
|
adc_value = log2(adc_read());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,9 +187,9 @@ static void send_color(uint8_t dev_addr) {
|
|||||||
buf[buf_idx+5] = 0x0A;
|
buf[buf_idx+5] = 0x0A;
|
||||||
switch (key_list[key_idx].mode) {
|
switch (key_list[key_idx].mode) {
|
||||||
case RGB_MODE_ADAPTIVE: // adjust brightness based on LDR ADC reading
|
case RGB_MODE_ADAPTIVE: // adjust brightness based on LDR ADC reading
|
||||||
buf[buf_idx+6] = (ADC_MAX-adc_value)*key_list[key_idx].red/ADC_MAX;
|
buf[buf_idx+6] = (ADC_MAX_LOG2-adc_value)*key_list[key_idx].red/ADC_MAX_LOG2;
|
||||||
buf[buf_idx+7] = (ADC_MAX-adc_value)*key_list[key_idx].green/ADC_MAX;
|
buf[buf_idx+7] = (ADC_MAX_LOG2-adc_value)*key_list[key_idx].green/ADC_MAX_LOG2;
|
||||||
buf[buf_idx+8] = (ADC_MAX-adc_value)*key_list[key_idx].blue/ADC_MAX;
|
buf[buf_idx+8] = (ADC_MAX_LOG2-adc_value)*key_list[key_idx].blue/ADC_MAX_LOG2;
|
||||||
break;
|
break;
|
||||||
case RGB_MODE_MUTE:
|
case RGB_MODE_MUTE:
|
||||||
if (mute) {
|
if (mute) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#define NUM_KEYS 107
|
#define NUM_KEYS 107
|
||||||
#define BUF_SIZE 64
|
#define BUF_SIZE 64
|
||||||
#define ADC_MAX 4096
|
#define ADC_MAX 4096
|
||||||
|
#define ADC_MAX_LOG2 log2(ADC_MAX)
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
RGG_MODE_INVALID=0,
|
RGG_MODE_INVALID=0,
|
||||||
|
|||||||
+12
-6
@@ -142,7 +142,7 @@ const keyboard_list = [
|
|||||||
{id: "Numpad7", label: "Home<br>7"},
|
{id: "Numpad7", label: "Home<br>7"},
|
||||||
{id: "Numpad8", label: "Up<br>8"},
|
{id: "Numpad8", label: "Up<br>8"},
|
||||||
{id: "Numpad9", label: "PgUp<br>9"},
|
{id: "Numpad9", label: "PgUp<br>9"},
|
||||||
{id: "NumpadAdd", label: "+", height: 2}
|
{id: "NumpadAdd", label: "+", height: 2.2}
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
{id: "CapsLock", label: "Caps<br>Lock", width: 2},
|
{id: "CapsLock", label: "Caps<br>Lock", width: 2},
|
||||||
@@ -157,8 +157,8 @@ const keyboard_list = [
|
|||||||
{id: "KeyL", label: "L"},
|
{id: "KeyL", label: "L"},
|
||||||
{id: "Semicolon", label: ":<br>;"},
|
{id: "Semicolon", label: ":<br>;"},
|
||||||
{id: "Quote", label: "\"<br>\'"},
|
{id: "Quote", label: "\"<br>\'"},
|
||||||
{id: "Enter", label: "Enter", width: 2.3},
|
{id: "Enter", label: "Enter", width: 2.2},
|
||||||
{id: "", label: "", width: 3.4},
|
{id: "", label: "", width: 3.55},
|
||||||
{id: "Numpad4", label: "Left<br>4"},
|
{id: "Numpad4", label: "Left<br>4"},
|
||||||
{id: "Numpad5", label: "5"},
|
{id: "Numpad5", label: "5"},
|
||||||
{id: "Numpad6", label: "Right<br>6"}
|
{id: "Numpad6", label: "Right<br>6"}
|
||||||
@@ -182,7 +182,7 @@ const keyboard_list = [
|
|||||||
{id: "Numpad1", label: "End<br>1"},
|
{id: "Numpad1", label: "End<br>1"},
|
||||||
{id: "Numpad2", label: "Down<br>2"},
|
{id: "Numpad2", label: "Down<br>2"},
|
||||||
{id: "Numpad3", label: "PgDn<br>3"},
|
{id: "Numpad3", label: "PgDn<br>3"},
|
||||||
{id: "NumpadEnter", label: "Enter", height: 2}
|
{id: "NumpadEnter", label: "Enter", height: 2.2}
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
{id: "ControlLeft", label: "Control", width: 2},
|
{id: "ControlLeft", label: "Control", width: 2},
|
||||||
@@ -192,11 +192,11 @@ const keyboard_list = [
|
|||||||
{id: "AltRight", label: "Alt", width: 2},
|
{id: "AltRight", label: "Alt", width: 2},
|
||||||
{id: "MetaRight", label: "FN"},
|
{id: "MetaRight", label: "FN"},
|
||||||
{id: "ContextMenu", label:"Menu"},
|
{id: "ContextMenu", label:"Menu"},
|
||||||
{id: "ControlRight", label: "Control", width: 1.7},
|
{id: "ControlRight", label: "Control", width: 1.6},
|
||||||
{id: "ArrowLeft", label: "Left"},
|
{id: "ArrowLeft", label: "Left"},
|
||||||
{id: "ArrowDown", label: "Down"},
|
{id: "ArrowDown", label: "Down"},
|
||||||
{id: "ArrowRight", label: "Right"},
|
{id: "ArrowRight", label: "Right"},
|
||||||
{id: "Numpad0", label: "Ins<br>0", width: 2},
|
{id: "Numpad0", label: "Ins<br>0", width: 2.2},
|
||||||
{id: "NumpadDecimal", label: "Del<br>."}
|
{id: "NumpadDecimal", label: "Del<br>."}
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@@ -339,6 +339,12 @@ function updateColor() {
|
|||||||
channel.value = 255;
|
channel.value = 255;
|
||||||
} else if (parseInt(channel.value) < 0) {
|
} else if (parseInt(channel.value) < 0) {
|
||||||
channel.value = 0;
|
channel.value = 0;
|
||||||
|
} else if ( isNan(parseInt(channel.value)) ) {
|
||||||
|
// non-numerical value entered, set to default
|
||||||
|
channel.value = 128;
|
||||||
|
} else {
|
||||||
|
// make sure that value in box reflects what parser thinks
|
||||||
|
channel.value = parseInt(channel.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+715
-690
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user