Add Pico 2 support
This commit is contained in:
+7
-23
@@ -1,4 +1,5 @@
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/multicore.h"
|
||||
@@ -13,7 +14,8 @@
|
||||
|
||||
static absolute_time_t lastSend;
|
||||
static absolute_time_t lastRead;
|
||||
static uint16_t adc_value = 0;
|
||||
//static uint16_t adc_value = 0;
|
||||
static uint8_t adc_value = 0;
|
||||
static bool mute = false;
|
||||
|
||||
static unsigned char buf[BUF_SIZE];
|
||||
@@ -165,7 +167,7 @@ static struct key key_list[NUM_KEYS] =
|
||||
void get_light() {
|
||||
// get ADC reading from LDR every 500ms
|
||||
if ( absolute_time_diff_us(lastRead, get_absolute_time()) >= 500000) {
|
||||
adc_value = adc_read();
|
||||
adc_value = log2(adc_read());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,24 +178,6 @@ void rgb_task(uint8_t dev_addr) {
|
||||
// updated color info (packets_sent>0) and continue to send the next
|
||||
// packet if so at a rate of one packet every 20ms
|
||||
// otherwise, wait 0.5s before sending the next set of color packets
|
||||
|
||||
/*if (packets_sent>0) {
|
||||
if ( absolute_time_diff_us(lastSend, get_absolute_time()) >= 20000) {
|
||||
if (backlight) {
|
||||
send_color(dev_addr, 0x20, 0x20, 0x20);
|
||||
// send a dim white color (#202020) for all keys
|
||||
} else {
|
||||
send_color(dev_addr, 0x00, 0x00, 0x00);
|
||||
// turn off all lighting by sending (#000000) for all keys
|
||||
}
|
||||
lastSend = get_absolute_time();
|
||||
}
|
||||
} else {
|
||||
if ( absolute_time_diff_us(lastSend, get_absolute_time()) >= 500000) {
|
||||
send_initial(dev_addr);
|
||||
lastSend = get_absolute_time();
|
||||
}
|
||||
}*/
|
||||
if ( absolute_time_diff_us(lastSend, get_absolute_time()) >= delay) {
|
||||
if ( packets_sent == 0) {
|
||||
// first packet is initialization packet
|
||||
@@ -227,9 +211,9 @@ static void send_color(uint8_t dev_addr) {
|
||||
buf[buf_idx] = 0x81;
|
||||
switch (key_list[key_idx].mode) {
|
||||
case RGB_MODE_ADAPTIVE: // adjust brightness based on LDR ADC reading
|
||||
buf[buf_idx+1] = (ADC_MAX-adc_value)*key_list[key_idx].red/ADC_MAX;
|
||||
buf[buf_idx+2] = (ADC_MAX-adc_value)*key_list[key_idx].green/ADC_MAX;
|
||||
buf[buf_idx+3] = (ADC_MAX-adc_value)*key_list[key_idx].blue/ADC_MAX;
|
||||
buf[buf_idx+1] = (ADC_MAX_LOG2-adc_value)*key_list[key_idx].red/ADC_MAX_LOG2;
|
||||
buf[buf_idx+2] = (ADC_MAX_LOG2-adc_value)*key_list[key_idx].green/ADC_MAX_LOG2;
|
||||
buf[buf_idx+3] = (ADC_MAX_LOG2-adc_value)*key_list[key_idx].blue/ADC_MAX_LOG2;
|
||||
break;
|
||||
case RGB_MODE_MUTE:
|
||||
if (mute) {
|
||||
|
||||
Reference in New Issue
Block a user