6663b6c9
adorian
projet complet av...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
#include "battery_test_controller.h"
#include "../constant.h"
#include "app.h"
extern "C" {
#include <assert.h>
}
#include <poincare.h>
using namespace Poincare;
namespace HardwareTest {
BatteryTestController::BatteryTestController(Responder * parentResponder) :
ViewController(parentResponder),
m_view()
{
}
View * BatteryTestController::view() {
return &m_view;
}
bool BatteryTestController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::OK) {
if (strcmp(m_view.batteryStateTextView()->text(), k_batteryOKText) == 0) {
// Handled in WizardViewController
return false;
}
}
updateBatteryState(Ion::Battery::voltage(), Ion::Battery::isCharging());
return true;
}
void BatteryTestController::viewWillAppear() {
const char * text = Ion::Battery::level() != Ion::Battery::Charge::FULL ? k_batteryNeedChargingText : k_batteryOKText;
KDColor color = Ion::Battery::level() != Ion::Battery::Charge::FULL ? KDColorRed : KDColorGreen;
m_view.setColor(color);
m_view.batteryStateTextView()->setText(text);
updateBatteryState(Ion::Battery::voltage(), Ion::Battery::isCharging());
}
void BatteryTestController::updateBatteryState(float batteryLevel, bool batteryCharging) {
char bufferLevel[ContentView::k_maxNumberOfCharacters + PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
const char * legend = "Battery level: ";
int legendLength = strlen(legend);
strlcpy(bufferLevel, legend, legendLength+1);
PrintFloat::convertFloatToText<float>(batteryLevel, bufferLevel+legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, PrintFloat::Mode::Decimal);
m_view.batteryLevelTextView()->setText(bufferLevel);
char bufferCharging[ContentView::k_maxNumberOfCharacters + PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
int numberOfChars = 0;
legend = "Battery charging: ";
legendLength = strlen(legend);
strlcpy(bufferCharging, legend, legendLength+1);
numberOfChars += legendLength;
legend = "no";
if (batteryCharging) {
legend = "yes";
}
legendLength = strlen(legend);
strlcpy(bufferCharging+numberOfChars, legend, legendLength+1);
numberOfChars += legendLength;
bufferCharging[numberOfChars] = 0;
m_view.batteryChargingTextView()->setText(bufferCharging);
}
BatteryTestController::ContentView::ContentView() :
SolidColorView(KDColorWhite),
m_batteryStateView(KDText::FontSize::Large),
m_batteryLevelView(KDText::FontSize::Small),
m_batteryChargingView(KDText::FontSize::Small)
{
}
BufferTextView * BatteryTestController::ContentView::batteryStateTextView() {
return &m_batteryStateView;
}
BufferTextView * BatteryTestController::ContentView::batteryLevelTextView() {
return &m_batteryLevelView;
}
BufferTextView * BatteryTestController::ContentView::batteryChargingTextView() {
return &m_batteryChargingView;
}
void BatteryTestController::ContentView::setColor(KDColor color) {
SolidColorView::setColor(color);
m_batteryStateView.setBackgroundColor(color);
m_batteryLevelView.setBackgroundColor(color);
m_batteryChargingView.setBackgroundColor(color);
}
void BatteryTestController::ContentView::layoutSubviews() {
m_batteryStateView.setFrame(KDRect(0, 0, Ion::Display::Width, Ion::Display::Height/2));
KDSize textSize = KDText::charSize(KDText::FontSize::Small);
m_batteryLevelView.setFrame(KDRect(0, Ion::Display::Height-2*textSize.height(), Ion::Display::Width, textSize.height()));
m_batteryChargingView.setFrame(KDRect(0, Ion::Display::Height-textSize.height(), Ion::Display::Width, textSize.height()));
}
int BatteryTestController::ContentView::numberOfSubviews() const {
return 3;
}
View * BatteryTestController::ContentView::subviewAtIndex(int index) {
if (index == 0) {
return &m_batteryStateView;
}
if (index == 1) {
return &m_batteryLevelView;
}
return &m_batteryChargingView;
}
}
|