Numworks Epsilon  1.4.1
Graphing Calculator Operating System
led_test_controller.cpp
Go to the documentation of this file.
1 #include "led_test_controller.h"
2 extern "C" {
3 #include <assert.h>
4 }
5 
6 namespace HardwareTest {
7 
8 constexpr KDColor LEDTestController::k_LEDColors[k_numberOfColors];
9 
11  ViewController(parentResponder),
12  m_view(),
13  m_LEDColorIndex(0),
14  m_batteryTestController(this)
15 {
16 }
17 
19  return &m_view;
20 }
21 
23  if (event == Ion::Events::OK) {
24  setLEDColor(LEDColorAtIndex(m_LEDColorIndex++));
25  if (m_LEDColorIndex == k_numberOfColors) {
27  modal->displayModalViewController(&m_batteryTestController, 0.0f, 0.0f);
28  }
29  }
30  return true;
31 }
32 
34  m_LEDColorIndex = 0;
35  setLEDColor(LEDColorAtIndex(m_LEDColorIndex++));
36 }
37 
38 void LEDTestController::setLEDColor(KDColor color) {
39  Ion::LED::setColor(color);
40  m_view.LEDColorIndicatorView()->setColor(color);
41 }
42 
43 KDColor LEDTestController::LEDColorAtIndex(int i) {
44  assert(i >= 0 && i < k_numberOfColors);
45  return k_LEDColors[i];
46 }
47 
48 LEDTestController::ContentView::ContentView() :
50  m_ledColorIndicatorView(KDColorBlack),
51  m_ledColorOutlineView(KDColorBlack),
52  m_ledView(KDText::FontSize::Large),
53  m_arrowView()
54 {
55  m_ledView.setText("LED");
56 }
57 
58 SolidColorView * LEDTestController::ContentView::LEDColorIndicatorView() {
59  return &m_ledColorIndicatorView;
60 }
61 
62 void LEDTestController::ContentView::layoutSubviews() {
63  KDSize ledSize = m_ledView.minimalSizeForOptimalDisplay();
64  m_ledView.setFrame(KDRect((Ion::Display::Width-ledSize.width()-k_indicatorSize-k_indicatorMargin)/2, k_arrowLength+2*k_arrowMargin, ledSize.width(), ledSize.height()));
65  m_ledColorIndicatorView.setFrame(KDRect((Ion::Display::Width-k_indicatorSize)/2+k_indicatorMargin/2+ledSize.width()/2, k_arrowLength+2*k_arrowMargin, k_indicatorSize, k_indicatorSize));
66  m_ledColorOutlineView.setFrame(KDRect((Ion::Display::Width-k_indicatorSize)/2+k_indicatorMargin/2+ledSize.width()/2-1, k_arrowLength+2*k_arrowMargin-1, k_indicatorSize+2, k_indicatorSize+2));
67  m_arrowView.setFrame(KDRect(0, k_arrowMargin, bounds().width(), k_arrowLength));
68 }
69 
70 int LEDTestController::ContentView::numberOfSubviews() const {
71  return 4;
72 }
73 
74 View * LEDTestController::ContentView::subviewAtIndex(int index) {
75  if (index == 0) {
76  return &m_ledView;
77  }
78  if (index == 1) {
79  return &m_ledColorOutlineView;
80  }
81  if (index == 2) {
82  return &m_ledColorIndicatorView;
83  }
84  return &m_arrowView;
85 }
86 
87 }
88 
#define assert(e)
Definition: assert.h:9
constexpr int Width
Definition: display.h:26
constexpr KDCoordinate width() const
Definition: size.h:10
Responder * parentResponder() const
Definition: responder.cpp:12
Definition: text.h:8
Definition: size.h:6
constexpr KDColor KDColorWhite
Definition: color.h:42
constexpr KDColor KDColorBlack
Definition: color.h:41
void setColor(KDColor c)
Definition: led.cpp:8
Definition: rect.h:26
Definition: color.h:6
void displayModalViewController(ViewController *vc, float verticalAlignment, float horizontalAlignment, KDCoordinate topMargin=0, KDCoordinate leftMargin=0, KDCoordinate bottomMargin=0, KDCoordinate rightMargin=0)
Definition: view.h:23
constexpr Event OK
Definition: events.h:65
bool handleEvent(Ion::Events::Event event) override
LEDTestController(Responder *parentResponder)
constexpr KDCoordinate height() const
Definition: size.h:11