-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathled.h
78 lines (65 loc) · 2.52 KB
/
led.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once
#include <Arduino.h>
#include <FastLED.h>
#include "data.h"
#include "hub.h"
#include "palettes.h"
#include "tacho.h"
CLEDController *cled = nullptr;
CLEDController *cled1 = nullptr;
CRGB *leds;
void led_init() {
leds = (CRGB *)malloc(sizeof(CRGB));
cled = &FastLED.addLeds<LED_CHIP, LED_PIN, LED_ORDER>(leds, 0);
cled1 = &FastLED.addLeds<LED_CHIP, LED_PIN1, LED_ORDER>(leds, 0);
}
void led_change() {
leds = (CRGB *)realloc(leds, sizeof(CRGB) * data.led_amount);
cled->setLeds(leds, data.led_amount);
cled1->setLeds(leds, data.led_amount);
}
void led_tick() {
static GHtimer tmr(LED_PRD);
if (tmr) {
static uint16_t pos = 0;
pos += data.max_spd * LED_PRD / 1000; // (mm / s) * (ms / 1000) == mm
if (data.max_spd == 0) {
pos = 0;
}
uint16_t idx = pos * data.ledm / 1000; // mm * (leds / m / 1000) == leds
switch (data.mode) {
case 0: {
for (uint16_t i = 0; i < data.led_amount; i++) {
leds[i] = ColorFromPalette(paletteArr[data.pal], 255 - (idx + i) * 255 / data.pal_len, 255, LINEARBLEND);
}
cled->showLeds(data.led_bri);
cled1->showLeds(data.led_bri);
} break;
case 1: {
for (uint16_t i = 0; i < data.led_amount; i++) {
if (i > data.led_amount / 2) {
leds[data.led_amount - i - 1] = ColorFromPalette(paletteArr[data.pal], 255 - (idx + i) * 255 / data.pal_len, 255, LINEARBLEND);
continue;
}
leds[i] = ColorFromPalette(paletteArr[data.pal], 255 - (idx + i) * 255 / data.pal_len, 255, LINEARBLEND);
}
cled->showLeds(data.led_bri);
cled1->showLeds(data.led_bri);
}break;
case 2: {
cled->showColor(CHSV(255, 0, 0), data.led_bri);
cled1->showColor(CHSV(255, 0, 0), data.led_bri);
} break;
case 3: {
if (data.max_spd == 0) {
for (uint16_t i = 0; i < data.led_amount; i++) {
static uint16_t pos = 0;
uint16_t idx = pos * data.ledm / 1000; // mm * (leds / m / 1000) == leds
leds[i] = ColorFromPalette(paletteArr[31], 255 - (idx + i) * 255 / data.pal_len, 255, LINEARBLEND);
}
cled->showLeds(data.led_bri);
} break;
}
}
}
}