AWind
TabVacuum.h
1 /*
2  AWind.h - Arduino window library support for Color TFT LCD Boards
3  Copyright (C)2016 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 <Window.h>
21 #include <Label.h>
22 #include <TextBoxNumber.h>
23 #include <ATimer.h>
24 #include <GaugeBar.h>
25 #include "PumpController.h"
26 
29 {
30  TextBoxNumber *_txtPause;
31  TextBoxNumber *_txtActive;
32  Button *_btnStart;
33  Button *_btnStop;
34  GaugeBar * _gaugeBar;
35  ATimer _pauseTimer;
36  ATimer _activeTimer;
37  ATimer _updateTimer;
38  PumpController *_pumpController;
39 public:
40  TabVacuum(PumpController *pumpController,const __FlashStringHelper * name, int left, int top, int width, int height) :Window(name, left, top, width, height)
41  {
42  _pumpController = pumpController;
43 
44  SetDecorators(Environment::Get()->FindDecorators(F("Window")));
45 
46  initLabel(new Label(0, 0, 0, 0, F("Active")));
47  initLabel(new Label(0, 0, 0, 0, F("min")));
48  initLabel(new Label(0, 0, 0, 0, F("Pause")));
49  initLabel(new Label(0, 0, 0, 0, F("min")));
50 
51  _txtActive = new TextBoxNumber(0, 0, 0, 0, 0);
52  _txtActive->SetNumber(0.5);
53  initTextWindow(_txtActive);
54  _txtPause = new TextBoxNumber(0, 0, 0, 0, 0);
55  _txtPause->SetNumber(10);
56  initTextWindow(_txtPause);
57 
58  _btnStart = new Button(0, 0, 0, 0, F("Start"));
59  initButton(_btnStart);
60  _btnStart->SetMargins(20, 20);
61  _btnStop = new Button(0, 0, 0, 0, F("Stop"));
62  initButton(_btnStop);
63  _btnStop->SetMargins(30, 20);
64 
65  }
66  void initLabel(Label *label)
67  {
68  label->SetFont(BigFont);
69  AddChild(label);
70  }
71  void initTextWindow(TextBoxNumber *wnd)
72  {
73  wnd->SetDecorators(GetDecorators()); // here we save one decorator beacuse main window and text window have thae same decorator properties: black background
74  wnd->SetFont(BigFont);
75  wnd->SetMargins(5, 5);
76  wnd->SetPrecission(1);
77  wnd->SetIsReadOnly(false);
78  AddChild(wnd);
79  }
80  void initButton(Button *btn)
81  {
82  btn->RegisterTouchEventReceiver(this);
83  AddChild(btn);
84  }
86  void Initialize()
87  {
88  int x = 1;
89  int szx = Width() - 10;
90  int szy = 35;
91  int gauge_axis_margins = 5;
92  DecoratorAxis *gaugeAxis = new DecoratorAxis(DecoratorAxis::HorizontalBottom, SmallFont, szx - gauge_axis_margins * 2, 0, 100, 5);
93  gaugeAxis->SetOffset(szx, 10);
94  _gaugeBar = new GaugeBar(gaugeAxis, 5, 105, szx, szy);
95  _gaugeBar->SetFillColor(Color::LightGray);
96  _gaugeBar->SetDecorators(Environment::Get()->FindDecorators(F("EditTextBoxReadOnly")));
97  AddChild(_gaugeBar);
98 
99  Children()[0]->Move(5, 20, 50, 30);
100  Children()[1]->Move(220, 20, 50, 30);
101  Children()[2]->Move(5, 75, 50, 30);
102  Children()[3]->Move(220, 75, 50, 30);
103  _txtActive->Move(140, 15, 70, 30);
104  _txtPause->Move(140, 70, 70, 30);
105 
106  _btnStart->Move(5, 150, 135, 50);
107  _btnStop->Move(172, 150, 135, 50);
108 
109  _updateTimer.SetAutoReset(true);
110  _updateTimer.SetInterval(1*1000);
111  _activeTimer.RegisterTimerEventReceiver(this);
112  _pauseTimer.RegisterTimerEventReceiver(this);
113  _updateTimer.RegisterTimerEventReceiver(this);
114  ((MainWindow *)RootWindow())->RegisterTimer(&_activeTimer);
115  ((MainWindow *)RootWindow())->RegisterTimer(&_pauseTimer);
116  ((MainWindow *)RootWindow())->RegisterTimer(&_updateTimer);
117  _updateTimer.Enable();
118 
119  }
121  void NotifyTouch(Window *window)
122  {
123  if (window == _btnStart)
124  {
125  _pumpController->initVacuumValve();
126  _btnStart->SetDecorators(Environment::Get()->FindDecorators(F("RedRectangle")));
127  _activeTimer.SetInterval(_txtActive->GetNumber() * 60 * 1000);
128  _pauseTimer.SetInterval(_txtPause->GetNumber() * 60 * 1000);
129  _txtActive->SetIsReadOnly(true);
130  _txtPause->SetIsReadOnly(true);
131  _activeTimer.Enable();
132  _gaugeBar->SetBarColor(Color::Red);
133  _gaugeBar->SetMinMax(0, _txtActive->GetNumber()*60*1000);
134  _gaugeBar->Invalidate();
135  _txtActive->Invalidate();
136  _txtPause->Invalidate();
137  _pumpController->startVacuum();
138  }
139  else if (window == _btnStop)
140  {
141  _pumpController->stopVacuum();
142  _btnStart->SetDecorators(Environment::Get()->FindDecorators(F("Button")));
143  _btnStart->Invalidate();
144  _activeTimer.Reset();
145  _pauseTimer.Reset();
146  _gaugeBar->SetValue(0);
147  _txtActive->SetIsReadOnly(false);
148  _txtPause->SetIsReadOnly(false);
149  _txtActive->Invalidate();
150  _txtPause->Invalidate();
151 
152  }
153  }
155  void NotifyTimer(ATimer *timer)
156  {
157  if (timer == &_updateTimer)
158  {
159  if (_activeTimer.IsEnabled())
160  {
161  out << F("Active timer: ")<<_activeTimer.Elapsed()<<F(" ");
162  _gaugeBar->SetValue(_activeTimer.Elapsed());
163  }
164  else if (_pauseTimer.IsEnabled())
165  {
166  out << F("Pause timer: ") << _activeTimer.Elapsed() << F(" ");
167  _gaugeBar->SetValue(_pauseTimer.Elapsed());
168  }
169  }
170  else if (timer == &_activeTimer)
171  {
172  _pumpController->stopVacuum();
173  _activeTimer.Reset();
174  _pauseTimer.Enable();
175  _gaugeBar->SetValue(0);
176  _gaugeBar->SetBarColor(Color::Green);
177  _gaugeBar->SetMinMax(0, _txtPause->GetNumber() * 60 * 1000);
178  }
179  else if (timer == &_pauseTimer)
180  {
181  _pauseTimer.Reset();
182  _activeTimer.Enable();
183  _gaugeBar->SetValue(0);
184  _gaugeBar->SetBarColor(Color::Red);
185  _gaugeBar->SetMinMax(0, _txtActive->GetNumber() * 60 * 1000);
186  _pumpController->startVacuum();
187  }
188 
189  }
190 };
void NotifyTouch(Window *window)
Events routing for gui interaction (see RegisterTouchEventReceiver and public ITouchEventReceiver dec...
Definition: TabVacuum.h:121
Interface that provides screen touch notifications. If you want receive this notification in the targ...
Definition: ITimerEventReceiver.h:24
void SetBarColor(Color color)
Set Bar color.
Definition: GaugeBar.h:47
Definition: ATimer.h:28
void RegisterTouchEventReceiver(ITouchEventReceiver *touchEventReceiver)
Registers receiver for touch event.
Definition: Window.h:102
DecoratorList * GetDecorators()
Returns window decorators list.
Definition: Window.h:81
Base class for all window objects. Provides basic window functionality.
Definition: Window.h:34
bool IsEnabled()
Returns true if timer is active.
Definition: ATimer.h:58
float SetValue(float value)
Sets display value.
Definition: Gauge.h:75
void SetFont(uint8_t *font)
Sets font.
Definition: TextBox.h:64
void SetIsReadOnly(bool isReadOnly)
Defines whether window is readonly.
Definition: TextBoxNumber.h:64
void SetInterval(uint32_t milliseconds)
Set timer interval in milliseconds.
Definition: ATimer.h:53
void Enable()
Starts timer.
Definition: ATimer.h:63
Not implemented yet.
Definition: DecoratorPrimitives.h:151
void Reset()
Disabels timer.
Definition: ATimer.h:69
static Environment * Get()
Returns singltone instance of environment.
Definition: Environment.h:44
Window * RootWindow()
Returns pointer to root window. MainWindow does not have any parents.
Definition: Window.h:133
uint32_t Elapsed()
Returns actual elapsed time.
Definition: ATimer.h:74
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
virtual void Move(int left, int top, int width, int height)
Moves and resizes window relativly to the parent window.
Definition: Window.h:149
Axis decorator primitive. It is shared between gauge and chart objects. Overriden members description...
Definition: DecoratorPrimitives.h:145
void RegisterTimerEventReceiver(ITimerEventReceiver *timerEventReceiver)
Registers event receiver.
Definition: ATimer.h:43
LinkedList< Window > & Children()
Returns list of children window.
Definition: Window.h:223
void Invalidate()
If function is called than the window manager updates the window.
Definition: Window.h:157
void NotifyTimer(ATimer *timer)
Events routing for timer.
Definition: TabVacuum.h:155
Tab that implements GUI to vacuum controller.
Definition: TabVacuum.h:28
void Initialize()
Initilizes positions of child windows + timers.
Definition: TabVacuum.h:86
Window(const __FlashStringHelper *name, int left, int top, int width, int height)
Constructor.
Definition: Window.h:60
void AddChild(Window *window)
Adds window child window.
Definition: Window.h:194
void SetNumber(float number)
Initialize window with number.
Definition: TextBoxNumber.h:74
virtual void SetDecorators(DecoratorList *decorators)
Sets window decorators list.
Definition: Window.h:76
Implement button control.
Definition: Button.h:24
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
void SetAutoReset(bool isAutoreset)
Set whether timer is in autoreset modus.
Definition: ATimer.h:48
void SetMinMax(float minVal, float maxVal)
Sets values range.
Definition: Gauge.h:65
void SetFillColor(Color fillColor)
Sets fill color.
Definition: Gauge.h:56
Interface that provides screen touch notifications. If you want receive this notification in the targ...
Definition: ITouchEventReceiver.h:24
Implements pump control logic.
Definition: PumpController.h:22
int Width()
Returns window width.
Definition: Window.h:184
Bar gauge class.
Definition: GaugeBar.h:25
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