Numworks Epsilon  1.4.1
Graphing Calculator Operating System
usb_test_controller.cpp
Go to the documentation of this file.
1 #include "usb_test_controller.h"
2 extern "C" {
3 #include <assert.h>
4 }
5 #include <poincare.h>
6 
7 using namespace Poincare;
8 
9 namespace HardwareTest {
10 
11 USBTestController::USBTestController(Responder * parentResponder) :
12  ViewController(parentResponder),
13  Timer(1),
14  m_view(),
15  m_shouldPlugUSB(true),
16  m_resetController(this)
17 {
18 }
19 
21  return &m_view;
22 }
23 
25  return true;
26 }
27 
28 bool USBTestController::fire() {
29  if (Ion::USB::isPlugged() && m_shouldPlugUSB) {
30  m_view.USBTextView()->setText(k_USBUnplugText);
31  m_view.arrowView()->setDirection(false);
32  m_view.arrowView()->setColor(KDColorRed);
33  m_shouldPlugUSB = false;
34  return true;
35  }
36  if (!Ion::USB::isPlugged() && !m_shouldPlugUSB) {
38  modal->displayModalViewController(&m_resetController, 0.0f, 0.0f);
39  return true;
40  }
41  return false;
42 }
43 
45  m_shouldPlugUSB = true;
46  m_view.USBTextView()->setText(k_USBPlugText);
47  m_view.arrowView()->setDirection(true);
48  m_view.arrowView()->setColor(KDColorGreen);
49 }
50 
51 void USBTestController::ContentView::USBView::drawRect(KDContext * ctx, KDRect rect) const {
52  KDCoordinate width = bounds().width();
53  KDCoordinate height = bounds().height();
54  ctx->fillRect(KDRect((width-k_USBHoleWidth+10)/2, 0, k_USBHoleWidth-10, 5), KDColorBlack);
55  ctx->fillRect(KDRect((width-k_USBHoleWidth)/2, 5, k_USBHoleWidth, k_USBHoleHeight-5), KDColorBlack);
56  ctx->fillRect(KDRect((width-k_USBHoleWidth)/2, k_USBHoleHeight+k_marginHeight, k_USBHoleWidth, 25), KDColorBlack);
57  ctx->fillRect(KDRect((width-k_USBHoleWidth)/2+10, k_USBHoleHeight+k_marginHeight+10, 7, 5), KDColorWhite);
58  ctx->fillRect(KDRect((width-k_USBHoleWidth)/2+10+7+6, k_USBHoleHeight+k_marginHeight+10, 7, 5), KDColorWhite);
59  ctx->fillRect(KDRect((width-k_USBHoleWidth)/2, k_USBHoleHeight+k_marginHeight+30, k_USBHoleWidth, 50), KDColorBlack);
60  ctx->fillRect(KDRect((width-10)/2, k_USBHoleHeight+k_marginHeight+30+50, 10, 10), KDColorBlack);
61  ctx->fillRect(KDRect((width-4)/2, k_USBHoleHeight+k_marginHeight+30+50+10, 4, height-(k_USBHoleHeight+k_marginHeight+30+50+10)), KDColorBlack);
62 }
63 
64 USBTestController::ContentView::ContentView() :
66  m_USBTextView(KDText::FontSize::Large),
67  m_USBView(),
68  m_arrowView()
69 {
70 }
71 
72 BufferTextView * USBTestController::ContentView::USBTextView() {
73  return &m_USBTextView;
74 }
75 
76 ArrowView * USBTestController::ContentView::arrowView() {
77  return &m_arrowView;
78 }
79 
80 void USBTestController::ContentView::layoutSubviews() {
81  m_USBTextView.setFrame(KDRect(0, 0, bounds().width(), k_textHeight));
82  m_USBView.setFrame(KDRect(0, k_textHeight, bounds().width(), bounds().height()-k_textHeight));
83  m_arrowView.setFrame(KDRect(0, k_textHeight+USBView::k_USBHoleHeight+5, bounds().width(), USBView::k_marginHeight-10));
84 }
85 
86 int USBTestController::ContentView::numberOfSubviews() const {
87  return 3;
88 }
89 
90 View * USBTestController::ContentView::subviewAtIndex(int index) {
91  assert(index >= 0 && index < 3);
92  if(index == 0) {
93  return &m_USBTextView;
94  }
95  if (index == 2) {
96  return &m_USBView;
97  }
98  return &m_arrowView;
99 }
100 
101 }
102 
bool isPlugged()
Definition: usb.cpp:12
Definition: timer.h:15
#define assert(e)
Definition: assert.h:9
void setFrame(KDRect frame)
Definition: view.cpp:125
int16_t KDCoordinate
Definition: coordinate.h:6
Responder * parentResponder() const
Definition: responder.cpp:12
Definition: text.h:8
constexpr KDColor KDColorWhite
Definition: color.h:42
constexpr KDColor KDColorBlack
Definition: color.h:41
bool handleEvent(Ion::Events::Event e) override
Definition: rect.h:26
void fillRect(KDRect rect, KDColor color)
Definition: context_rect.cpp:8
void displayModalViewController(ViewController *vc, float verticalAlignment, float horizontalAlignment, KDCoordinate topMargin=0, KDCoordinate leftMargin=0, KDCoordinate bottomMargin=0, KDCoordinate rightMargin=0)
constexpr KDColor KDColorRed
Definition: color.h:43
Definition: view.h:23
constexpr KDColor KDColorGreen
Definition: color.h:44
#define true
Definition: stdbool.h:8