Lydia - Printhead
PHApp.h
Go to the documentation of this file.
1 #ifndef PHAPP_H
2 #define PHAPP_H
3 
4 
5 #include "debug_config.h"
6 #include "config.h"
7 #include "enums.h"
8 
9 #include <xmath.h>
10 #include <macros.h>
11 #include <osr-base.h>
12 #include <App.h>
13 #include <Component.h>
14 #include <Bridge.h>
15 #include <SerialMessage.h>
16 
17 #include <ArduinoLog.h>
18 
19 class POT;
20 class Relay;
21 class ModbusBridge;
22 class OmronVFD;
23 class OmronPID;
24 class Pos3Analog;
25 class StepperController;
26 class MotorLoad;
27 class StatusLight;
28 
29 #define MAX_ADDONS 5
30 
31 // test <<COMPONENT_KEY;CALL_TYPE;FLAGS;1:foo:2300:5>>
32 // test app::foo <<1;2;64;1:foo:2300:5>>
33 // test relay::_set <<51;2;64;1:set:1:0>>
34 class PHApp : public App
35 {
36 public:
37  // states
39  {
40  E_CS_OK = 0,
42  };
43  enum APP_STATE
44  {
45  RESET = 0,
46  EXTRUDING = 1,
47  STANDBY = 2,
48  ERROR = 5,
53  PID_ERROR = 20,
54  VFD_ERROR = 30,
55  FEED_ERROR = 40,
56  };
57  PHApp() : App()
58  {
59  }
60 
61  SerialMessage *com_serial;
65 
74 
77 
80 
83 
88 
92 
93  millis_t comTS;
94  millis_t loopTS;
95  millis_t wait;
96  millis_t waitTS;
97  Timer<10, millis> timer; // 10 concurrent tasks, using micros as resolution
98 
99  // error states and handling
100  short _state;
101  short _cstate;
102  short _error;
103  short getLastError()
104  {
105  return _error;
106  }
107  short setLastError(short val = 0)
108  {
109  _error = val;
110  return _error;
111  };
112  short onError(short id, short code);
113  short clearError();
114 
115  // unimpl. app states (JSON Rest)
116  short setAppState(short newState);
117  short getAppState(short val);
118 
119  // component callbacks
120  short onStop(short code = 0);
121  short onRun(short code = 0);
122  short onWarning(short code);
123 
124  // component methods
125  virtual short setup();
126  short loop();
127  virtual short list(short val0, short val1);
128  virtual short onRegisterMethods(Bridge *bridge);
129 
130  // addons
131  short loopExtruderFeed();
132  short loopModbus();
133 
134  // debugging
135  void printRegisters();
136  short reset();
137  short print(short arg1, short arg2);
138 };
139 
140 #define STATUS_WARNING_BLINK \
141  if (statusLight_0) \
142  { \
143  statusLight_0->setBlink(true); \
144  }
145 #define STATUS_WARNING_BLINK_OFF \
146  if (statusLight_0) \
147  { \
148  statusLight_0->setBlink(false); \
149  }
150 
151 #define STATUS_ERROR_BLINK \
152  if (statusLight_1) \
153  { \
154  statusLight_1->setBlink(true); \
155  }
156 #define STATUS_ERROR_BLINK_OFF \
157  if (statusLight_1) \
158  { \
159  statusLight_1->setBlink(false); \
160  }
161 
162 #define STATUS_WARNING_ON \
163  if (statusLight_0) \
164  { \
165  statusLight_0->set(1); \
166  }
167 #define STATUS_WARNING_OFF \
168  if (statusLight_0) \
169  { \
170  statusLight_0->set(0); \
171  }
172 #define STATUS_ERROR_ON \
173  if (statusLight_1) \
174  { \
175  statusLight_1->set(1); \
176  }
177 #define STATUS_ERROR_OFF \
178  if (statusLight_1) \
179  { \
180  statusLight_1->set(0); \
181  }
182 
183 #endif
PHApp::list
virtual short list(short val0, short val1)
Definition: PHApp.cpp:96
PHApp::relay_3
Relay * relay_3
Definition: PHApp.h:69
PHApp::pot_2
POT * pot_2
Definition: PHApp.h:64
PHApp::extruderFeed
StepperController * extruderFeed
Definition: PHApp.h:89
PHApp::setExtruderFeed
void setExtruderFeed(StepperController *feed)
Definition: PHApp.h:90
PHApp::STANDBY
@ STANDBY
Definition: PHApp.h:47
PHApp::onWarning
short onWarning(short code)
Definition: PHApp.cpp:260
PHApp::loopTS
millis_t loopTS
Definition: PHApp.h:94
PHApp::CONTROLLER_STATE
CONTROLLER_STATE
Definition: PHApp.h:38
debug_config.h
PHApp::VFD_ERROR
@ VFD_ERROR
Definition: PHApp.h:54
Pos3Analog
Definition: 3PosAnalog.h:13
PHApp::EXTRUDING
@ EXTRUDING
Definition: PHApp.h:46
PHApp::clearError
short clearError()
Definition: PHApp.cpp:319
PHApp::timer
Timer< 10, millis > timer
Definition: PHApp.h:97
PHApp::mLoad
MotorLoad * mLoad
Definition: PHApp.h:85
OmronPID
Definition: OmronPID.h:108
ModbusBridge
Definition: ModbusBridge.h:107
PHApp::pids
OmronPID * pids
Definition: PHApp.h:87
Relay
Definition: Relay.h:17
PHApp::E_CS_ERROR
@ E_CS_ERROR
Definition: PHApp.h:41
PHApp::loopModbus
short loopModbus()
Definition: PHApp.cpp:378
PHApp::setAppState
short setAppState(short newState)
PHApp::relay_5
Relay * relay_5
Definition: PHApp.h:71
PHApp::reset
short reset()
Definition: PHApp.cpp:84
PHApp::pot_1
POT * pot_1
Definition: PHApp.h:63
PHApp::_cstate
short _cstate
Definition: PHApp.h:101
PHApp::_error
short _error
Definition: PHApp.h:102
PHApp::waitTS
millis_t waitTS
Definition: PHApp.h:96
PHApp
Definition: PHApp.h:34
PHApp::omronVFD
OmronVFD * omronVFD
Definition: PHApp.h:86
PHApp::relay_4
Relay * relay_4
Definition: PHApp.h:70
PHApp::printRegisters
void printRegisters()
Definition: PHApp.cpp:56
PHApp::setup
virtual short setup()
Definition: PHApp.cpp:106
PHApp::PHApp
PHApp()
Definition: PHApp.h:57
PHApp::relay_6
Relay * relay_6
Definition: PHApp.h:72
PHApp::getLastError
short getLastError()
Definition: PHApp.h:103
POT
Definition: POT.h:21
PHApp::com_serial
SerialMessage * com_serial
Definition: PHApp.h:61
OmronVFD
Definition: OmronVFD.h:83
PHApp::loop
short loop()
Definition: PHApp.cpp:418
PHApp::APP_STATE
APP_STATE
Definition: PHApp.h:43
PHApp::relay_2
Relay * relay_2
Definition: PHApp.h:68
PHApp::FEED_ERROR
@ FEED_ERROR
Definition: PHApp.h:55
PHApp::CONTROL_PANEL_INVALID
@ CONTROL_PANEL_INVALID
Definition: PHApp.h:52
PHApp::print
short print(short arg1, short arg2)
Definition: PHApp.cpp:45
StatusLight
Definition: StatusLight.h:16
PHApp::onError
short onError(short id, short code)
Definition: PHApp.cpp:278
PHApp::PID_TIMEOUT
@ PID_TIMEOUT
Definition: PHApp.h:50
PHApp::relay_0
Relay * relay_0
Definition: PHApp.h:66
PHApp::getExtruderFeed
StepperController * getExtruderFeed()
Definition: PHApp.h:91
PHApp::getAppState
short getAppState(short val)
Definition: PHApp.cpp:425
PHApp::relay_7
Relay * relay_7
Definition: PHApp.h:73
PHApp::comTS
millis_t comTS
Definition: PHApp.h:93
PHApp::pos3Analog_1
Pos3Analog * pos3Analog_1
Definition: PHApp.h:76
PHApp::stepperController_1
StepperController * stepperController_1
Definition: PHApp.h:79
PHApp::_state
short _state
Definition: PHApp.h:100
PHApp::RESET
@ RESET
Definition: PHApp.h:45
PHApp::stepperController_0
StepperController * stepperController_0
Definition: PHApp.h:78
PHApp::statusLight_1
StatusLight * statusLight_1
Definition: PHApp.h:82
PHApp::FEED_TIMEOUT
@ FEED_TIMEOUT
Definition: PHApp.h:51
PHApp::pot_0
POT * pot_0
Definition: PHApp.h:62
PHApp::VFD_TIMEOUT
@ VFD_TIMEOUT
Definition: PHApp.h:49
PHApp::onStop
short onStop(short code=0)
Definition: PHApp.cpp:312
enums.h
config.h
PHApp::onRegisterMethods
virtual short onRegisterMethods(Bridge *bridge)
Definition: PHApp.cpp:251
PHApp::statusLight_0
StatusLight * statusLight_0
Definition: PHApp.h:81
StepperController
Definition: StepperController.h:19
PHApp::onRun
short onRun(short code=0)
Definition: PHApp.cpp:272
PHApp::setLastError
short setLastError(short val=0)
Definition: PHApp.h:107
PHApp::PID_ERROR
@ PID_ERROR
Definition: PHApp.h:53
PHApp::modbusBridge
ModbusBridge * modbusBridge
Definition: PHApp.h:84
PHApp::pos3Analog_0
Pos3Analog * pos3Analog_0
Definition: PHApp.h:75
PHApp::wait
millis_t wait
Definition: PHApp.h:95
PHApp::relay_1
Relay * relay_1
Definition: PHApp.h:67
PHApp::E_CS_OK
@ E_CS_OK
Definition: PHApp.h:40
MotorLoad
Definition: MotorLoad.h:15
PHApp::loopExtruderFeed
short loopExtruderFeed()
Definition: PHApp.cpp:329
ERROR
ERROR
Definition: enums.h:71