ERIS CORE

◆ update()

void FLASHMEM AppManager::update ( )

this is the main update loop for ErisCore

AppManager update executes single update of the state machine.

Definition at line 148 of file AppManager.cpp.

148  {
149  elapsedMicros app_time;
150  uint32_t heapTop;
151  uint32_t drt;
152  bool touch_updated;
153  bool update_analog;
154  AppBaseClass *node;
155  bool monitor_update;
156  int32_t te;
157 
158  te = touched_elapsed;
159 
160  monitor_update = (monitor_dd_update_timer > APPMANAGER_MONITOR_DD_UPDATE_RATE_MSEC);
161  cycle_time=0;
162  drt = display_refresh_time;
163  touch_updated = false;
164  update_analog = false;
165  node = root;
166 
167  //requestArmSetClock(CPU_BASE_FREQ);
168 
169  if (node == 0){
170  Serial.println(F("AppManager::update called without an application initalized"));
171  return;
172  }
173 
174  //update loop is directed by the state variable
175  switch(state){
176  case redraw_background:
177  app_time=0;
178  if (!draw.busy() || 1){
179  data->update(RENDER,(int32_t)0);
181  requestArmSetClock(CPU_BOOST_MAX_FREQ);
183  data->update(AM_REDRAW_BG,(int32_t)app_time);
184  requestArmSetClock(CPU_BASE_FREQ);
185  } else Serial.println(F("M bad chunk"));
186  }
187  if ((data->read(RENDER) == 0) && animated_wallpaper.isFrameComplete()){
188  data->update(RENDER,(int32_t)1);
190  }
191  break;
192 
193  case redraw_wait://idle render time to give the screen refresh a head start
194  if(exclusive_app_render && (draw.busy()==false || drt > 40)) state = redraw_objects;
195  else if(!exclusive_app_render && (draw.busy()==false || drt > 24)) state = redraw_background;
196  //execute on next state transition
197  if (state != redraw_wait){
198  //update analog inputs
199  update_analog = analog.update();
200  touch.update();
201  touch_updated = true;
202  //note: this is a good place for application manager housekeeping tasks where screen access is not required
203  data->update(AM_AUDIO_CPU_MAX,(float32_t)AudioProcessorUsageMax());
204  float32_t cpu;
205  cpu = AudioProcessorUsage();
206  data->update(AM_AUDIO_CPU,(float32_t)cpu);
207  data->update(AM_AUDIO_MEM_MAX,(int32_t)AudioMemoryUsageMax());
208  data->update(AM_AUDIO_MEM,(int32_t)AudioMemoryUsage());
209  }
210  break;
211 
212  case redraw_render:
213  PXP_finish(); //make sure any PXP operations are complete
214  //draw.updateScreenAsync(false);
215  if(draw.busy()==false){
217  data->update(RENDER_PERIOD,(int32_t)drt);
218  data->update(RENDER,(int32_t)4);
219  data->increment(RENDER_FRAME);
220  app_time=0;
221  state = redraw_wait;
223  }
224  break;
225 
226  case redraw_objects:
227  node = root;
228  if (exclusive_app_render == false){
229  do{
230  app_time=0;
231  if (node->et_render_period > node->render_period_max) node->render_period_max = node->et_render_period;
232  node->render(); //update active window
233  node->render_cpu_time = app_time;
234  if (node->render_cpu_time > node->render_cpu_time_max){
235  node->render_cpu_time_max = node->render_cpu_time;
236  }
237  //update the data dictionary
238  node->et_render_period =0;
239  node=node->next_app_node;//check next node
240  }while(node !=NULL);
241  };
242  data->update(RENDER,(int32_t)2);
243  data->increment(UPDATE_CALLS);
245  break;
246 
247  case redraw_popup:
248  app_time=0;
249  //draw any popups
252  if (node != 0){
253  //Serial.println(F("AppManager::redraw_popup"));
254  node->render();
255  }
256  }
257  data->update(RENDER,(int32_t)3);
258  state = redraw_render;
259  break;
260  }
261  //always call the apps updateRT function on every loop
262 
263  data->increment(RT_CALLS);
264  node = root;
265  bool isactive_child;
266  do{
267  app_time=0;
268  if (node->update_priority > node->update_priority_counter){
269  node->update_priority_counter++;
270  }else{
271  node->update_priority_counter = 0;
272  if (node->et_update_period > node->update_period_max) node->update_period_max = node->et_update_period;
273  node->update(); //real time update (always called)
274  node->update_cpu_time = app_time;
276  node->et_update_period =0;
277  }
278  isactive_child = false;
279  if (node->id == active_app_id && !draw.busy()) {
280  if (p_active_app != node){
282  node->onFocus();
283  p_active_app = node;
284  }
285  }
286  if (node->parent_node!=NULL){if(node->parent_node->id == active_app_id){isactive_child = true;}}; //send event triggers to any child apps
287  if (node->id == active_app_id || isactive_child) {
288  //Serial.print("AppManager::updating active application");Serial.println(active_app_id);
289  //trigger any events and then call the update function for this 'active' app or child node
290  if (update_analog){
291  data->update(AM_AN1,(int32_t)analog.readAN1());
292  data->update(AM_AN2,(int32_t)analog.readAN2());
293  data->update(AM_AN3,(int32_t)analog.readAN3());
294  data->update(AM_AN4,(int32_t)analog.readAN4());
295 
300  }
301  data->update("TOUCHED_ELAPSED",(int32_t)te);
302  if (touch_updated == true && touch.touched()) {
303  p = touch.getPoint();
304  data->update("TOUCH_Z",(int32_t)p.z);
305 
306  if ((node->touch_state == 0) && (te > 250) ){
307  node->onTouch(p.x, p.y);
308  node->touch_state=1;
309  touched_elapsed = 0;
310  } else{
311  node->onTouchDrag(p.x, p.y);
312  }
313  } else if (node->touch_state==1){
314  node->touch_state=0;
315  node->onTouchRelease(p.x, p.y);
316  }
317  }
318  node->cycle_time = cycle_time;
319  if (node->cycle_time > node->cycle_time_max){
320  node->cycle_time_max = node->cycle_time;
321  }
322  node=node->next_app_node;//check next node
323  }while(node !=NULL);
324 
325  if (cycle_time > cycle_time_max){
327  } else{
328  //delayMicroseconds((cycle_time_max - cycle_time)/100);
329  }
330 
331  if(monitor_update){
333  data->update(AM_LOOP_TIME,(int32_t)cycle_time_max);
334  data->update(AM_SERIAL_AVAIL,(int32_t)Serial.availableForWrite());
335  //data->update("FRAME_PTR1",(int32_t)draw.getFrameAddress());
336  //data->update("FRAME_PTR2",(int32_t)render.getFrameAddress());
337  int32_t free_mem;
338  void* htop;
339  free_mem = 1000;
340  cycle_time_max*=0.999;
341  htop = malloc(1000);
342  while (htop){
343  //memset(htop,0x5A,1000);
344  heapTop = (uint32_t) htop;
345  free(htop);
346  free_mem += 1000;
347  htop = malloc(free_mem);
348  }
349 
350  data->update(FREE_MEM,(int32_t)(free_mem - 1000));
351  data->update(FREE_HEAP,(int32_t)(0x20280000 - heapTop));
352  data->update(FREE_LOCAL,(int32_t)(0x2007F000 - (uint32_t)(&heapTop)));
353  data->update(FREE_STACK,(int32_t)FreeStack());
354 
355  heapTop = 0;
356  data->update(CPU_TEMP,(float32_t)tempmonGetTemp());
357  AudioProcessorUsageMaxReset();
358  AudioMemoryUsageMaxReset();
359  }
360 };
ILI9341_t3_ERIS draw(TFT_CS, TFT_DC, TFT_RESET, TFT_MOSI, TFT_SCLK, TFT_MISO)
Touch touch(CS_TOUCH)
@ redraw_objects
Definition: AppManager.h:29
@ redraw_popup
Definition: AppManager.h:31
@ redraw_wait
Definition: AppManager.h:27
@ redraw_render
Definition: AppManager.h:30
@ redraw_background
Definition: AppManager.h:28
void PXP_finish()
Definition: T4_PXP.cpp:307
bool update()
update returns true if a change is detected; false otherwise update is rate limited....
Definition: AnalogInputs.h:49
uint16_t readAN4()
Definition: AnalogInputs.h:84
float freadAN2()
Definition: AnalogInputs.h:88
float freadAN3()
Definition: AnalogInputs.h:89
float freadAN1()
Definition: AnalogInputs.h:87
uint16_t readAN1()
Definition: AnalogInputs.h:81
uint16_t readAN3()
Definition: AnalogInputs.h:83
float freadAN4()
Definition: AnalogInputs.h:90
uint16_t readAN2()
Definition: AnalogInputs.h:82
bool isFrameComplete()
bool getNextFrameChunk()
virtual void update()
update loop
Definition: AppBaseClass.h:171
bool touch_state
Definition: AppBaseClass.h:45
uint16_t update_priority_counter
Definition: AppBaseClass.h:53
uint16_t cycle_time_max
Definition: AppBaseClass.h:59
uint16_t id
Definition: AppBaseClass.h:46
virtual void onFocusLost()
Event handler called when the app loses focus.
Definition: AppBaseClass.h:184
virtual void onTouchDrag(uint16_t t_x, uint16_t t_y)
Event handler for touch drag.
Definition: AppBaseClass.h:201
AppBaseClass * next_app_node
Definition: AppBaseClass.h:44
virtual void onFocus()
Event handler called when the app gains focus.
Definition: AppBaseClass.h:178
virtual void onTouch(uint16_t t_x, uint16_t t_y)
Event handler called on touch.
Definition: AppBaseClass.h:192
uint16_t update_cpu_time
Definition: AppBaseClass.h:56
uint16_t update_cpu_time_max
Definition: AppBaseClass.h:57
virtual void onAnalog3(uint16_t uval, float fval)
Event handler for analog 3 event.
Definition: AppBaseClass.h:232
virtual void onAnalog1(uint16_t uval, float fval)
Event handler for analog 1 event.
Definition: AppBaseClass.h:216
uint16_t render_cpu_time_max
Definition: AppBaseClass.h:55
elapsedMicros et_render_period
Definition: AppBaseClass.h:60
virtual void render()
render loop
Definition: AppBaseClass.h:165
uint16_t update_priority
Definition: AppBaseClass.h:52
uint16_t update_period_max
Definition: AppBaseClass.h:63
elapsedMicros et_update_period
Definition: AppBaseClass.h:62
virtual void onAnalog2(uint16_t uval, float fval)
Event handler for analog 2 event.
Definition: AppBaseClass.h:224
uint16_t cycle_time
Definition: AppBaseClass.h:58
virtual void onTouchRelease(uint16_t t_x, uint16_t t_y)
Event handler for touch release.
Definition: AppBaseClass.h:208
AppBaseClass * parent_node
Definition: AppBaseClass.h:42
uint16_t render_cpu_time
Definition: AppBaseClass.h:54
uint16_t render_period_max
Definition: AppBaseClass.h:61
virtual void onAnalog4(uint16_t uval, float fval)
Event handler for analog 4 event.
Definition: AppBaseClass.h:240
base class definition / implementation from which all app classes will be derived and override
Definition: AppBaseClass.h:34
AppBaseClass * root
Definition: AppManager.h:38
uint16_t cycle_time_max
Definition: AppManager.h:42
AppBaseClass * p_active_app
Definition: AppManager.h:39
elapsedMillis touched_elapsed
Definition: AppManager.h:46
bool exclusive_app_render
Definition: AppManager.h:55
AnalogInputs analog
Definition: AppManager.h:37
elapsedMillis display_refresh_time
Definition: AppManager.h:43
elapsedMillis monitor_dd_update_timer
Definition: AppManager.h:45
loopState state
Definition: AppManager.h:48
SvcDataDictionary * data
Definition: AppManager.h:63
TS_Point p
Definition: AppManager.h:49
AppBaseClass * getApp(uint16_t id)
provides an interface for apps to request another app object by id
Definition: AppManager.cpp:376
uint8_t app_popup_stack_index
Definition: AppManager.h:54
elapsedMicros cycle_time
Definition: AppManager.h:44
uint16_t app_popup_stack[8]
Definition: AppManager.h:52
Animation animated_wallpaper
Definition: AppManager.h:47
bool requestArmSetClock(uint32_t requested_cpu_frequency)
provides an interface for apps to request cpu freq change note: this is only a request....
Definition: AppManager.cpp:603
uint16_t active_app_id
Definition: AppManager.h:41
bool updateScreenAsyncFrom(ILI9341_t3_ERIS *draw, bool update_cont)
bool busy()
tft busy check
void bltSDAnimationFullScreen(Animation *an)
renders an image chunk using the information provided by Animation parameter This function is used to...
int32_t read(const char *key)
returns the int32_t value of the record
bool increment(const char *key)
increments the value of a global record creates a new record if one does not exist and initializes ...
bool update(const char *key, int32_t val, uint32_t *owner)
update the value of an owned record creates a new record if one does not exist and initializes its ...
void update()
Definition: touch.cpp:34
bool touched()
Definition: touch.cpp:105
TS_Point getPoint()
Definition: touch.cpp:111

