NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ledstrip.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Ninjaflight is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Ninjaflight is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 
20 #include <stddef.h>
21 
22 #include "../config/ledstrip.h"
23 
24 static inline int ledGetX(const struct led_config *lcfg) { return (lcfg->xy >> LED_X_BIT_OFFSET) & LED_XY_MASK; }
25 static inline int ledGetY(const struct led_config *lcfg) { return (lcfg->xy >> LED_Y_BIT_OFFSET) & LED_XY_MASK; }
26 static inline void ledSetXY(struct led_config *lcfg, int x, int y) {
27  lcfg->xy = ((x & LED_XY_MASK) << LED_X_BIT_OFFSET) | ((y & LED_XY_MASK) << LED_Y_BIT_OFFSET);
28 }
29 
30 struct ledstrip {
33 
34  uint8_t ledGridWidth;
35  uint8_t ledGridHeight;
36  // grid offsets
41 
42  uint8_t ledCount;
43  uint8_t ledRingCount;
44  uint8_t ledRingSeqLen;
45 
46  const struct system_calls *system;
47  struct failsafe *failsafe;
48  struct battery *battery;
49  struct rx *rx;
50  const struct config *config;
51 };
52 
53 // TODO: ledstrip should not depend on rx and failsafe
54 void ledstrip_init(struct ledstrip *self, const struct config *config, const struct system_calls *system, struct rx *rx, struct failsafe *failsafe);
55 
56 bool ledstrip_set_led_config(struct ledstrip *self, int ledIndex, const char *config);
57 void ledstrip_update(struct ledstrip *self);
58 void ledstrip_update_ring(struct ledstrip *self);
59 
60 void ledstrip_set_default_config(struct ledstrip *self);
61 void ledstrip_genconfig(struct ledstrip *self, int ledIndex, char *ledConfigBuffer, size_t bufferSize);
62 
63 void applyDefaultColors(void);
64 
65 void ledstrip_enable(struct ledstrip *self);
66 void ledstrip_disable(struct ledstrip *self);
67 
69 void ledstrip_reload_config(struct ledstrip *self);
70 
void ledstrip_genconfig(struct ledstrip *self, int ledIndex, char *ledConfigBuffer, size_t bufferSize)
struct failsafe * failsafe
Definition: ledstrip.h:47
void ledstrip_update(struct ledstrip *self)
Definition: ledstrip.c:581
Definition: config.h:81
void ledstrip_set_default_config(struct ledstrip *self)
uint8_t xy
Definition: ledstrip.h:121
bool ledStripInitialised
Definition: ledstrip.h:31
uint8_t ledGridHeight
Definition: ledstrip.h:35
uint8_t ledCount
Definition: ledstrip.h:42
Definition: failsafe.h:46
bool ledstrip_set_led_config(struct ledstrip *self, int ledIndex, const char *config)
Definition: ledstrip.h:120
Definition: battery.h:30
uint8_t ledRingCount
Definition: ledstrip.h:43
uint8_t lowestXValueForEast
Definition: ledstrip.h:40
struct system_config system
Definition: config.h:99
Definition: rx.h:97
uint8_t highestYValueForNorth
Definition: ledstrip.h:37
#define LED_X_BIT_OFFSET
Definition: ledstrip.h:37
#define LED_Y_BIT_OFFSET
Definition: ledstrip.h:38
bool ledStripEnabled
Definition: ledstrip.h:32
uint8_t lowestYValueForSouth
Definition: ledstrip.h:38
struct battery * battery
Definition: ledstrip.h:48
void applyDefaultColors(void)
uint8_t ledRingSeqLen
Definition: ledstrip.h:44
const struct config * config
Definition: ledstrip.h:50
Definition: system_calls.h:200
void ledstrip_reload_config(struct ledstrip *self)
Currently reloads config from the global store TODO: pass config to init!
Definition: ledstrip.c:109
void ledstrip_update_ring(struct ledstrip *self)
#define LED_XY_MASK
Definition: ledstrip.h:39
struct rx * rx
Definition: ledstrip.h:49
uint8_t highestXValueForWest
Definition: ledstrip.h:39
uint8_t ledGridWidth
Definition: ledstrip.h:34
void ledstrip_enable(struct ledstrip *self)
Definition: ledstrip.c:632
void ledstrip_init(struct ledstrip *self, const struct config *config, const struct system_calls *system, struct rx *rx, struct failsafe *failsafe)
void ledstrip_disable(struct ledstrip *self)
Definition: ledstrip.c:640
Definition: ledstrip.h:30
const struct system_calls * system
Definition: ledstrip.h:46