Compare commits
2 Commits
v0.1.0
...
1414d915a4
| Author | SHA1 | Date | |
|---|---|---|---|
|
1414d915a4
|
|||
|
dc961ce480
|
+4
-1
@@ -49,7 +49,10 @@ target_compile_options(${PROJECT} PRIVATE ) #-Wall -Wextra
|
|||||||
target_compile_definitions(${PROJECT} PRIVATE PIO_USB_USE_TINYUSB)
|
target_compile_definitions(${PROJECT} PRIVATE PIO_USB_USE_TINYUSB)
|
||||||
|
|
||||||
# needed so tinyusb can find tusb_config.h
|
# 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
|
target_link_libraries(${PROJECT} PRIVATE
|
||||||
pico_lwip
|
pico_lwip
|
||||||
|
|||||||
@@ -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];
|
||||||
@@ -29,7 +30,6 @@ static void send_color(uint8_t dev_addr);
|
|||||||
static void send_initial(uint8_t dev_addr);
|
static void send_initial(uint8_t dev_addr);
|
||||||
static struct key * find_key(char * name);
|
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(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] =
|
static struct key key_list[NUM_KEYS] =
|
||||||
{
|
{
|
||||||
@@ -144,9 +144,8 @@ 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 above threshold, set backlight to off
|
|
||||||
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,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) {
|
||||||
@@ -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
|
// parse color request from webpage and update keyboard colors
|
||||||
void parse_colors(char * data, uint16_t len) {
|
void parse_colors(char * data, uint16_t len) {
|
||||||
(void) len;
|
(void) len;
|
||||||
@@ -341,7 +326,7 @@ void parse_colors(char * data, uint16_t len) {
|
|||||||
if (token != NULL) {
|
if (token != NULL) {
|
||||||
// first string is the RGB color code
|
// first string is the RGB color code
|
||||||
uint8_t red, green, blue;
|
uint8_t red, green, blue;
|
||||||
sscanf(token, "%02x%02x%02x", &red, &green, &blue);
|
sscanf(token, "%2x%2x%2x", &red, &green, &blue);
|
||||||
|
|
||||||
token = strtok(NULL, ",");
|
token = strtok(NULL, ",");
|
||||||
if (token != NULL) {
|
if (token != NULL) {
|
||||||
|
|||||||
@@ -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
@@ -96,10 +96,6 @@
|
|||||||
|
|
||||||
#define CFG_TUD_HID_EP_BUFSIZE 64
|
#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
|
// HOST CONFIGURATION
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 89 KiB |
+1
-5
@@ -73,6 +73,7 @@ void usb_device_main(void) {
|
|||||||
device_state = DEVICE_INACTIVE;
|
device_state = DEVICE_INACTIVE;
|
||||||
usb_device_init();
|
usb_device_init();
|
||||||
|
|
||||||
|
// start the web server on USB
|
||||||
usb_server_init();
|
usb_server_init();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -252,8 +253,3 @@ void cdc_print_hex(uint8_t const* msg, uint16_t msg_len) {
|
|||||||
}
|
}
|
||||||
tud_cdc_write_str("\n");
|
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);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ extern device_state_t device_state;
|
|||||||
|
|
||||||
void usb_device_main(void);
|
void usb_device_main(void);
|
||||||
void cdc_print_hex(uint8_t const* msg, uint16_t msg_len);
|
void cdc_print_hex(uint8_t const* msg, uint16_t msg_len);
|
||||||
void cdc_print(uint8_t const* msg, uint16_t msg_len);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -251,7 +251,7 @@ static void report_desc_init(struct report_desc *descriptor) {
|
|||||||
descriptor->next = NULL;
|
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) {
|
static void report_desc_free(struct report_desc *descriptor) {
|
||||||
if (descriptor != NULL) {
|
if (descriptor != NULL) {
|
||||||
if (descriptors == descriptor) {
|
if (descriptors == descriptor) {
|
||||||
|
|||||||
Reference in New Issue
Block a user