ERIS CORE
appScope.h
Go to the documentation of this file.
1 /**
2  * @file appScope.h
3  * @author Brian Monkaba (brian.monkaba@gmail.com)
4  * @brief
5  * @version 0.1
6  * @date 2021-08-24
7  *
8  * @copyright Copyright (c) 2021
9  *
10  */
11 #include "AppManager.h"
12 
13 /**
14  * @brief Basic Oscilloscope Applicaiton
15  *
16  */
17 class AppScope:public AppBaseClass {
18  public:
21  scope->trigger();
22  strcpy(name,"AppScope");
23  scale = 0;
24  update_priority = 0;
25  };
26 
27  protected:
29  float32_t scale;
30  void render(){
31 
32  uint16_t y_last_scope;
33  uint16_t y_last_scope_ch2;
34 
35  y_last_scope=h/2;
36  y_last_scope_ch2=h/2;
37 
38  scale = 30000.0 / ((float)scope->getPeakValue() + 0.0001);
39  if (scale > 10.0) scale = 10.0;
40  am->data->update("OSCOPE_SCALE",scale);
41  if (has_pop) draw->fillRoundRect(x,y,w,h,3,CL(0,0,0));
42  for (int16_t i=0;i<w;i++){
43  int16_t v;
44  float f;
45  uint16_t ch1,ch2;
46  v = scope->read(0,i) * scale;
47  f = ((v * 0.000030517578125) + 1.0) * 0.5; // 1/32768 = 0.000030517578125
48  ch1 = y + (uint16_t)(f * h);
49  if (i > 0) draw->drawLine(x + i-1,y_last_scope,x + i,ch1,ILI9341_ORANGE);
50  //draw the second channel
51  v = scope->read(1,i) * scale;
52  f = ((v * 0.000030517578125) + 1.0) * 0.5;
53  ch2 = y + (uint16_t)(f * h);
54  if (i > 0) draw->drawLine(x + i-1,y_last_scope_ch2,x + i,ch2,ILI9341_GREEN);
55  //draw x-y plot
56  if (i > 0) draw->drawLine(y_last_scope_ch2,y_last_scope,ch2,ch1,ILI9341_GREENYELLOW);
57  y_last_scope = ch1;
58  y_last_scope_ch2 = ch2;
59  }
60 
61  if (w>120 && h>60){
62  draw->setCursor(x+w - 100,y+5);
63  draw->print("scale: ");
64  draw->print(scale);
65  draw->setCursor(x+w - 100,y+20);
66  draw->print("hdiv: ");
67  draw->print(scope->getHDiv());
68  }
69  draw->drawRoundRect(x,y,w,h,4,ILI9341_MAGENTA);
70  }; //called only when the app is active
71 
72  void update(){
73  am->data->update("INPUT_PEAK",(int32_t)scope->getPeakValue());
74  /*
75  //publish the scopes math functions
76  AppManager *am = AppManager::getInstance();
77  //am->data->update("DOT",scope->getDotProduct());
78  //am->data->update("DOT_AVG",scope->getDotProductAvg());
79  am->data->update("DOT_AVG_SLOW",scope->getDotProductAvgSlow());
80  am->data->update("DOT_DELTA",scope->getDotDelta());
81  //am->data->update("DOT_DELTA_MACD",scope->getDotDeltaMACD());
82  am->data->update("DOT_ACCEL",scope->getDotAcceleration());
83  //am->data->update("DOT_MACD",scope->getDotMACD());
84  //am->data->update("EDGE_COUNT",scope->getEdgeCount());
85  //am->data->update("EDGE_COUNT_CH2",scope->getEdgeCount_ch2());
86  //am->data->update("EDGE_DELAY",scope->getEdgeDelay());
87  //am->data->update("EDGE_DELAY2",scope->getEdgeDelay2());
88  am->data->update("EDGE_DELTA",scope->getEdgeDelay()-scope->getEdgeDelay2() + 1); //min value of 1 (protect for div by zero)
89  am->data->update("INPUT_PEAK",scope->getPeakValue());
90  if(scope->getEdgeDelay()>20) am->data->update("CH1_FREQ",(int32_t)(AUDIO_SAMPLE_RATE_EXACT/(0.001* ((float32_t)scope->getEdgeDelay() + 0.00001))));
91  if(scope->getEdgeDelay2()>20) am->data->update("CH2_FREQ",(int32_t)(AUDIO_SAMPLE_RATE_EXACT/(0.001* ((float32_t)scope->getEdgeDelay2()+ 0.00001))));
92  */
93  }; //allways called even if app is not active
94 
95  void onFocus(){}; //called when given focus
96 
97  void onFocusLost(){}; //called when focus is taken
98 
99  void onTouch(uint16_t t_x, uint16_t t_y){
100  //check if touch point is within the application bounding box
101  if (t_x > x && t_x < (x + w) && t_y > y && t_y < (y + h)){
102  //is touched
103  if(!has_pop){
104  //getFocus();
105  requestPopUp();
106 
107  }else{
108  //returnFocus();
109  releasePopUp();
110  }
111  }
112  };
113  void onTouchRelease(uint16_t x, uint16_t y){
114  };
115 };
void requestPopUp(bool exclusive=false)
request popup from the AppManager will be activated by the next render loop applications in popup m...
AppManager * am
Definition: AppBaseClass.h:38
void releasePopUp()
gives up popup
ILI9341_t3_ERIS * draw
Definition: AppBaseClass.h:41
char name[MAX_NAME_LENGTH]
Definition: AppBaseClass.h:74
uint16_t update_priority
Definition: AppBaseClass.h:52
AudioDirector * ad
Definition: AppBaseClass.h:37
base class definition / implementation from which all app classes will be derived and override
Definition: AppBaseClass.h:34
SvcDataDictionary * data
Definition: AppManager.h:63
void onFocus()
Event handler called when the app gains focus.
Definition: appScope.h:95
void onTouch(uint16_t t_x, uint16_t t_y)
Event handler called on touch.
Definition: appScope.h:99
erisAudioAnalyzeScope * scope
Definition: appScope.h:25
void render()
render loop
Definition: appScope.h:30
AppScope()
Definition: appScope.h:19
void onTouchRelease(uint16_t x, uint16_t y)
Event handler for touch release.
Definition: appScope.h:113
float32_t scale
Definition: appScope.h:29
void onFocusLost()
Event handler called when the app loses focus.
Definition: appScope.h:97
void update()
update loop
Definition: appScope.h:72
Basic Oscilloscope Applicaiton.
Definition: appScope.h:17
AudioStream * getAudioStreamObjByName(const char *AudioStreamObjName)
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 ...
int16_t read(int8_t channel, uint16_t mem_index)