Skip to content

Commit 8a1aa43

Browse files
author
Fola Fatola
committed
# This is a combination of 3 commits.
# This is the 1st commit message: Started State classes # This is the commit message #2: LightingStateTransitions # This is the commit message #3: Implemented lighting states
1 parent dc1c6cb commit 8a1aa43

File tree

6 files changed

+348
-43
lines changed

6 files changed

+348
-43
lines changed

Lighting/Inc/conversions.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ typedef struct {
3737
* Add other modes as necessary
3838
*/
3939

40+
4041
enum ControlDomain {
4142
CD_MAIN = 0,
4243
CD_TAXI = 1,
@@ -58,14 +59,13 @@ enum ControlDomain {
5859

5960
enum LightingStateTransition {
6061
TRANSITION_GROUND = 0,
61-
TRANSITION_GROUND_STANDBY = 1,
62+
TRANSITION_STANDBY = 1,
6263
TRANSITION_TAXI = 2,
63-
TRANSITION_TAXI_BRAKE = 3,
64-
TRANSITION_TAKEOFF = 4,
65-
TRANSITION_FLIGHT = 5,
66-
TRANSITION_FLIGHT_BRAKE = 6,
67-
TRANSITION_LANDING = 7,
68-
TRANSITION_SEARCH = 8
64+
TRANSITION_TAKEOFF = 3,
65+
TRANSITION_FLIGHT = 4,
66+
TRANSITION_BRAKE = 5,
67+
TRANSITION_LANDING = 6,
68+
TRANSITION_SEARCH = 7
6969
};
7070

7171
#endif /* INC_CONVERSIONS_HPP_ */
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* lighting_controller_states.hpp
3+
*
4+
* Created on: Feb 26, 2025
5+
* Author: folafatola
6+
*/
7+
8+
#include "lighting_control_state_manager.hpp"
9+
10+
class LC_State_GROUND: public LightingControlState {
11+
public:
12+
LC_State_GROUND();
13+
uint8_t execute(uint16_t domain_leds_LC[]) override;
14+
15+
private:
16+
uint16_t domain_leds_ground[CD_LENGTH];
17+
uint8_t domain_settings;
18+
};
19+
20+
21+
class LC_State_TAXI: public LightingControlState {
22+
public:
23+
LC_State_TAXI();
24+
uint8_t execute(uint16_t domain_leds_LC[]) override;
25+
26+
private:
27+
uint16_t domain_leds_taxi[CD_LENGTH];
28+
uint8_t domain_settings;
29+
};
30+
31+
32+
class LC_State_TAKEOFF: public LightingControlState {
33+
public:
34+
LC_State_TAKEOFF();
35+
uint8_t execute(uint16_t domain_leds_LC[]) override;
36+
37+
private:
38+
uint16_t domain_leds_takeoff[CD_LENGTH];
39+
uint8_t domain_settings;
40+
};
41+
42+
class LC_State_FLIGHT: public LightingControlState {
43+
public:
44+
LC_State_FLIGHT();
45+
uint8_t execute(uint16_t domain_leds_LC[]) override;
46+
47+
private:
48+
uint16_t domain_leds_flight[CD_LENGTH];
49+
uint8_t domain_settings;
50+
};
51+
52+
53+
class LC_State_BRAKE: public LightingControlState {
54+
public:
55+
LC_State_BRAKE();
56+
uint8_t execute(uint16_t domain_leds_LC[]) override;
57+
58+
private:
59+
uint16_t domain_leds_brake[CD_LENGTH];
60+
uint8_t domain_settings;
61+
};
62+
63+
64+
class LC_State_LANDING: public LightingControlState {
65+
public:
66+
LC_State_LANDING();
67+
uint8_t execute(uint16_t domain_leds_LC[]) override;
68+
69+
private:
70+
uint16_t domain_leds_landing[CD_LENGTH];
71+
uint8_t domain_settings;
72+
};
73+
74+
class LC_State_STANDBY : public LightingControlState {
75+
public:
76+
LC_State_STANDBY();
77+
uint8_t execute(uint16_t domain_leds_LC[]);
78+
private:
79+
uint16_t domain_leds_standby[CD_LENGTH];
80+
uint8_t domain_settings;
81+
};
82+
83+
//If you reach this state, you might be cooked.
84+
class LC_State_SEARCH: public LightingControlState {
85+
public:
86+
LC_State_SEARCH();
87+
uint8_t execute(uint16_t domain_leds_LC[]);
88+
private:
89+
uint16_t domain_leds_search[CD_LENGTH];
90+
uint8_t domain_settings;
91+
};
92+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* lighting_control_state_manager.hpp
3+
*
4+
* Created on: Feb 26, 2025
5+
* Author: folafatola
6+
*/
7+
8+
#ifndef INC_LIGHTING_CONTROL_STATE_MANAGER_HPP_
9+
#define INC_LIGHTING_CONTROL_STATE_MANAGER_HPP_
10+
11+
#include "conversions.hpp"
12+
13+
14+
class LightingControlState {
15+
public:
16+
virtual uint8_t execute(uint16_t domain_leds[]) = 0;
17+
};
18+
19+
#endif /* INC_LIGHTING_CONTROL_STATE_MANAGER_HPP_ */

Lighting/Inc/lighting_controller.hpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <cstdint>
1212

1313
#include "conversions.hpp"
14+
#include "lighting_control_state_classes.hpp"
1415
#include "ws2812.hpp"
1516

1617

@@ -106,6 +107,13 @@ class LightingController {
106107
*/
107108
void deactivate_domain(ControlDomain domain);
108109

110+
/*
111+
* Enables (turns on) a Control Domain
112+
* This enables Control Domains to become active, so LEDs that are part of that control
113+
* domain can shine their domain colours.
114+
*
115+
* @param domain : domain to be disabled
116+
*/
109117
void allow_domain(ControlDomain domain);
110118

111119
void disallow_domain(ControlDomain domain);
@@ -139,23 +147,30 @@ class LightingController {
139147
void set_domain_brightness(ControlDomain domain, uint8_t brightness);
140148

141149

150+
void set_state(LightingStateTransition next_state);
151+
152+
void executeState();
142153

143154
// TODO: add function to "recolour domain" (enables & sets colour)
144155
// Use this instead of set + enable?
145156

146157
private:
147-
static constexpr uint8_t NUM_LEDS = 6;
158+
static constexpr uint8_t NUM_LEDS = 10;
159+
160+
LightingControlStates *lighting_control_state;
161+
148162
uint8_t *dma_buffer;
149163
uint8_t *bank_buffer;
150164
WS2812 *leds;
151-
uint8_t domain_allowed; // true when a domain is allowed to be active
152-
uint8_t domain_active; // true when domain is active
153-
uint8_t domain_leds[CD_LENGTH]; // Bitmask of LED's which are active in each domain
154-
RGB_colour_t domain_colours[CD_LENGTH]; // Domain colour
155-
uint8_t domain_brightness[CD_LENGTH]; // Domain brightness
156-
157-
TIM_HandleTypeDef *htimx; //timer handle
158-
uint16_t tim_channel_x; //timer channel
165+
166+
uint8_t domain_allowed; // bitfield of which control domains are ALLOWED to be active.
167+
uint8_t domain_active; // bitfield of which control domains are CURRENTLY active.
168+
uint16_t domain_leds[CD_LENGTH]; // Bitmask of LED's which are active in each domain
169+
RGB_colour_t domain_colours[CD_LENGTH]; // Control domain colour
170+
uint8_t domain_brightness[CD_LENGTH]; // Control domain brightness
171+
172+
TIM_HandleTypeDef *lighting_controller_tim_handle; //timer handle
173+
uint16_t lighting_controller_tim_channel; //timer channel
159174

160175
void initialize_bank_buffer_off();
161176
void initialize_bank_buffer_on();
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* lighting_controller_states.cpp
3+
*
4+
* Created on: Feb 26, 2025
5+
* Author: folafatola
6+
*/
7+
8+
#include <lighting_control_state_classes.hpp>
9+
10+
11+
12+
LC_State_GROUND::LC_State_GROUND() {
13+
domain_leds_GROUND[CD_BEACON] |= 1 + (1 << 2) + (1 << 3) + (1 << 5) + (1 << 6) + (1 << 8);
14+
}
15+
16+
uint8_t LC_State_GROUND::execute(uint16_t domain_leds_LC[]) {
17+
domain_leds_LC[CD_BEACON] = domain_leds_fround[CD_BEACON];
18+
domain_settings |= (1 << CD_BEACON);
19+
return domain_settings;
20+
}
21+
22+
LC_State_TAXI::LC_State_TAXI() {
23+
domain_leds_taxi[CD_TAXI] |= (1 << 7) + (1 << 9);
24+
domain_leds_taxi[CD_BEACON] |= (1 << 6) + (1 << 8);
25+
domain_leds_taxi[CD_BRAKE] |= (1 << 1) + (1 << 4);
26+
}
27+
28+
uint8_t LC_State_TAXI::execute(uint16_t domain_leds_LC[]) {
29+
domain_leds_LC[CD_TAXI] = domain_leds_taxi[CD_TAXI];
30+
domain_leds_LC[CD_BEACON] = domain_leds_taxi[CD_BEACON];
31+
domain_leds_LC[CD_BRAKE] = domain_leds_taxi[CD_BRAKE];
32+
domain_settings |= (1 << CD_TAXI) + (1 << CD_BEACON) + (1 << CD_BRAKE);
33+
return domain_settings;
34+
}
35+
36+
LC_State_TAKEOFF::LC_State_TAKEOFF() {
37+
domain_leds_takeoff[CD_STROBE] |= (1 << 7) + (1 << 9);
38+
domain_leds_takeoff[CD_BEACON] |= (1 << 6) + (1 << 8);
39+
}
40+
41+
uint8_t LC_State_TAKEOFF::execute(uint16_t domain_leds_LC[]) {
42+
domain_leds_LC[CD_STROBE] = domain_leds_takeoff[CD_STROBE];
43+
domain_leds_LC[CD_BEACON] = domain_leds_takeoff[CD_BEACON];
44+
domain_settings |= (1 << CD_STROBE) + (1 << CD_BEACON);
45+
return domain_settings;
46+
}
47+
48+
LC_State_FLIGHT::LC_State_FLIGHT() {
49+
domain_leds_flight[CD_STROBE] |= (1 << 7) + (1 << 9);
50+
domain_leds_flight[CD_BEACON] |= (1 << 6) + (1 << 8);
51+
domain_leds_flight[CD_NAV] |= 1 + (1 << 1) + (1 << 2);
52+
}
53+
54+
uint8_t LC_State_FLIGHT::execute(uint16_t domain_leds_LC[]) {
55+
domain_leds_LC[CD_STROBE] = domain_leds_flight[CD_STROBE];
56+
domain_leds_LC[CD_BEACON] = domain_leds_flight[CD_BEACON];
57+
domain_leds_LC[CD_NAV] = domain_leds_flight[CD_NAV];
58+
domain_settings |= (1 << CD_STROBE) + (1 << CD_BEACON) + (1 << CD_NAV);
59+
return domain_settings;
60+
}
61+
62+
LC_State_BRAKE::LC_State_BRAKE() {
63+
domain_leds_brake[CD_BRAKE] |= (1 << 1) + (1 << 4);
64+
}
65+
66+
uint8_t LC_State_BRAKE::execute(uint16_t domain_leds_LC[]) {
67+
domain_leds_LC[CD_BRAKE] = domain_leds_brake[CD_BRAKE];
68+
domain_settings |= (1 << CD_BRAKE);
69+
}
70+
71+
LC_State_LANDING::LC_State_LANDING() {
72+
domain_leds_landing[CD_STROBE] |= (1 << 7) + (1 << 9);
73+
domain_leds_landing[CD_BEACON] |= (1 << 6) + (1 << 8);
74+
domain_leds_landing[CD_NAV] |= 1 + (1 << 5);
75+
domain_leds_landing[CD_LANDING] |= (1 << 1) + (1 << 2) + (1 << 3) + (1 << 4);
76+
}
77+
78+
uint8_t LC_State_LANDING::execute(uint16_t domain_leds_LC[]) {
79+
domain_leds_LC[CD_STROBE] = domain_leds_landing[CD_STROBE];
80+
domain_leds_LC[CD_BEACON] = domain_leds_landing[CD_BEACON];
81+
domain_leds_LC[CD_NAV] = domain_leds_landing[CD_NAV];
82+
domain_leds_LC[CD_LANDING] = domain_leds_landing[CD_LANDING];
83+
domain_settings |= (1 << CD_STROBE) + (1 << CD_BEACON) + (1 << CD_NAV) + (1 << CD_LANDING);
84+
return domain_settings;
85+
}
86+
87+
LC_State_STANDBY::LC_State_STANDBY() {
88+
domain_leds_standby[CD_BEACON] |= (1 << 1) + (1 << 4);
89+
domain_leds_standby[CD_STROBE] |= 1 + (1 << 2) + (1 << 3) + (1 << 5);
90+
}
91+
92+
uint8_t LC_State_STANDBY::execute(uint16_t domain_leds_LC[]) {
93+
domain_leds_LC[CD_STROBE] = domain_leds_standby[CD_STROBE];
94+
domain_leds_LC[CD_BEACON] = domain_leds_standby[CD_BEACON];
95+
domain_settings |= (1 << CD_STROBE) + (1 << CD_BEACON);
96+
return domain_settings;
97+
}
98+
99+
LC_State_SEARCH::LC_State_SEARCH() {
100+
for (int i = 0; i < 6; ++i) {
101+
domain_leds_search[CD_SEARCH] |= (1 << i);
102+
}
103+
}

0 commit comments

Comments
 (0)