more configurable led

This commit is contained in:
Conor Patrick 2018-12-03 20:30:35 -05:00
parent e107a9aa86
commit 9b4b18e1a4
6 changed files with 45 additions and 13 deletions

View File

@ -78,7 +78,7 @@ int main(int argc, char * argv[])
while(1)
{
if (millis() - t1 > 100)
if (millis() - t1 > HEARTBEAT_PERIOD)
{
heartbeat();
t1 = millis();

View File

@ -143,7 +143,10 @@ int bootloader_bridge(uint8_t klen, uint8_t * keyh)
void bootloader_heartbeat()
{
static int state = 0;
static uint32_t val = 0x10;
static uint32_t val = (LED_MAX_SCALER - LED_MIN_SCALER)/2;
uint8_t r = (LED_INIT_VALUE >> 16) & 0xff;
uint8_t g = (LED_INIT_VALUE >> 8) & 0xff;
uint8_t b = (LED_INIT_VALUE >> 0) & 0xff;
if (state)
{
@ -154,9 +157,10 @@ void bootloader_heartbeat()
val++;
}
if (val > 30 || val < 1)
if (val > LED_MAX_SCALER || val < LED_MIN_SCALER)
{
state = !state;
}
led_rgb((val * 3)<<8 | (val*10) << 16);
led_rgb(((val * g)<<8) | ((val*r) << 16) | (val*b));
}

View File

@ -22,8 +22,20 @@
#define DISABLE_CTAPHID_WINK
#define DISABLE_CTAPHID_CBOR
#define LED_INIT_VALUE 0x101000
// 0xRRGGBB
#define LED_INIT_VALUE 0x0a0300
#define LED_MAX_SCALER 40
#define LED_MIN_SCALER 1
// # of ms between each change in LED
#define HEARTBEAT_PERIOD 5
// Each LED channel will be multiplied by a integer between LED_MAX_SCALER
// and LED_MIN_SCALER to cause the slow pulse. E.g.
// #define LED_INIT_VALUE 0x301000
// #define LED_MAX_SCALER 30
// #define LED_MIN_SCALER 1
// #define HEARTBEAT_PERIOD 8
// Will pulse from 0x301000 to 0x903000 to 0x301000 ...
// Which will take ~8 * (30)*2 ms
// Button
#define SOLO_BUTTON_PORT GPIOA

View File

@ -107,12 +107,12 @@ int main(int argc, char * argv[])
memset(hidmsg,0,sizeof(hidmsg));
printf1(TAG_GEN,"recv'ing hid msg \n");
printf1(TAG_GEN,"recv'ing hid msg \n");
while(1)
{
if (millis() - t1 > 8)
if (millis() - t1 > HEARTBEAT_PERIOD)
{
bootloader_heartbeat();
t1 = millis();

View File

@ -27,7 +27,20 @@ void hw_init(void);
//#define TEST
//#define TEST_POWER
#define LED_INIT_VALUE 0x001000
// 0xRRGGBB
#define LED_INIT_VALUE 0x000800
#define LED_MAX_SCALER 30
#define LED_MIN_SCALER 1
// # of ms between each change in LED
#define HEARTBEAT_PERIOD 100
// Each LED channel will be multiplied by a integer between LED_MAX_SCALER
// and LED_MIN_SCALER to cause the slow pulse. E.g.
// #define LED_INIT_VALUE 0x301000
// #define LED_MAX_SCALER 30
// #define LED_MIN_SCALER 1
// #define HEARTBEAT_PERIOD 8
// Will pulse from 0x301000 to 0x903000 to 0x301000 ...
// Which will take ~8 * (30)*2 ms
// Button
#define SOLO_BUTTON_PORT GPIOA

View File

@ -149,7 +149,10 @@ void main_loop_delay()
void heartbeat()
{
static int state = 0;
static uint32_t val = (LED_INIT_VALUE >> 8) & 0xff;
static uint32_t val = (LED_MAX_SCALER - LED_MIN_SCALER)/2;
uint8_t r = (LED_INIT_VALUE >> 16) & 0xff;
uint8_t g = (LED_INIT_VALUE >> 8) & 0xff;
uint8_t b = (LED_INIT_VALUE >> 0) & 0xff;
int but = IS_BUTTON_PRESSED();
if (state)
@ -161,13 +164,13 @@ void heartbeat()
val++;
}
if (val > 30 || val < 1)
if (val > LED_MAX_SCALER || val < LED_MIN_SCALER)
{
state = !state;
}
if (but) led_rgb(val * 2);
if (but) led_rgb((val*b));
else
led_rgb((val << 16) | (val*2 << 8));
led_rgb(((val * g)<<8) | ((val*r) << 16) | (val*b));
}
void authenticator_read_state(AuthenticatorState * a)