2 #include "../constant.h" 13 BatteryTestController::BatteryTestController(
Responder * parentResponder) :
25 if (
strcmp(m_view.batteryStateTextView()->text(), k_batteryOKText) == 0) {
36 const char * text =
Ion::Battery::voltage() < k_batteryThreshold ? k_batteryNeedChargingText : k_batteryOKText;
38 m_view.setColor(color);
39 m_view.batteryStateTextView()->setText(text);
43 void BatteryTestController::updateBatteryState(
float batteryLevel,
bool batteryCharging) {
45 const char * legend =
"Battery level: ";
46 int legendLength =
strlen(legend);
47 strlcpy(bufferLevel, legend, legendLength+1);
49 m_view.batteryLevelTextView()->setText(bufferLevel);
52 int numberOfChars = 0;
53 legend =
"Battery charging: ";
54 legendLength =
strlen(legend);
55 strlcpy(bufferCharging, legend, legendLength+1);
56 numberOfChars += legendLength;
58 if (batteryCharging) {
61 legendLength =
strlen(legend);
62 strlcpy(bufferCharging+numberOfChars, legend, legendLength+1);
63 numberOfChars += legendLength;
64 bufferCharging[numberOfChars] = 0;
65 m_view.batteryChargingTextView()->setText(bufferCharging);
68 BatteryTestController::ContentView::ContentView() :
70 m_batteryStateView(
KDText::FontSize::Large),
71 m_batteryLevelView(
KDText::FontSize::Small),
72 m_batteryChargingView(
KDText::FontSize::Small)
76 BufferTextView * BatteryTestController::ContentView::batteryStateTextView() {
77 return &m_batteryStateView;
80 BufferTextView * BatteryTestController::ContentView::batteryLevelTextView() {
81 return &m_batteryLevelView;
84 BufferTextView * BatteryTestController::ContentView::batteryChargingTextView() {
85 return &m_batteryChargingView;
90 m_batteryStateView.setBackgroundColor(color);
91 m_batteryLevelView.setBackgroundColor(color);
92 m_batteryChargingView.setBackgroundColor(color);
95 void BatteryTestController::ContentView::layoutSubviews() {
102 int BatteryTestController::ContentView::numberOfSubviews()
const {
106 View * BatteryTestController::ContentView::subviewAtIndex(
int index) {
108 return &m_batteryStateView;
111 return &m_batteryLevelView;
113 return &m_batteryChargingView;
Responder * parentResponder() const
bool handleEvent(Ion::Events::Event event) override
size_t strlcpy(char *dst, const char *src, size_t len)
constexpr KDColor KDColorWhite
size_t strlen(const char *s)
static constexpr int LargeNumberOfSignificantDigits
void displayModalViewController(ViewController *vc, float verticalAlignment, float horizontalAlignment, KDCoordinate topMargin=0, KDCoordinate leftMargin=0, KDCoordinate bottomMargin=0, KDCoordinate rightMargin=0)
constexpr KDColor KDColorRed
constexpr KDColor KDColorGreen
static constexpr KDSize charSize(FontSize size=FontSize::Large)
virtual void setColor(KDColor color)
int strcmp(const char *s1, const char *s2)
void viewWillAppear() override
ViewController * USBController()
constexpr KDCoordinate height() const