References active_app_id, analog, animated_wallpaper, app_popup_stack, app_popup_stack_index, ILI9341_t3_ERIS::bltSDAnimationFullScreen(), ILI9341_t3_ERIS::busy(), AppBaseClass::cycle_time, cycle_time, AppBaseClass::cycle_time_max, cycle_time_max, data, display_refresh_time, draw, AppBaseClass::et_render_period, AppBaseClass::et_update_period, exclusive_app_render, AnalogInputs::freadAN1(), AnalogInputs::freadAN2(), AnalogInputs::freadAN3(), AnalogInputs::freadAN4(), getApp(), Animation::getNextFrameChunk(), Touch::getPoint(), AppBaseClass::id, SvcDataDictionary::increment(), Animation::isFrameComplete(), monitor_dd_update_timer, AppBaseClass::next_app_node, AppBaseClass::onAnalog1(), AppBaseClass::onAnalog2(), AppBaseClass::onAnalog3(), AppBaseClass::onAnalog4(), AppBaseClass::onFocus(), AppBaseClass::onFocusLost(), AppBaseClass::onTouch(), AppBaseClass::onTouchDrag(), AppBaseClass::onTouchRelease(), p, p_active_app, AppBaseClass::parent_node, PXP_finish(), SvcDataDictionary::read(), AnalogInputs::readAN1(), AnalogInputs::readAN2(), AnalogInputs::readAN3(), AnalogInputs::readAN4(), redraw_background, redraw_objects, redraw_popup, redraw_render, redraw_wait, AppBaseClass::render(), AppBaseClass::render_cpu_time, AppBaseClass::render_cpu_time_max, AppBaseClass::render_period_max, requestArmSetClock(), root, state, touch, AppBaseClass::touch_state, Touch::touched(), touched_elapsed, AnalogInputs::update(), AppBaseClass::update(), Touch::update(), SvcDataDictionary::update(), AppBaseClass::update_cpu_time, AppBaseClass::update_cpu_time_max, AppBaseClass::update_period_max, AppBaseClass::update_priority, AppBaseClass::update_priority_counter, and ILI9341_t3_ERIS::updateScreenAsyncFrom().

Referenced by loop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: