-
Notifications
You must be signed in to change notification settings - Fork 0
/
activity.cpp
91 lines (76 loc) · 1.53 KB
/
activity.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#include "board.h"
#include "activity.h"
#if NEOPIXEL_ENABLE
#ifdef PIN_NEOPIXEL
Adafruit_NeoPixel strip (NB_NEOPIXEL, PIN_NEOPIXEL, NEO_GRB );
static uint16_t _history[NB_NEOPIXEL *2];
#endif
#endif
void activity_begin (void)
{
#if NEOPIXEL_ENABLE
#ifdef PIN_NEOPIXEL
strip.begin();
for (int i = 0; i < NB_NEOPIXEL; i++) {
strip.setPixelColor(i, 0, 0, 255);
}
strip.show();
#endif
#endif
}
static uint16_t color = 0;
static uint32_t lastvalue = 0;
void activity_event (uint32_t value)
{
/*
if (value > lastvalue && color < 32)
color++;
if (value < lastvalue && color > 1)
color--;
activity_add_history (value & 0xff);
*/
lastvalue = value;
}
void activity_process (void)
{
if (lastvalue != 0)
{
if (color < lastvalue)
color++;
else if (color > lastvalue && color > 1)
color--;
}
}
void activity_add_history (uint8_t value)
{
#if NEOPIXEL_ENABLE
#ifdef PIN_NEOPIXEL
memmove (&_history[0], &_history[1], sizeof(_history) - 1);
_history[sizeof(_history) - 1] = value;
#endif
#endif
}
void activity_show (void)
{
#if NEOPIXEL_ENABLE
#ifdef PIN_NEOPIXEL
for (int i = 0; i < NB_NEOPIXEL; i++)
{
strip.setPixelColor (i, color == 0 ? 0L : strip.ColorHSV(color * 512, 255, 255));
}
strip.show ();
#endif
#endif
}
void activity_clear ()
{
#if NEOPIXEL_ENABLE
#ifdef PIN_NEOPIXEL
lastvalue = 0;
color = 0;
memset (&_history[0], 0, sizeof(_history));
#endif
#endif
}