Serial Wombat Arduino Library
Loading...
Searching...
No Matches
SerialWombatSimulatedQuadEnc.h
Go to the documentation of this file.
1#pragma once
3
4#include <stdint.h>
5#include "SerialWombat.h"
6
15
23{
24public:
25 SerialWombatSimulatedQuadEnc(SerialWombatChip& serialWombat0, SerialWombatChip& serialWombat1, uint8_t _pin0, uint8_t _pin1, bool openDrain, bool doubleTransition): sw0(serialWombat0), sw1(serialWombat1)
26 {
27 pin0State = true;
28 pin1State = true;
29 pin0 = _pin0;
30 pin1 = _pin1;
31 this->openDrain = openDrain;
32
33 initialize();
34 }
35
37 {
38 pin0High();
39 pin1High();
40 }
42 {
43 if (pin0State)
44 {
45 pin0Low();
46 }
47 else
48 {
49 pin0High();
50 }
51 }
52
54 {
55 if (pin1State)
56 {
57 pin1Low();
58 }
59 else
60 {
61 pin1High();
62 }
63 }
64 void pin0High()
65 {
66 sw0.digitalWrite(pin0, HIGH);
67 pin0State = true;
68 }
69
70 void pin1High()
71 {
72 sw1.digitalWrite(pin1, HIGH);
73 pin1State = true;
74 }
75
76
77 void pin0Low()
78 {
79 sw0.digitalWrite(pin0, LOW);
80 pin0State = false;
81 }
82
83 void pin1Low()
84 {
85 sw1.digitalWrite(pin1, LOW);
86 pin1State = false;
87 }
88
89 bool service()
90 {
92 {
93 switch (state)
94 {
95 case SIMQE_IDLE:
96 {
98 {
101 {
102 togglePin0();
103 }
104 else
105 {
106 togglePin1();
107 }
108
110 }
111
112 }
113 break;
114
116 {
118 {
119 lastTransitionTime_millis = millis();
121 {
122 togglePin1();
123 if (!doubleTransition)
124 {
126 }
127 }
128 else
129 {
130 togglePin0();
131 if (!doubleTransition)
132 {
134 }
135
136 }
137
138
140 }
141
142 }
143 break;
144
146 {
148 {
150 {
151 lastTransitionTime_millis = millis();
153 {
154 togglePin0();
155 }
156 else
157 {
158 togglePin1();
159 }
160
162 }
163 else
164 {
166 }
167 }
168
169 }
170 break;
172 {
174 {
175 lastTransitionTime_millis = millis();
177 {
178 togglePin1();
180
181 }
182 else
183 {
184 togglePin0();
186
187 }
189 }
190
191 }
192 break;
193
195 {
197 {
198
200 }
201
202 }
203 break;
204 }
205 }
206 return state == SIMQE_IDLE;
207 }
209 {
210 sw0.pinMode(pin0, OUTPUT, false, openDrain);
211 sw1.pinMode(pin1, OUTPUT, false, openDrain);
212 bothPinsHigh();
213 currentPosition = 0;
214 targetPosition = 0;
216 }
217
218
219 bool doubleTransition = false;
221
222 int32_t currentPosition = 0;
223 int32_t targetPosition = 0;
228 bool openDrain = true;
230
231private:
232 bool pin0State = true;
233 bool pin1State = true;
234 SerialWombatChip& sw0;
235 SerialWombatChip& sw1;
236 uint8_t pin0;
237 uint8_t pin1;
238
239
240
241};
@ SIMQE_2ND_TRANSITION_1ST_PIN_COMPLETED
@ SIMQE_2ND_TRANSITION_COMPLETED
@ SIMQE_2ND_TRANSITION_2ND_PIN_COMPLETED
@ SIMQE_1ST_TRANSITION_1ST_PIN_COMPLETED
@ SIMQE_1ST_TRANSITION_2ND_PIN_COMPLETED
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
SerialWombatSimulatedQuadEnc(SerialWombatChip &serialWombat0, SerialWombatChip &serialWombat1, uint8_t _pin0, uint8_t _pin1, bool openDrain, bool doubleTransition)