-
Notifications
You must be signed in to change notification settings - Fork 0
/
trafficlight.h
62 lines (46 loc) · 1.53 KB
/
trafficlight.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
#pragma once
#include <map>
#include "pico/stdlib.h"
class TrafficLight
{
public:
enum class LedType
{
CommonAnode,
CommonCathode
};
enum Light
{
None = 0,
Red = 1 << 0,
Yellow = 1 << 1,
Green = 1 << 2,
RedCrossing = 1 << 3,
GreenCrossing = 1 << 4,
Main = Red | Yellow | Green,
Crossing = RedCrossing | GreenCrossing,
All = Main | Crossing
};
TrafficLight(uint redPin, uint yellowPin, uint greenPin, LedType ledType = LedType::CommonCathode);
TrafficLight(uint redPin, uint yellowPin, uint greenPin, uint redCrossingPin, uint greenCrossingPin, LedType ledType = LedType::CommonCathode);
TrafficLight(uint redCrossingPin, uint greenCrossingPin, LedType ledType = LedType::CommonCathode);
void setUpForStandardLights(uint redPin, uint yellowPin, uint greenPin);
void setUpForCrossingLights(uint redPin, uint greenPin);
void setLedType(LedType ledType);
void turnAllLightsOff();
void turnLightsOn(Light lights);
void turnLightsOff(Light lights);
void setLightsState(Light lights, bool on);
void setPin(Light light, uint pin);
bool hasLights() const;
bool hasCrossingLights() const;
bool hasValidPin(Light light) const;
uint getPin(Light light) const;
private:
bool _hasLights = false;
bool _hasCrossingLights = false;
LedType _ledType = LedType::CommonCathode;
std::map<Light, uint> _lightPinMap;
void initPin(uint pin);
bool shouldInvertOnOff() const;
};