Numworks Epsilon  1.4.1
Graphing Calculator Operating System
battery_view.cpp
Go to the documentation of this file.
1 #include "battery_view.h"
2 
4  {0xDB, 0x00, 0x00, 0xFF},
5  {0xB7, 0x00, 0x6D, 0xFF},
6  {0x6D, 0x00, 0xDB, 0xFF},
7  {0x24, 0x00, 0x00, 0x00},
8  {0x00, 0x00, 0x00, 0x24},
9  {0xFF, 0xDB, 0x00, 0x6D},
10  {0xFF, 0x6D, 0x00, 0xB7},
11  {0xFF, 0x00, 0x00, 0xDB},
12 };
13 
15  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xDB, 0x00, 0x24},
16  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x6D, 0x00, 0xDB},
17  {0x6D, 0x00, 0xB7, 0xFF, 0xB7, 0x00, 0x24, 0xFF},
18  {0xDB, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF},
19  {0xFF, 0xB7, 0x00, 0x24, 0x00, 0xB7, 0xFF, 0xFF},
20  {0xFF, 0xFF, 0x24, 0x00, 0x24, 0xFF, 0xFF, 0xFF},
21 
22 };
23 
24 
26  View(),
27  m_chargeState(Ion::Battery::Charge::SOMEWHERE_INBETWEEN),
28  m_isCharging(false),
29  m_isPlugged(false)
30 {
31 }
32 
34  if (chargeState != m_chargeState) {
35  m_chargeState = chargeState;
37  return true;
38  }
39  return false;
40 }
41 
43  if (m_isCharging != isCharging) {
44  m_isCharging = isCharging;
46  return true;
47  }
48  return false;
49 }
50 
52  if (m_isPlugged != isPlugged) {
53  m_isPlugged = isPlugged;
55  return true;
56  }
57  return false;
58 }
59 
62 
63 void BatteryView::drawRect(KDContext * ctx, KDRect rect) const {
64  /* We draw from left to right. The middle part representing the battery
65  *'content' depends on the charge */
66  ctx->fillRect(KDRect(0, 0, k_elementWidth, k_batteryHeight), KDColorWhite);
67  if (m_isCharging) {
68  ctx->fillRect(KDRect(k_elementWidth+k_separatorThickness, 0, k_batteryWidth-3*k_elementWidth-2*k_separatorThickness, k_batteryHeight), Palette::YellowLight);
69  KDRect frame((k_batteryWidth-k_flashWidth)/2, 0, k_flashWidth, k_flashHeight);
71  }
72  if (!m_isCharging && m_isPlugged && m_chargeState == Ion::Battery::Charge::FULL) {
73  ctx->fillRect(KDRect(k_elementWidth+k_separatorThickness, 0, k_batteryWidth-3*k_elementWidth-2*k_separatorThickness, k_batteryHeight), KDColorWhite);
74  KDRect frame((k_batteryWidth-k_tickWidth)/2, (k_batteryHeight-k_tickHeight)/2, k_tickWidth, k_tickHeight);
76  }
77  if (!m_isCharging && m_chargeState == Ion::Battery::Charge::LOW) {
78  ctx->fillRect(KDRect(k_elementWidth+k_separatorThickness, 0, 2*k_elementWidth, k_batteryHeight), Palette::LowBattery);
79  ctx->fillRect(KDRect(3*k_elementWidth+k_separatorThickness, 0, k_batteryWidth-5*k_elementWidth-2*k_separatorThickness, k_batteryHeight), Palette::YellowLight);
80  }
81  if (!m_isCharging && m_chargeState == Ion::Battery::Charge::SOMEWHERE_INBETWEEN) {
82  ctx->fillRect(KDRect(k_elementWidth+k_separatorThickness, 0, (k_batteryWidth-3*k_elementWidth-2*k_separatorThickness)/2, k_batteryHeight), KDColorWhite);
83  ctx->fillRect(KDRect(k_elementWidth+k_separatorThickness+(k_batteryWidth-3*k_elementWidth-2*k_separatorThickness)/2, 0, (k_batteryWidth-3*k_elementWidth-2*k_separatorThickness)/2, k_batteryHeight), Palette::YellowLight);
84  }
85  if (!m_isCharging && !m_isPlugged && m_chargeState == Ion::Battery::Charge::FULL) {
86  ctx->fillRect(KDRect(k_elementWidth+k_separatorThickness, 0, k_batteryWidth-3*k_elementWidth-2*k_separatorThickness, k_batteryHeight), KDColorWhite);
87  }
88  ctx->fillRect(KDRect(k_batteryWidth-2*k_elementWidth, 0, k_elementWidth, k_batteryHeight), KDColorWhite);
89  ctx->fillRect(KDRect(k_batteryWidth-k_elementWidth, (k_batteryHeight-k_capHeight)/2, k_elementWidth, k_capHeight), KDColorWhite);
90 }
91 
93  return KDSize(k_batteryWidth, k_batteryHeight);
94 }
bool isPlugged()
Definition: usb.cpp:12
KDColor s_flashWorkingBuffer[BatteryView::k_flashHeight *BatteryView::k_flashWidth]
static constexpr KDColor YellowDark
Definition: palette.h:8
const uint8_t tickMask[BatteryView::k_tickHeight][BatteryView::k_tickWidth]
bool isCharging()
Definition: battery.cpp:16
void markRectAsDirty(KDRect rect)
Definition: view.cpp:39
void blendRectWithMask(KDRect rect, KDColor color, const uint8_t *mask, KDColor *workingBuffer)
bool setIsCharging(bool isCharging)
bool setIsPlugged(bool isPlugged)
unsigned char uint8_t
Definition: stdint.h:4
static constexpr int k_flashHeight
Definition: battery_view.h:14
void drawRect(KDContext *ctx, KDRect rect) const override
KDColor s_tickWorkingBuffer[BatteryView::k_tickHeight *BatteryView::k_tickWidth]
Definition: size.h:6
KDSize minimalSizeForOptimalDisplay() const override
constexpr KDColor KDColorWhite
Definition: color.h:42
static constexpr KDColor LowBattery
Definition: palette.h:22
static constexpr int k_tickHeight
Definition: battery_view.h:16
#define false
Definition: stdbool.h:9
static constexpr KDColor YellowLight
Definition: palette.h:9
static constexpr int k_flashWidth
Definition: battery_view.h:15
Definition: rect.h:26
void fillRect(KDRect rect, KDColor color)
Definition: context_rect.cpp:8
Definition: color.h:6
Definition: view.h:23
Definition: backlight.h:6
const uint8_t flashMask[BatteryView::k_flashHeight][BatteryView::k_flashWidth]
Definition: battery_view.cpp:3
static constexpr int k_tickWidth
Definition: battery_view.h:17
KDRect bounds() const
Definition: view.cpp:157
bool setChargeState(Ion::Battery::Charge chargeState)