Compare commits

2 Commits

Author SHA1 Message Date
kenji 1414d915a4 minor UI and adaptive lighting tweaks 2025-08-28 21:46:44 -04:00
kenji dc961ce480 cleanup 2025-08-27 08:13:20 -04:00
10 changed files with 741 additions and 730 deletions
+4 -1
View File
@@ -49,7 +49,10 @@ target_compile_options(${PROJECT} PRIVATE ) #-Wall -Wextra
target_compile_definitions(${PROJECT} PRIVATE PIO_USB_USE_TINYUSB)
# needed so tinyusb can find tusb_config.h
target_include_directories(${PROJECT} PRIVATE ${CMAKE_CURRENT_LIST_DIR} ${TUSB_NETWORKING_PATH})
target_include_directories(${PROJECT} PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${TUSB_NETWORKING_PATH}
)
target_link_libraries(${PROJECT} PRIVATE
pico_lwip
+7 -22
View File
@@ -1,4 +1,5 @@
#include <stdlib.h>
#include <math.h>
#include "pico/stdlib.h"
#include "pico/multicore.h"
@@ -13,7 +14,7 @@
static absolute_time_t lastSend;
static absolute_time_t lastRead;
static uint16_t adc_value = 0;
static uint8_t adc_value = 0;
static bool mute = false;
static unsigned char buf[BUF_SIZE];
@@ -29,7 +30,6 @@ static void send_color(uint8_t dev_addr);
static void send_initial(uint8_t dev_addr);
static struct key * find_key(char * name);
static void set_color(char * name, uint8_t red, uint8_t green, uint8_t blue, uint8_t mode);
static void set_color_all(uint8_t red, uint8_t green, uint8_t blue, uint8_t mode);
static struct key key_list[NUM_KEYS] =
{
@@ -144,9 +144,8 @@ static struct key key_list[NUM_KEYS] =
void get_light() {
// get ADC reading from LDR every 500ms
// if above threshold, set backlight to off
if ( absolute_time_diff_us(lastRead, get_absolute_time()) >= 500000) {
adc_value = adc_read();
adc_value = log2(adc_read());
}
}
@@ -188,9 +187,9 @@ static void send_color(uint8_t dev_addr) {
buf[buf_idx+5] = 0x0A;
switch (key_list[key_idx].mode) {
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+7] = (ADC_MAX-adc_value)*key_list[key_idx].green/ADC_MAX;
buf[buf_idx+8] = (ADC_MAX-adc_value)*key_list[key_idx].blue/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_LOG2-adc_value)*key_list[key_idx].green/ADC_MAX_LOG2;
buf[buf_idx+8] = (ADC_MAX_LOG2-adc_value)*key_list[key_idx].blue/ADC_MAX_LOG2;
break;
case RGB_MODE_MUTE:
if (mute) {
@@ -316,20 +315,6 @@ static void set_color(char * name, uint8_t red, uint8_t green, uint8_t blue, uin
}
}
// set RGB color for all keys
static void set_color_all(uint8_t red, uint8_t green, uint8_t blue, uint8_t mode) {
for (uint8_t i=0; i<NUM_KEYS; i++) {
key_list[i].red = red;
key_list[i].green = green;
key_list[i].blue = blue;
// don't change modes on MUTE only to preserve toggling behavior
// user can set manually from GUI if desired
if (key_list[i].val != KEY_MUTE) {
key_list[i].mode = mode;
}
}
}
// parse color request from webpage and update keyboard colors
void parse_colors(char * data, uint16_t len) {
(void) len;
@@ -341,7 +326,7 @@ void parse_colors(char * data, uint16_t len) {
if (token != NULL) {
// first string is the RGB color code
uint8_t red, green, blue;
sscanf(token, "%02x%02x%02x", &red, &green, &blue);
sscanf(token, "%2x%2x%2x", &red, &green, &blue);
token = strtok(NULL, ",");
if (token != NULL) {
+1
View File
@@ -11,6 +11,7 @@
#define NUM_KEYS 107
#define BUF_SIZE 64
#define ADC_MAX 4096
#define ADC_MAX_LOG2 log2(ADC_MAX)
enum {
RGG_MODE_INVALID=0,
+12 -6
View File
@@ -142,7 +142,7 @@ const keyboard_list = [
{id: "Numpad7", label: "Home<br>7"},
{id: "Numpad8", label: "Up<br>8"},
{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},
@@ -157,8 +157,8 @@ const keyboard_list = [
{id: "KeyL", label: "L"},
{id: "Semicolon", label: ":<br>;"},
{id: "Quote", label: "\"<br>\'"},
{id: "Enter", label: "Enter", width: 2.3},
{id: "", label: "", width: 3.4},
{id: "Enter", label: "Enter", width: 2.2},
{id: "", label: "", width: 3.55},
{id: "Numpad4", label: "Left<br>4"},
{id: "Numpad5", label: "5"},
{id: "Numpad6", label: "Right<br>6"}
@@ -182,7 +182,7 @@ const keyboard_list = [
{id: "Numpad1", label: "End<br>1"},
{id: "Numpad2", label: "Down<br>2"},
{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},
@@ -192,11 +192,11 @@ const keyboard_list = [
{id: "AltRight", label: "Alt", width: 2},
{id: "MetaRight", label: "FN"},
{id: "ContextMenu", label:"Menu"},
{id: "ControlRight", label: "Control", width: 1.7},
{id: "ControlRight", label: "Control", width: 1.6},
{id: "ArrowLeft", label: "Left"},
{id: "ArrowDown", label: "Down"},
{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>."}
],
];
@@ -339,6 +339,12 @@ function updateColor() {
channel.value = 255;
} else if (parseInt(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
View File
File diff suppressed because it is too large Load Diff
-4
View File
@@ -96,10 +96,6 @@
#define CFG_TUD_HID_EP_BUFSIZE 64
// NCM settings
//#define CFG_TUD_NCM_OUT_MAX_DATAGRAMS_PER_NTB 1
//#define CFG_TUD_NCM_IN_MAX_DATAGRAMS_PER_NTB 1
//--------------------------------------------------------------------
// HOST CONFIGURATION
//--------------------------------------------------------------------
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 89 KiB

+1 -5
View File
@@ -73,6 +73,7 @@ void usb_device_main(void) {
device_state = DEVICE_INACTIVE;
usb_device_init();
// start the web server on USB
usb_server_init();
while (true) {
@@ -252,8 +253,3 @@ void cdc_print_hex(uint8_t const* msg, uint16_t msg_len) {
}
tud_cdc_write_str("\n");
}
// print message to CDC
void cdc_print(uint8_t const* msg, uint16_t msg_len) {
tud_cdc_write(msg, msg_len);
}
-1
View File
@@ -37,7 +37,6 @@ extern device_state_t device_state;
void usb_device_main(void);
void cdc_print_hex(uint8_t const* msg, uint16_t msg_len);
void cdc_print(uint8_t const* msg, uint16_t msg_len);
#endif
+1 -1
View File
@@ -251,7 +251,7 @@ static void report_desc_init(struct report_desc *descriptor) {
descriptor->next = NULL;
}
// free memory and teardown usb->bt report ID mappings for report descriptor struct
// free memory for report descriptor struct
static void report_desc_free(struct report_desc *descriptor) {
if (descriptor != NULL) {
if (descriptors == descriptor) {