27 lines
710 B
Python
27 lines
710 B
Python
from compLib.ADC import ADC
|
|
from compLib.LogstashLogging import Logging
|
|
|
|
BATTERY_CHANNEL = 2
|
|
BATTERY_COUNT = 2
|
|
BATTERY_MULTIPLIER = 3
|
|
BATTERY_MIN_VOLTAGE = 3.4
|
|
BATTERY_MAX_VOLTAGE = 4.2
|
|
|
|
adc = ADC()
|
|
|
|
|
|
class Battery(object):
|
|
"""Used to interact with the battery
|
|
"""
|
|
|
|
@staticmethod
|
|
def percent() -> int:
|
|
"""Get battery percentage
|
|
|
|
:return: Percentage between 0 and 100
|
|
:rtype: int
|
|
"""
|
|
voltage = adc.read(BATTERY_CHANNEL) * BATTERY_MULTIPLIER
|
|
result = int(((voltage / BATTERY_COUNT) - BATTERY_MIN_VOLTAGE) / (BATTERY_MAX_VOLTAGE - BATTERY_MIN_VOLTAGE) * 100)
|
|
Logging.get_logger().debug(f"Battery.percent = {result}")
|
|
return result
|