-
Notifications
You must be signed in to change notification settings - Fork 0
/
rgb.h
64 lines (57 loc) · 1.25 KB
/
rgb.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef RGB_H
#define RGB_H
#include <Arduino.h>
#include "gammaramp.h"
#include "batterymonitor.h"
/**
* Adjusts the PWM width based on battery voltage
*
* TODO: Implement some actual adjustment curve
*/
uint8_t pwmlimit(uint8_t pwm)
{
// TODO: precalculate the limit factor (possibly in batterymonitor.h)
int foo = batterymonitor.bat_mv;
return pwm - (pwm >> 2);
}
/**
* Generic setter for 3 consequtve PWM pins
*
* TODO: Apply gamma correction
*/
void setRGB(uint8_t startpin, uint8_t r, uint8_t g, uint8_t b)
{
byte rgamma = gamma256to256(r);
byte bgamma = gamma256to256(b);
byte ggamma = gamma256to256(g);
analogWrite(startpin, pwmlimit(rgamma));
analogWrite(startpin+1, pwmlimit(ggamma));
analogWrite(startpin+2, pwmlimit(bgamma));
}
/**
* Set the first set of built-in drivers
*/
inline void setRGB0(uint8_t r, uint8_t g, uint8_t b)
{
setRGB(16, r,g,b);
}
/**
* Set the second set of built-in drivers
*/
inline void setRGB1(uint8_t r, uint8_t g, uint8_t b)
{
setRGB(19, r,g,b);
}
inline void setStdRGB(uint8_t ledno, uint8_t r, uint8_t g, uint8_t b)
{
switch(ledno)
{
case 0x0:
setRGB0(r,g,b);
break;
case 0x1:
setRGB1(r,g,b);
break;
}
}
#endif