ASCEND Flight Software
Loading...
Searching...
No Matches
ErrorDisplay.h
Go to the documentation of this file.
1#ifndef ERROR_DISPLAY_H
2#define ERROR_DISPLAY_H
3
4#include <Arduino.h>
5
6#include "PayloadConfig.h"
7#include "pico/multicore.h"
8#include "pico/stdlib.h"
9
16typedef enum {
17 CRITICAL_FAIL = 0, // no sensors or no storage
18 SD_CARD_FAIL, // triggered if SD card verify function returns false or if an
19 // SD card write fails
20 LOW_SENSOR_COUNT, // triggered for less than 5 sensors verified
21 POWER_CYCLED, // determined based on if there are multiple data files on the
22 // SD card
23 NONE // default state, lowest priority
25
31 private:
35
37 mutex_init(&error_display_mutex);
38 this->pin_level = 1;
39 this->code = NONE;
40 pinMode(ERROR_PIN_2, OUTPUT);
41 pinMode(ERROR_PIN_1, INPUT);
42 pinMode(ERROR_PIN_0, INPUT);
43 }
44
45 public:
52 static ErrorDisplay only_instance;
53 return only_instance;
54 }
55
62 void addCode(Error e) {
63 mutex_enter_blocking(&error_display_mutex);
64
65 if (e < this->code) {
66 this->code = e;
67 }
68
69 mutex_exit(&error_display_mutex);
70 }
71
76 void toggle() {
77 mutex_enter_blocking(&error_display_mutex);
78
79 this->pin_level = !(this->pin_level);
80
81 uint8_t display_code = 7 - this->code; // 0 is highest
82
83 if (this->code == Error::NONE) display_code = 0b001;
84
85 // digitalWrite(ERROR_PIN_2, this->pin_level && (display_code & 0b100));
86 // digitalWrite(ERROR_PIN_1, this->pin_level && (display_code & 0b010));
87 // digitalWrite(ERROR_PIN_0, this->pin_level && (display_code & 0b001));
88 digitalWrite(ERROR_PIN_2, this->pin_level);
89
90 mutex_exit(&error_display_mutex);
91 }
92};
93
94#endif
Error
Definition ErrorDisplay.h:16
@ CRITICAL_FAIL
Definition ErrorDisplay.h:17
@ POWER_CYCLED
Definition ErrorDisplay.h:21
@ LOW_SENSOR_COUNT
Definition ErrorDisplay.h:20
@ NONE
Definition ErrorDisplay.h:23
@ SD_CARD_FAIL
Definition ErrorDisplay.h:18
Central location for pinout and config defines.
#define ERROR_PIN_0
Error display bit 0.
Definition PayloadConfig.h:18
#define ERROR_PIN_1
Error display bit 1.
Definition PayloadConfig.h:16
#define ERROR_PIN_2
Error display bit 2.
Definition PayloadConfig.h:14
Singleton class for the 3 GPIO LED Error Display.
Definition ErrorDisplay.h:30
ErrorDisplay()
Definition ErrorDisplay.h:36
void addCode(Error e)
Sets the error code to the given value if the given error is of a higher priority then the current er...
Definition ErrorDisplay.h:62
int pin_level
Definition ErrorDisplay.h:33
void toggle()
Toggles the level of the error display.
Definition ErrorDisplay.h:76
static ErrorDisplay & instance()
Accesses the only instance of ErrorDisplay (Singleton)
Definition ErrorDisplay.h:51
Error code
Definition ErrorDisplay.h:34
mutex_t error_display_mutex
Definition ErrorDisplay.h:32