-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.h
182 lines (127 loc) · 4.68 KB
/
Config.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#ifndef CONFIG_H_
#define CONFIG_H_
#include "Arduino.h"
#include <AccelStepper.h>
const char softwareName[] = "MR Flow Phantom ";
const char softwareVersion[] = "v1.1";
const char NameAndVersion[] = "MR Flow Phantom v1.1";
// ------------------------------------ //
// ----- EasyDriver Configuration ----- //
// EasyDriver Pin Configuration (digital pins)
#define drv_step A1
#define drv_dir A2
#define drv_ms1 A3
#define drv_ms2 A4
#define drv_enable A5
// Define Microstepping
//MS1 MS2 Microstep Resolution
//L L Full Step (2 Phase)
//H L Half Step
//L H Quarter Step
//H H Eigth Step
#define drv_ms1_set HIGH
#define drv_ms2_set HIGH
// ------------------------------------ //
// -------------------------------------------- //
// ----- Movement Calculations & Settings ----- //
#define stepper_default_speed 1000
#define stepper_default_acc 5000
// Threaded rod is probably 20tpi = 7.874015 thread/cm
// motor: 1.8deg/step
// configuration: Eighth of a step
// 1 step = 1.8/8 = 0.225deg
// 1600 steps per rev
// 1600 * 7.874015 = 12,598.425 steps per cm
#define CALC_ROD_THREADING 7.874015 // threads/cm
#define CALC_DEG_PER_STEP 0.225 // deg/step
#define CALC_STEPS_PER_CM ( (360.0/CALC_DEG_PER_STEP) * CALC_ROD_THREADING )
#define CALC_CM_PER_CC ( 9.0 / 50 ) // 90mm/50cc
#define CALC_CC_PER_STEP ( 1.0 / (CALC_STEPS_PER_CM * CALC_CM_PER_CC) )
#define SYRINGE_MAX_VOL_CC 8.0 / CALC_CM_PER_CC // cc, actual total movable length is 107mm
// -------------------------------------------- //
#define prg_osc_phaseDuration_default 30 // seconds
#define prg_osc_volume_default 40 // mL
#define prg_osc_isPushing_default true //
#define prg_push_duration_default 30 // seconds
#define prg_push_volume_default 40 // mL
#define prg_push_status_default false // false = 'off', true = 'on'
#define prg_pull_duration_default 30 // seconds
#define prg_pull_volume_default 40 // mL
#define prg_pull_status_default false // false = 'off', true = 'on'
#define displayBrightness_default 2
#define VOLUME_INCREMENT 5 //mL
#define VOLUME_MAX 50 //mL
#define VOLUME_MIN 5 //mL
#define VOLUME_DIGITS 3 // (including '-' sign)
#define DURATION_INCREMENT 5 //s
#define DURATION_MAX 2700 //s
#define DURATION_MIN 15 //s
#define DURATION_DIGITS 4
class Config
{
public:
char appNameAndVersion[sizeof(NameAndVersion)];
char *getSettingStr(byte cmdId);
Config(void);
float stepUpOscVol(void);
float stepDnOscVol(void);
float getOscVol(void);
unsigned long stepUpOscDur(void);
unsigned long stepDnOscDur(void);
unsigned long getOscDur(void);
void startOsc(void);
void stopOsc(void);
void continueOsc(void);
float stepUpPushVol(void);
float stepDnPushVol(void);
float getPushVol(void);
unsigned long stepUpPushDur(void);
unsigned long stepDnPushDur(void);
unsigned long getPushDur(void);
void startPush(void);
void stopPush(void);
float stepUpPullVol(void);
float stepDnPullVol(void);
float getPullVol(void);
unsigned long stepUpPullDur(void);
unsigned long stepDnPullDur(void);
unsigned long getPullDur(void);
void startPull(void);
void stopPull(void);
bool isMotionActive(void);
//char *getFormattedStr(byte cmdId); // Returns formatted config value associated with menu command id.
void save(void); // Saves config to EEPROM.
void load(void); // Loads config from EEPROM.
void setDefaults(void); // Sets config to default values.
void copyTo(Config *dest); // Copies current instance to destination instance.
void debugPrintState(void);
private:
AccelStepper *stepper;
void stepUpVol(float *vol); //mL
void stepDnVol(float *vol); //mL
void stepUpDur(unsigned long *dur); //s
void stepDnDur(unsigned long *dur); //s
void enable_stepper(void);
void disable_stepper(void);
bool isVolTooLarge(float vol_cc);
void inject_cc(float vol_cc, unsigned long duration);
void retract_cc(float vol_cc, unsigned long duration);
float calcStepperSpeed(unsigned long volume, unsigned long duration);
void msgERR(String messageText);
void msgAction(String messageText);
void msgLapse(unsigned long last_micros, unsigned long setting);
bool activeMotion;
unsigned long motionUnit_time_last;
unsigned long prg_osc_phaseDuration;
float prg_osc_volume;
bool prg_osc_isPushing; // either pushing or pulling
bool prg_osc_status;
unsigned long prg_push_duration;
float prg_push_volume;
bool prg_push_status;
unsigned long prg_pull_duration;
float prg_pull_volume;
bool prg_pull_status;
byte displayBrightness; // 1=25%, 2=50%, 3=75%, 4=100%
};
#endif