AWind
Oscilloscope.h
1 /*
2  AWind.h - Arduino window library support for Color TFT LCD Boards
3  Copyright (C)2014 Andrei Degtiarev. All right reserved
4 
5  You can find the latest version of the library at
6  https://github.com/AndreiDegtiarev/AWind
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the CC BY-NC-SA 3.0 license.
10  Please see the included documents for further information.
11 
12  Commercial use of this library requires you to buy a license that
13  will allow commercial use. This includes using the library,
14  modified or not, as a tool to sell products.
15 
16  The license applies to all part of the library including the
17  examples and tools supplied with the library.
18 */
19 #pragma once
20 #include "MainWindow.h"
21 #include "ChartWindow.h"
22 #include "TextBoxNumber.h"
23 #include "DefaultDecorators.h"
24 #include "Label.h"
27 {
28  VoltmeterSensor *_voltmeter;
29  ChartWindow *_chartWnd;
30  TextBoxNumber *_txtTimeStep;
31  TextBoxNumber *_txtBufSize;
32  TextBoxNumber *_txtBuf;
33  TextBoxNumber *_txtMinV;
34  TextBoxNumber *_txtMaxV;
35  DecoratorAxis *_chartYAxis;
36 public:
37  Oscilloscope(int wnd_width,int wnd_height):MainWindow(wnd_width,wnd_height)
38  {
39  }
40  void Initialize(VoltmeterSensor *voltmeter,int buf_size,float minV,float maxV)
41  {
42  SetDecorators(Environment::Get()->FindDecorators(F("Window")));
43  int wnd_width=Width();
44  int wnd_height=Height();
45  _voltmeter=voltmeter;
46  int x=2;
47  int y=2;
48  int width=70;
49  int height=30;
50 
51  LinkedList<Decorator> *txtDecorators= Environment::Get()->FindDecorators(F("EditTextBox"));
52 
53  Label *labelTimeSTep=new Label(x,y+10,width,height,F("Tstep mus:"));
54  initTextBox(labelTimeSTep,true);
55  x+=width;
56  _txtTimeStep=new TextBoxNumber(x,y,width,height,0);
57  _txtTimeStep->SetNumber(voltmeter->TimeStep());
58  initTextBox(_txtTimeStep,false);
59  x+=width*1.2;
60  Label *labelBufsize=new Label(x,y+10,width,height,F("Buf. size:"));
61  initTextBox(labelBufsize,true);
62  x+=width*1.1;
63  _txtBufSize=new TextBoxNumber(x,y,width,height,0);
64  initTextBox(_txtBufSize,false);
65  _txtBufSize->SetNumber(buf_size);
66  x=1;
67  y=_txtBufSize->Top()+_txtBufSize->Height()+1;
68  int cy=wnd_height-y-height*1.2;
69  int axis_y_margins=2;
70  _chartYAxis=new DecoratorAxis(DecoratorAxis::VerticalLeft,SmallFont,cy-axis_y_margins*2,minV,maxV,5);
71  _chartYAxis->SetOffset(4,axis_y_margins);
72  _chartWnd=new ChartWindow(NULL,_chartYAxis,x,y,wnd_width-2,cy);
73  //_chartWnd->SetMinMaxY(minV,maxV);
74  _chartWnd->AddDecorator(new Decorator3DRect(Color::White,Color::Gray));
75  _chartWnd->AddDecorator(new DecoratorColor(Color::Black));
76  _chartWnd->AddDecorator(_chartYAxis);
77  AddChild(_chartWnd);
78  y=_chartWnd->Top()+_chartWnd->Height()+3;
79 
80  Label *labelMinV=new Label(x,y+10,width,height,F("Vmin/max:"));
81  x+=width;
82  _txtMinV=new TextBoxNumber(x,y,width-10,height,1);
83  _txtMinV->SetNumber(minV);
84  x+=width;
85  _txtMaxV=new TextBoxNumber(x,y,width-10,height,1);
86  _txtMaxV->SetNumber(maxV);
87  x+=width;
88 
89  initTextBox(labelMinV,true);
90  initTextBox(_txtMinV,false);
91  initTextBox(_txtMaxV,false);
92  }
93  void initTextBox(TextBox *textBox,bool isLabel)
94  {
95  AddChild(textBox);
96  if(!isLabel)
97  {
98  textBox->RegisterContentChangedReceiver(this);
99  textBox->SetMargins(0,7);
100  textBox->SetFont(BigFont);
101  ((TextBoxNumber *)textBox)->SetIsReadOnly(false);
102  }
103 
104  }
105  ChartWindow *ChartWnd()
106  {
107  return _chartWnd;
108  }
110  {
111  if(textBox == _txtMinV || textBox == _txtMaxV)
112  {
113  _chartYAxis->SetMinMax(_txtMinV->GetNumber(),_txtMaxV->GetNumber());
114  _chartWnd->Invalidate();
115  }
116  else if(textBox == _txtTimeStep)
117  {
118  _voltmeter->SetTimeStep(_txtTimeStep->GetNumber());
119  }
120  else if(textBox == _txtBufSize)
121  {
122  _voltmeter->Buffer()->SetSize(_txtBufSize->GetNumber());
123  _txtBufSize->SetNumber(_voltmeter->Buffer()->Size());
124  }
125  }
126 };
Base class for all window objects. Provides basic window functionality.
Definition: Window.h:34
Osciloscope main window.
Definition: Oscilloscope.h:26
void SetFont(uint8_t *font)
Sets font.
Definition: TextBox.h:64
Base class for window with text content.
Definition: TextBox.h:30
Interface that provides content change notifications (like text is changed in text box) from child wi...
Definition: IContentChangedEventReceiver.h:24
static Environment * Get()
Returns singltone instance of environment.
Definition: Environment.h:44
Vertcal axis with the labels left to the axis.
Definition: DecoratorPrimitives.h:152
Text box for numbers.
Definition: TextBoxNumber.h:24
void SetOffset(int offsetX, int offsetY)
Sets decorator offset in the parent window coordinate system.
Definition: DecoratorPrimitives.h:188
Axis decorator primitive. It is shared between gauge and chart objects. Overriden members description...
Definition: DecoratorPrimitives.h:145
Chart window implement XY plots.
Definition: ChartWindow.h:30
int Height()
Returns window height.
Definition: Window.h:189
void Invalidate()
If function is called than the window manager updates the window.
Definition: Window.h:157
Decorator primitive for 3D rectangle. Overriden members description see Decorator class documentation...
Definition: DecoratorPrimitives.h:130
Decorator primitive that sets current color. Overriden members description see Decorator class docume...
Definition: DecoratorPrimitives.h:24
void AddChild(Window *window)
Adds window child window.
Definition: Window.h:194
void RegisterContentChangedReceiver(IContentChangedEventReceiver *event)
Application need to call this function if it wants receive notification about this window content cha...
Definition: TextBox.h:53
void SetNumber(float number)
Initialize window with number.
Definition: TextBoxNumber.h:74
void AddDecorator(Decorator *decorator)
Adds decorator to the decaorator list.
Definition: Window.h:86
MainWindow(int width, int height)
Constructor.
Definition: MainWindow.h:52
int Top()
Returns window top coordinate relative to the parent window.
Definition: Window.h:179
void SetMinMax(float minVal, float maxVal)
Sets min and max for label values.
Definition: DecoratorPrimitives.h:200
virtual void SetDecorators(DecoratorList *decorators)
Sets window decorators list.
Definition: Window.h:76
void NotifyContentChanged(Window *textBox)
Has to be implemented in target class.
Definition: Oscilloscope.h:109
Base class for main application window. Each application has to have one main window, which is root parent for all other application windows.
Definition: MainWindow.h:38
DecoratorList * FindDecorators(const __FlashStringHelper *id)
Finds registered decorators by the name.
Definition: Environment.h:59
int Width()
Returns window width.
Definition: Window.h:184
Implement Label control.
Definition: Label.h:24
void SetMargins(int offset_x, int offset_y)
Defines offset from left and top for text.
Definition: TextBox.h:58