ClearCore Library
BlinkCodeDriver.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Teknic, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22 
32 #ifndef BLINKCODEDRIVER_H_
33 #define BLINKCODEDRIVER_H_
34 
35 #include <stdint.h>
36 
37 #ifndef HIDE_FROM_DOXYGEN
38 namespace ClearCore {
39 
40 
47 class BlinkCodeDriver {
48  friend class StatusManager;
49 public:
50  typedef enum {
51  BLINK_GROUP_IO_OVERLOAD,
52  BLINK_GROUP_SUPPLY_ERROR,
53  BLINK_GROUP_DEVICE_ERROR,
54  BLINK_GROUP_CCIO_OVERLOAD,
55  BLINK_GROUP_APPLICATION,
56  BLINK_GROUP_MAX,
57  } BlinkCodeGroups;
58 
59  typedef enum {
60  SUPPLY_ERROR_NONE = 0x00,
61  SUPPLY_ERROR_VSUPPLY_LOW = 0x01,
62  SUPPLY_ERROR_VSUPPLY_HIGH = 0x02,
63  SUPPLY_ERROR_5VOB_OVERLOAD = 0x04,
64  } SupplyErrorCodes;
65 
66  typedef enum {
67  DEVICE_ERROR_NONE = 0x00,
68  DEVICE_ERROR_HBRIDGE = 0x01,
69  DEVICE_ERROR_SD_CARD = 0x02,
70  DEVICE_ERROR_ETHERNET = 0x04,
71  DEVICE_ERROR_CCIO = 0x08,
72  DEVICE_ERROR_XBEE = 0x10,
73  } DeviceErrors;
74 
75  typedef enum {
76  CCIO_OVERLOAD_NONE = 0x00,
77  CCIO_OVERLOAD_BOARD0 = 0x01,
78  CCIO_OVERLOAD_BOARD1 = 0x02,
79  CCIO_OVERLOAD_BOARD2 = 0x04,
80  CCIO_OVERLOAD_BOARD3 = 0x08,
81  CCIO_OVERLOAD_BOARD4 = 0x10,
82  CCIO_OVERLOAD_BOARD5 = 0x20,
83  CCIO_OVERLOAD_BOARD6 = 0x40,
84  CCIO_OVERLOAD_BOARD7 = 0x80,
85  } CcioOverload;
86 
90  bool CodePresent() {
91  return m_blinkState != IDLE;
92  }
93 
97  volatile const bool &LedState() {
98  return m_ledOn;
99  }
100 
104  void BlinkCodeClear(uint8_t group, uint8_t code);
105 
106 private:
107  enum BlinkState {
108  IDLE,
109  PRE_START_DELAY,
110  START_OUTPUT,
111  PRE_GROUP_DELAY,
112  GROUP_OUTPUT,
113  GROUP_DELAY,
114  PRE_CODE_DELAY,
115  CODE_OUTPUT,
116  CODE_DELAY,
117  };
118  // What are the codes that need displaying
119  uint8_t m_codes[BLINK_GROUP_MAX];
120  // Where are we in the code output sequence
121  BlinkState m_blinkState;
122  uint8_t m_currentCode;
123  uint8_t m_currentGroup;
124  uint16_t m_timer;
125  uint16_t m_strobeCnt;
126  uint16_t m_blinkCnt;
127  bool m_ledOn;
128  bool m_patternWrap;
129 
130  // What is the timing of the blink pattern
131  uint16_t m_strobeOnOffTicks;
132  uint16_t m_blinkTicks;
133  uint16_t m_prestartTicks;
134  uint16_t m_startTicks;
135  uint16_t m_pregroupTicks;
136  uint16_t m_precodeTicks;
137 
138  BlinkCodeDriver()
139  : m_codes{0},
140  m_blinkState(IDLE),
141  m_currentCode(0),
142  m_currentGroup(0),
143  m_timer(0),
144  m_strobeCnt(0),
145  m_blinkCnt(0),
146  m_ledOn(false),
147  m_patternWrap(false),
148  m_strobeOnOffTicks(250),
149  m_blinkTicks(2500),
150  m_prestartTicks(5000),
151  m_startTicks(11500),
152  m_pregroupTicks(5000),
153  m_precodeTicks(2500) {}
154 
158  void CodeGroupAdd(uint8_t group, uint8_t codes) {
159  m_codes[group] |= codes;
160  }
161 
165  void Update();
166 
172  bool NextCode(uint8_t group, uint8_t code);
173 };
174 
175 }
176 #endif /* HIDE_FROM_DOXYGEN */
177 #endif /* BLINKCODEDRIVER_H_ */
Namespace to encompass the ClearCore board API.
Definition: AdcManager.h:36