-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathFeeder.h
120 lines (93 loc) · 2.78 KB
/
Feeder.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef _FEEDER_h
#define _FEEDER_h
#include "arduino.h"
#include "config.h"
#include "shield.h"
#include <Servo.h>
#include <EEPROMex.h>
class FeederClass {
protected:
//on initialize it gets a number. Off feederNo the location EEPROM settings are stored is derived. Nothing else so: TODO: make it obsolete
int feederNo=-1;
enum tFeederErrorState {
sOK=0,
sOK_NOFEEDBACKLINE=1,
sERROR_IGNORED=2,
sERROR=-1,
} ;
tFeederErrorState getFeederErrorState();
public:
//used to transfer settings between different objects
struct sFeederSettings {
uint8_t full_advanced_angle;
uint8_t half_advanced_angle;
uint8_t retract_angle;
uint8_t feed_length;
int time_to_settle;
int motor_min_pulsewidth;
int motor_max_pulsewidth;
#ifdef HAS_FEEDBACKLINES
uint8_t ignore_feedback;
#endif
//sFeederState lastFeederState; //save last position to stay there on poweron? needs something not to wear out the eeprom. until now just go to retract pos.
};
uint8_t remainingFeedLength=0;
//operational status of the feeder
enum sFeederState {
sDISABLED,
sIDLE,
sMOVING,
sADVANCING_CYCLE_COMPLETED,
} feederState = sDISABLED;
//store the position of the advancing lever
//last state is stored to enable half advance moves (2mm tapes)
enum sFeederPosition {
sAT_UNKNOWN,
sAT_FULL_ADVANCED_POSITION,
sAT_HALF_ADVANCED_POSITION,
sAT_RETRACT_POSITION,
} lastFeederPosition = sAT_UNKNOWN, feederPosition = sAT_UNKNOWN;
//store last tinestamp position changed to respect a settle time
unsigned long lastTimePositionChange;
//some variables for utilizing the feedbackline to feed for setup the feeder...
uint8_t feedbackLineTickCounter=0;
unsigned long lastTimeFeedbacklineCheck;
int lastButtonState;
//permanently in eeprom stored settings
sFeederSettings feederSettings = {
FEEDER_DEFAULT_FULL_ADVANCED_ANGLE,
FEEDER_DEFAULT_HALF_ADVANCED_ANGLE,
FEEDER_DEFAULT_RETRACT_ANGLE,
FEEDER_DEFAULT_FEED_LENGTH,
FEEDER_DEFAULT_TIME_TO_SETTLE,
FEEDER_DEFAULT_MOTOR_MIN_PULSEWIDTH,
FEEDER_DEFAULT_MOTOR_MAX_PULSEWITH,
#ifdef HAS_FEEDBACKLINES
FEEDER_DEFAULT_IGNORE_FEEDBACK,
#endif
};
Servo servo;
void initialize(uint8_t _feederNo);
bool isInitialized();
bool hasFeedbackLine();
void outputCurrentSettings();
void setup();
sFeederSettings getSettings();
void setSettings(sFeederSettings UpdatedFeederSettings);
void loadFeederSettings();
void saveFeederSettings();
void factoryReset();
void gotoPostPickPosition();
void gotoRetractPosition();
void gotoHalfAdvancedPosition();
void gotoFullAdvancedPosition();
void gotoAngle(uint8_t angle);
bool advance(uint8_t feedLength, bool overrideError);
String reportFeederErrorState();
bool feederIsOk();
void enable();
void disable();
void update();
};
extern FeederClass Feeder;
#endif