egoShield
egoShieldTimeLapse.h
Go to the documentation of this file.
1 /********************************************************************************************
2 * File: egoShieldTimeLapse.h *
3 * Version: 1.1.0 *
4 * Date: March 17th, 2018 *
5 * Author: Mogens Groth Nicolaisen *
6 * *
7 *********************************************************************************************
8 * (C) 2018 *
9 * *
10 * uStepper ApS *
11 * www.ustepper.com *
12 * administration@ustepper.com *
13 * *
14 * The code contained in this file is released under the following open source license: *
15 * *
16 * Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International *
17 * *
18 * The code in this file is provided without warranty of any kind - use at own risk! *
19 * neither uStepper ApS nor the author, can be held responsible for any damage *
20 * caused by the use of the code contained in this file ! *
21 * *
22 ********************************************************************************************/
110 #ifndef egoShield_h
111 #define egoShield_h
112 
113 #include "uStepper.h"
114 #include "U8g2lib.h"
115 #include "SPI.h"
116 #include "Arduino.h"
117 #include "SoftwareSerial.h"
118 
120 #define FWBT A3
121 
122 #define PLBT A1
123 
124 #define RECBT A2
125 
126 #define BWBT A0
127 
128 #define CNT 50
129 
130 #define OPTO 3
131 
133 #define FULL 1
134 
135 #define HALF 2
136 
137 #define QUARTER 4
138 
139 #define EIGHT 8
140 
141 #define SIXTEEN 16
142 
143 #define en_width 11
144 #define en_height 9
145 static unsigned char fw_bits[] = {
146  0x41, 0x00, 0xc3, 0x00, 0xc7, 0x01, 0xcf, 0x03, 0xdf, 0x07, 0xcf, 0x03,
147  0xc7, 0x01, 0xc3, 0x00, 0x41, 0x00 };
148 static unsigned char bw_bits[] = {
149  0x10, 0x04, 0x18, 0x06, 0x1c, 0x07, 0x9e, 0x07, 0xdf, 0x07, 0x9e, 0x07,
150  0x1c, 0x07, 0x18, 0x06, 0x10, 0x04 };
151 #define tt_width 10
152 #define tt_height 10
153 static unsigned char rec_bits[] = {
154  0xfc, 0x00, 0xfe, 0x01, 0xff, 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, 0x03,
155  0xff, 0x03, 0xff, 0x03, 0xfe, 0x01, 0xfc, 0x00 };
156 static unsigned char stop_bits[] = {
157  0xff, 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, 0x03,
158  0xff, 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, 0x03 };
159 static unsigned char pse_bits[] = {
160  0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00,
161  0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00, 0xcc, 0x00 };
162 #define play_width 6
163 #define play_height 11
164 static unsigned char play_bits[] = {
165  0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01 };
166 #define loop_width 11
167 #define loop_height 10
168 static unsigned char loop_bits[] = {
169  0x04, 0x00, 0x08, 0x00, 0x9e, 0x03, 0x09, 0x04, 0x05, 0x04, 0x01, 0x05,
170  0x81, 0x04, 0xce, 0x03, 0x80, 0x00, 0x00, 0x01 };
171 #define logo_width 90
172 #define logo_height 16
173 static unsigned char logo_bits[] = {
174  0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
175  0x00, 0x80, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
176  0x00, 0xc0, 0xff, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
177  0x00, 0xc0, 0xc7, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
178  0x3e, 0xcf, 0x07, 0xfc, 0xe3, 0xc3, 0x7b, 0x78, 0x0f, 0x3e, 0x9c, 0x01,
179  0xdf, 0xcf, 0x3f, 0xfe, 0xf3, 0xf7, 0xff, 0xfe, 0x1f, 0x7f, 0xff, 0x03,
180  0x3e, 0xcf, 0xff, 0x78, 0x38, 0xc7, 0xf3, 0x78, 0x9e, 0x73, 0xfe, 0x03,
181  0x3c, 0x8f, 0xff, 0x79, 0xfc, 0xcf, 0xf3, 0x79, 0xde, 0xff, 0xbc, 0x01,
182  0x1c, 0x47, 0xfe, 0x78, 0xfc, 0xcf, 0xf3, 0x78, 0xbe, 0x7f, 0x1e, 0x00,
183  0x3c, 0xef, 0xf0, 0x79, 0x38, 0xc0, 0xf3, 0x79, 0xde, 0x03, 0x1e, 0x00,
184  0xbe, 0xcf, 0xff, 0x78, 0x78, 0xc4, 0xf3, 0x78, 0x9e, 0x47, 0x3e, 0x00,
185  0xfc, 0xdf, 0x7f, 0xf8, 0xf3, 0xc7, 0x7f, 0xf8, 0x0f, 0x7f, 0x7e, 0x00,
186  0x38, 0x07, 0x3f, 0xf0, 0xe1, 0xc3, 0x3f, 0xf8, 0x07, 0x3e, 0x7f, 0x00,
187  0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x7c, 0x00, 0x00, 0x00, 0x00,
188  0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00,
189  0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00 };
190 
194 typedef struct {
195  uint8_t debounce,
196  state,
197  holdCnt,
198  btn;
199  uint16_t time;
200 } buttons;
201 
202 #define DEPRESSED 0
203 #define PRESSED 1
204 #define HOLD 2
206 #define HOLDTIME 75
207 #define HOLDTICK 5
210 #define RESETWDT asm volatile("WDR \n\t")
211 
221 extern "C" void WDT_vect(void) __attribute__ ((signal,used));
222 
224 {
225 public:
231  egoShield(void);
255  void egoShield::setup(uint16_t acc = 1500,
256  uint16_t vel = 1000,
257  uint8_t uStep = SIXTEEN,
258  uint16_t fTol = 10,
259  uint16_t fHys = 5,
260  float P = 1.0,
261  float I = 0.02,
262  float D = 0.006,
263  float res = 1,
264  uint16_t shutterDelay = 250);
268  void loop(void);
272  uStepper stepper;
273 private:
275  SoftwareSerial *BTSerial;
277  U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI *u8g2;
279  uint8_t place;
281  uint8_t endmove;
283  float pos[CNT];
285  bool pidFlag;
287  bool record;
289  bool loopMode;
291  bool longPushFlag[4];
293  char state;
295  uint8_t rec;
297  uint8_t play;
299  uint8_t fw;
301  uint8_t bw;
303  float setPoint;
305  uint16_t acceleration;
307  uint16_t velocity;
309  uint8_t microStepping;
311  uint16_t faultTolerance;
313  uint16_t faultHysteresis;
315  float pTerm;
317  float iTerm;
319  float dTerm;
321  float stepSize;
323  uint16_t interval;
325  float resolution;
327  bool brakeFlag;
328  /* Declaration of structs for each button*/
329  volatile buttons forwardBtn = {0x1F, DEPRESSED, 0, 0, 0},
330  playBtn = {0x1F, DEPRESSED, 0, 0, 0},
331  recordBtn = {0x1F, DEPRESSED, 0, 0, 0},
332  backwardsBtn = {0x1F, DEPRESSED, 0, 0, 0};
334  uint16_t shutterDelay;
335 
341  void resetButton(buttons *btn);
345  void resetAllButton();
349  void inputs(void);
362  uint8_t buttonState(uint8_t button, uint8_t nmbr);
366  void idleMode(void);
370  void playMode(void);
374  void pauseMode(void);
378  void timeMode(void);
382  void manForward(void);
386  void manBackward(void);
390  void startPage(void);
398  void idlePage(bool pidMode, float pos);
410  void recordPage(bool pidMode, bool recorded, uint8_t index, float pos);
420  void playPage(bool loopMode, bool pidMode, uint8_t index, bool mode);
430  void pausePage(bool loopMode, bool pidMode, uint8_t index);
438  void timePage(uint8_t step, bool pidMode);
442  void changeVelocity(void);
450  void debounce(buttons *btn, uint8_t sample);
451  friend void WDT_vect(void) __attribute__ ((signal,used));
452 };
453 #endif
void loop(void)
Contains the main logic of the shield functionality, e.g. transition between states (idle...
void playPage(bool loopMode, bool pidMode, uint8_t index, bool mode)
Holds the code for the play page of the OLED.
uStepper stepper
Creates an uStepper instance.
void WDT_vect(void) __attribute__((signal
Watchdog timer interrupt handler, for examining the buttons periodically.
void idleMode(void)
Holds the idle logic; page to show, what buttons to enable etc.
void debounce(buttons *btn, uint8_t sample)
This function handles the debouncing and tracking of whether buttons are pressed, released or held...
void resetAllButton()
Resets the state of all 4 buttons at once.
void recordPage(bool pidMode, bool recorded, uint8_t index, float pos)
Holds the code for the record page of the OLED.
uint16_t acceleration
void idlePage(bool pidMode, float pos)
Holds the code for the idle page of the OLED.
void timeMode(void)
Holds the timelapse logic, showing the timelapse page.
uint16_t shutterDelay
friend void WDT_vect(void) __attribute__((signal
Watchdog timer interrupt handler, for examining the buttons periodically.
U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI * u8g2
void playMode(void)
Holds the play logic, showing play page and running the recorded sequence.
void manBackward(void)
Holds the manual backward logic for driving the stepper motor manually with the pushbuttons.
uint8_t microStepping
float pos[CNT]
void pauseMode(void)
Holds the pause logic, showing the pause page and pausing the playing of a sequence.
void setup(uint16_t acc=1500, uint16_t vel=1000, uint8_t uStep=SIXTEEN, uint16_t fTol=10, uint16_t fHys=5, float P=1.0, float I=0.02, float D=0.006, float res=1, uint16_t shutterDelay=250)
Initializes buttons, OLED, uStepper and BT-module.
bool longPushFlag[4]
void resetButton(buttons *btn)
Function for resetting the state of a button seperately.
struct to hold information required to debounce button.
uint16_t time
uint16_t velocity
void inputs(void)
Reads the four buttons and writes their value; no push, short push or long push, to global variables...
uint16_t faultTolerance
#define SIXTEEN
SoftwareSerial * BTSerial
void startPage(void)
Holds the code for the start page of the OLED.
void pausePage(bool loopMode, bool pidMode, uint8_t index)
Holds the code for the pause page of the OLED.
void changeVelocity(void)
Holds the code for the changing velocity during sequence play.
#define CNT
void manForward(void)
Holds the manual forward logic for driving the stepper motor manually with the pushbuttons.
uint16_t faultHysteresis
void timePage(uint8_t step, bool pidMode)
Holds the code for the timelapse page of the OLED.
uint8_t buttonState(uint8_t button, uint8_t nmbr)
Returns the button state of the appropriate button.
egoShield(void)
Constructor of egoShield class.
uint16_t interval