User Manual

2/12/2018 PiJuice/Software at master · PiSupply/PiJuice · GitHub
https://github.com/PiSupply/PiJuice/tree/master/Software 15/18
starts with one byte command code, followed by data payload and with checksum byte at the end of message. Checksum is
8-bit XOR calculated over all data payload bytes.
Command Abstraction Layer
In order to facilitate communication with PiJuice HAT using I2C Command API there is abstraction layer hat encapsulates
commands into more intuitive interface to configure, control and retrieve status of PiJuice features. This layer is
implemented as python script module pijuice.py. Different types of interface function are encapsulated in next set of classes:
PiJuiceInterface. Functions for low level message exchange end error checking through I2C bus.
PiJuiceStatusFunctions for dynamically controlling and reading status of PiJuice features.
PiJuiceRtcAlarmFunctions for setting-up real time clock and wake-up alarm.
PiJuicePowerPower management functions.
PiJuiceConfigFunctions for static configuration that mostly involves non-volatile data that saves in EEPROM. All the
function classes are encapsulated in top level object PiJuice(bus, address), where bus presents I2C bus identifier and
address presents PiJuice HAT I2C slave address. Usage example:
from pijuice import PiJuice # Import pijuice module
pijuice = PiJuice(1, 0x14) # Instantiate PiJuice interface object
print pijuice.status.GetStatus() # Read PiJuice staus.
Commands are encapsulated with two type of functions, Setters that writes configuration and control data to PiJuice and
Getters that reads status or current configuration/control data. Every function returns object of dictionary type containing
communication error status:
{
'error':error_status
}
Where error_staus value can be NO_ERROR in case data are exchanged with no communication errors or value that
describers error in cases where communication fails. In case of Getter functions additions additional data object is returned
in case of successful data read with value that presents returned data:
{
'error':error_status,
'data':data
}
PiJuiceStatus functions
GetStatus()
Gets basic PiJuice status information about power inputs, battery and events. Returns: 'data':{ 'isFault':is_fault,
'isButton':is_button, 'battery':battery_status, 'powerInput':power_input_status, 'powerInput5vIo':5v_power_input_status }
Where:
is_fault is True if there faults or fault events waiting to be read or False if there is no faults and no fault events.
is_button is True if there are button events, False if not.
battery_status is string constant that describes current battery status, one of four: 'NORMAL', 'CHARGING_FROM_IN',
'CHARGING_FROM_5V_IO', 'NOT_PRESENT'.
power_input_status is string constant that describes current status of USB Micro power input, one of four:
'NOT_PRESENT', 'BAD', 'WEAK', 'PRESENT'.
5v_power_input_status: is string constant that describes current status of 5V GPIO power input, one of four:
'NOT_PRESENT', 'BAD', 'WEAK', 'PRESENT'. Example: