-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmg126_spionglas_NEU.ino
94 lines (74 loc) · 1.96 KB
/
mg126_spionglas_NEU.ino
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
92
93
94
#include <Arduino.h>
#include <stdio.h>
#include <FastLED.h>
#include <MG126_Ble.h>
#include "SPI.h"
#define NUM_LEDS 55
#define DATA_PIN 5
CRGB leds[NUM_LEDS];
MG126_Ble_Class MG126_Ble;
bool bItemCharacteristicValueChanged = false;
bool itemCharacteristicValue = false;
void setup() {
MG126_Ble.ble_init();
setupItemAction();
}
void loop() {
if (GetConnectedStatus()) {
itemAction(true);
delay(3000);
itemAction(true);
delay(3000);
itemAction(false);
}
//establishConnection();
}
void setupItemAction() {
#ifdef DEFAULT_ITEM
// setup default item action
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
#endif // DEFAULT_ITEM
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.delay(10);
FastLED.clear(true);
}
void itemAction(bool state) {
#ifdef DEFAULT_ITEM
// default item action
digitalWrite(LED_BUILTIN, state);
#endif // DEFAULT_ITEM
if (state) {
fill_solid(leds, NUM_LEDS, CRGB::White);
for (int brightness = 0; brightness < 256; brightness++) {
FastLED.setBrightness(brightness);
FastLED.show();
FastLED.delay(10);
}
} else {
for (int brightness = 255; brightness >= 0; brightness--) {
FastLED.setBrightness(brightness);
FastLED.show();
FastLED.delay(10);
}
FastLED.clear(true);
}
}
void establishConnection() {
if (GetConnectedStatus()) {
Serial.println("Central connected");
// TODO Verify identity here
//SIG_ConnParaUpdateReq(48, 100, 0, 3200);
while (GetConnectedStatus()) {
if (bItemCharacteristicValueChanged) {
itemAction(itemCharacteristicValue);
bItemCharacteristicValueChanged = false;
}
}
Serial.println("Disconnected from central");
itemCharacteristicValue = false;
itemAction(itemCharacteristicValue);
FastLED.clear(true);
FastLED.delay(10);
}
}