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

@@ -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)