Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"icon_url": "https://apps.micropythonos.com/apps/com.micropythonos.showbattery/icons/com.micropythonos.showbattery_0.1.1_64x64.png",
"download_url": "https://apps.micropythonos.com/apps/com.micropythonos.showbattery/mpks/com.micropythonos.showbattery_0.1.1.mpk",
"fullname": "com.micropythonos.showbattery",
"version": "0.1.1",
"version": "0.2.0",
"category": "development",
"activities": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"""

import lvgl as lv
import time

import mpos.time
from mpos import Activity, BatteryManager

HISTORY_LEN = 60
Expand All @@ -56,11 +55,13 @@ class ShowBattery(Activity):
# Widgets
lbl_time = None
lbl_sec = None
lbl_date = None
lbl_text = None

bat_outline = None
bat_fill = None

clear_cache_checkbox = None # Add reference to checkbox

history_v = []
history_p = []

Expand All @@ -69,16 +70,21 @@ def onCreate(self):

# --- TIME ---
self.lbl_time = lv.label(scr)
self.lbl_time.set_style_text_font(lv.font_montserrat_48, 0)
self.lbl_time.set_style_text_font(lv.font_montserrat_40, 0)
self.lbl_time.align(lv.ALIGN.TOP_LEFT, 5, 5)

self.lbl_sec = lv.label(scr)
self.lbl_sec.set_style_text_font(lv.font_montserrat_24, 0)
self.lbl_sec.align_to(self.lbl_time, lv.ALIGN.OUT_RIGHT_BOTTOM, 24, -4)

self.lbl_date = lv.label(scr)
self.lbl_date.set_style_text_font(lv.font_montserrat_24, 0)
self.lbl_date.align(lv.ALIGN.TOP_LEFT, 5, 60)
# --- CHECKBOX ---
self.clear_cache_checkbox = lv.checkbox(scr)
self.clear_cache_checkbox.set_text("Real-time values")
self.clear_cache_checkbox.align(lv.ALIGN.TOP_LEFT, 5, 50)

self.lbl_text = lv.label(scr)
self.lbl_text.set_style_text_font(lv.font_montserrat_16, 0)
self.lbl_text.align(lv.ALIGN.TOP_LEFT, 5, 80)

# --- BATTERY ICON ---
self.bat_outline = lv.obj(scr)
Expand Down Expand Up @@ -126,19 +132,26 @@ def onResume(self, screen):
super().onResume(screen)

def update(timer):
now = time.localtime()
now = mpos.time.localtime()

hour, minute, second = now[3], now[4], now[5]
date = f"{now[0]}-{now[1]:02}-{now[2]:02}"

if self.clear_cache_checkbox.get_state() & lv.STATE.CHECKED:
# Get "real-time" values by clearing the cache before reading
BatteryManager.clear_cache()

voltage = BatteryManager.read_battery_voltage()
percent = BatteryManager.get_battery_percentage()

# --- TIME ---
self.lbl_time.set_text(f"{hour:02}:{minute:02}")
self.lbl_sec.set_text(f":{second:02}")

# --- BATTERY VALUES ---
date += f"\n{voltage:.2f}V {percent:.0f}%"
self.lbl_date.set_text(date)
date += f"\nRaw ADC: {BatteryManager.read_raw_adc()}"
self.lbl_text.set_text(date)

# --- BATTERY ICON ---
fill_h = int((percent / 100) * (self.bat_size * 0.9))
Expand Down
20 changes: 17 additions & 3 deletions internal_filesystem/lib/mpos/board/odroid_go.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
# Misc settings:
LED_BLUE = const(2)
BATTERY_PIN = const(36)
BATTERY_RESISTANCE_NUM = const(2)
SPEAKER_ENABLE_PIN = const(25)
SPEAKER_PIN = const(26)

Expand Down Expand Up @@ -105,8 +104,22 @@
from mpos import BatteryManager


def adc_to_voltage(adc_value):
return adc_value * BATTERY_RESISTANCE_NUM
def adc_to_voltage(raw_adc_value):
"""
The percentage calculation uses MIN_VOLTAGE = 3.15 and MAX_VOLTAGE = 4.15
0% at 3.15V -> raw_adc_value = 270
100% at 4.15V -> raw_adc_value = 310

4.15 - 3.15 = 1V
310 - 270 = 40 raw ADC steps

So each raw ADC step is 1V / 40 = 0.025V
Offset calculation:
270 * 0.025 = 6.75V. but we want it to be 3.15V
So the offset is 3.15V - 6.75V = -3.6V
"""
voltage = raw_adc_value * 0.025 - 3.6
return voltage


BatteryManager.init_adc(BATTERY_PIN, adc_to_voltage)
Expand Down Expand Up @@ -183,6 +196,7 @@ def input_callback(indev, data):
current_key = lv.KEY.ESC
elif button_volume.value() == 0:
print("Volume button pressed -> reset")
blue_led.on()
machine.reset()
elif button_select.value() == 0:
current_key = lv.KEY.BACKSPACE
Expand Down
Loading