-
Notifications
You must be signed in to change notification settings - Fork 0
/
bg_krkl.cpp
55 lines (46 loc) · 1.25 KB
/
bg_krkl.cpp
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
#include "bg_krkl.h"
#include <Wire.h>
#include "pca95xx.h"
BG_KRKL::BG_KRKL()
{
this->sa0 = KRKL_SA0;
this->sa1 = KRKL_SA1;
this->resetPin = KRKL_PIN_RESET;
}
BG_KRKL::BG_KRKL(uint8_t sa0, uint8_t sa1, int8_t resetPin)
{
this->sa0 = sa0;
this->sa1 = sa1;
this->resetPin = resetPin;
this->regBuffer = KRKL_MASK_BARGRAPH;
}
void BG_KRKL::rgbCommon(uint8_t rgb, uint8_t offset, uint8_t mask)
{
regBuffer &= ~(mask << 8u);
regBuffer |= ((rgb & KRKL_BIT_R) << offset) << 8u;
regBuffer |= ((rgb & KRKL_BIT_G) << offset) << 8u;
regBuffer |= ((rgb & KRKL_BIT_B) << offset) << 8u;
pca95xx_out(sa1, (uint8_t)(regBuffer >> 8u));
}
void BG_KRKL::init()
{
pca95xx_reset(resetPin);
Wire.begin();
pca95xx_configure(sa0);
pca95xx_configure(sa1);
}
void BG_KRKL::bargraph(uint8_t level)
{
regBuffer &= ~KRKL_MASK_BARGRAPH;
regBuffer |= (~((1u << level) - 1u)) & KRKL_MASK_BARGRAPH;
pca95xx_out(sa0, (uint8_t)(regBuffer));
pca95xx_out(sa1, (uint8_t)(regBuffer >> 8u));
}
void BG_KRKL::rgb1(uint8_t rgb)
{
rgbCommon(rgb, KRKL_OFFSET_RGB1, KRKL_MASK_RGB1);
}
void BG_KRKL::rgb2(uint8_t rgb)
{
rgbCommon(rgb, KRKL_OFFSET_RGB2, KRKL_MASK_RGB2);
}