philander package

Submodules

philander.accelerometer module

Abstract interface for accelerometer sensors accessible via serial communication.

Provide an API to abstract from acceleration measurement devices.

class Accelerometer[source]

Bases: Sensor

Abstract base class for digital accelerometers.

class Activity(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Identifies general types of human walking activities, that an accelerometer is possibly able to detect or distinguish.

running = 4
still = 2
unknown = 1
walking = 3
class AxesSign(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Flag

Data class to name coordinate axes along with their positive or negative sign.

all = 7
none = 0
sign = 8
signNeg = 8
signPos = 0
x = 1
y = 2
z = 4
class Configuration(item: ConfigItem = ConfigItem.implicit, value: int = 1, fifo: CfgFifo = None, rateMode: CfgRateMode = None, eventCondition: CfgInterrupt = None)[source]

Bases: Configuration

Data class to describe common configuration settings.

Use the parental class sensor.Configuration.item attribute to de-multiplex the inner data types.

class CfgInterrupt(delay: int = 10, thrshld: int = 1500, hysteresis: int = 200, axes: philander.accelerometer.AxesSign = <AxesSign.z: 4>, event: philander.accelerometer.EventSource = <EventSource.dataReady: 1>)[source]

Bases: object

axes: AxesSign = 4
delay: int = 10
event: EventSource = 1
hysteresis: int = 200
thrshld: int = 1500
class CfgRateMode(mValue: int = 2, control: philander.accelerometer.SamplingMode = <SamplingMode.normal: 2>)[source]

Bases: object

control: SamplingMode = 2
mValue: int = 2
eventCondition: CfgInterrupt = None
rateMode: CfgRateMode = None
class Data(x: int = 0, y: int = 0, z: int = 0)[source]

Bases: object

Container type to wrap an accelerometer’s primary measurement result.

Measurement data should always be expressed as a signed value in per-mille of the standard gravity milli-g [mg] along the three axes. Of course:

1000 mg = 1 g = 9,80665 m/s^2
x: int = 0
y: int = 0
z: int = 0
class EventContext(source: EventSource = EventSource.none, data: Data = None, status: int = 0)[source]

Bases: EventContext

Data class holding the context information of an event (interrupt).

Use the source attribute to de-multiplex the inner data items.

data: Data = None
source: EventSource = 0
status: int = 0
class EventSource(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Flag

Data class to hold known event (interrupt) sources.

activity = 32768
all = 4294967295
dataReady = 1
error = 262144
fifoFull = 4
fifoWatermark = 2
gesture = 16384
highG = 32
highGTime = 64
highSlope = 512
highSlopeTime = 1024
lowG = 8
lowGTime = 16
lowSlope = 128
lowSlopeTime = 256
lyingFlat = 65536
none = 0
orientation = 131072
significantMotion = 2048
step = 8192
tap = 4096
class Orientation(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Flag

Data class to enumerate orientations that the device carrying the accelerometer may be in.

faceDown = 4
faceMask = 4
faceUp = 0
invalidFace = 32
invalidMask = 240
invalidStand = 16
invalidTilt = 64
landscapeLeft = 2
landscapeRight = 3
portraitDown = 1
portraitUp = 0
standMask = 3
tiltFlat = 8
tiltMask = 8
tiltStand = 0
unknown = 255
class SamplingMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Mnemonic type to identify different types of sampling techniques, such as averaging, normal or over-sampling.

OSR2 = 3
OSR4 = 4
average = 1
normal = 2
class StatusID(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Data class to comprise different types of status information.

NVM = 12
activity = 6
dataReady = 2
dieTemp = 1
error = 5
fifo = 4
highG = 8
highSlope = 9
interrupt = 3
orientation = 10
sensorTime = 13
stepCount = 7
tap = 11
class Tap(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Data class to identify different types of tap.

A tap should be understood as a quick finger tip onto some touch screen to simulate the click of a mouse.

double = 3
none = 1
single = 2
triple = 4

philander.actuator module

Abstract actuator interface.

Provide an API to abstract from any type of actuators. Only a very basic set of common types and functions is provided.

class Actuator[source]

Bases: object

Unified interface to parts and subsystems with mechanical capabilities.

This may involve some sort of motor to execute mechanical work, such as in gears, drives or stimulators. However, also other physical media like electricity (taser) or light (laser) might be the functional basis of an actuator.

An actuator is meant to reflect the most atomic component of a mechanical device. Several actuators may compose a more complex subsystem, such as a steering axis of a rover.

action(pattern=None)[source]

Executes a predefined action or movement pattern with this actuator.

Runs an action on this actuator instance. The type of action can be specified further using the optional pattern parameter. In most cases, this will be an integer number designating one or the other pre-defined / default movement. If applicable, the value zero (0) shall encode a “move to home/rest/parking position” action. Also “switch off” could be a valid interpretation. A value of one (1) shall be used for “the standard/default movement”. The interpretation of other values is at the discretion of the implementation.

Parameters:

pattern (int) – The action pattern to execute.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

startOperation(direction=Direction.positive, strengthIntensity=0, onSpeedDuty=0, ctrlInterval=0, durationLengthCycles=0)[source]

Start a continuous or lengthy operation of this actuator instance.

Begin an operation, such as running a motor. The operation may or may not end automatically. In any case, the operation can be stopped intentionally by calling stopOperation().

The optional direction parameter may be used to indicate the direction of the operation. Interpretation of left/right or positive/negative etc. is up to the implementation.

The strengthIntensity parameter may be used to set the drive strength or intensity of a movement. The strength should be given in a meaningful physical unit. If meant as an intensity, it should be an integer percentage in the range [0…100]. In the context of PWM control, this parameter may be interpreted as the voltage amplitude applied, expressed in milli Volt. This parameter is optional.

The optional parameter onSpeedDuty may indicate the speed of the movement or the length of the ON phase in a rectangular control signal. If interpreted as a speed, it should be given either as a value in meters per second (m/s) or as an integer percentage related to some maximum possible or reference speed. When controlling a PWM device, this is the duty cycle expressed as a percentage.

The ctrlInterval parameter gives the total length of a periodic control interval, e.g. for PWM control. It is expressed in milliseconds. This parameter is optional.

The parameter durationLengthCycles is optional. It and may be interpreted as a run time duration, preferably expressed as a number in milliseconds (ms). Alternatively, this parameter may also be interpreted as a way length for the actuator to go, preferably expressed as a number in millimeters (mm). Finally, this can also be the number of cycles to last, e.g. when controlling a PWM device. Then, this is a unitless integer number.

See also: stopOperation().

Parameters:
  • direction (Direction) – The direction to move the actuator in.

  • strengthIntensity (int) – The speed or intensity of the movement.

  • durationLengthCycles (int) – The duration, length or number of cycles to move.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

stopOperation()[source]

Immediately stops the current operation.

See also: startOperation().

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

class Direction(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Data class to represent the direction that an actuator can move to.

back = -1
clockwise = -1
counterclockwise = 1
down = -1
forth = 1
left = 1
negative = -1
positive = 1
right = -1
up = 1

philander.adc module

Abstraction module for analogue-to-digital conversion.

Provide a convergence layer API to abstract from several different ADC implementing driver modules possibly installed on the target system.

class ADC[source]

Bases: Module

Analogue-to-digital converter abstraction class.

Provide access to and control over the underlying ADC hardware. For that, an implementing driver module is used. As a convergence layer, this class is to hide specifics and to level syntactic requirements of the implementing package.

CHANNEL_DIE_TEMP = -1
DEFAULT_SAMPLING_TIME = 100
DEFAULT_VREF_LOWER = 0
DEFAULT_VREF_UPPER = 3000
DIGITAL_MAX = 65535
classmethod Params_init(paramDict)[source]

Initialize parameters with their defaults.

The given dictionary should not be None, on entry. Options not present in the dictionary will be added and set to their defaults on return. The following options are supported.

Key

Range

Default

adc.channel

pin name or channel number (e.g. 2 or “2”)

None

adc.samplingTime

Sampling time in microseconds; integer>=0

None

adc.vref.lower

lower reference voltage in mV; integer

DEFAULT_VREF_LOWER

adc.vref.upper

upper reference voltage in mV; integer

DEFAULT_VREF_UPPER

Parameters:

paramDict (dict(str, object)) – Configuration parameters as obtained from Params_init(), possibly.

Returns:

none

Return type:

None

close()[source]

Closes this instance and releases associated hardware resources.

This is the counterpart of open(). Upon return, further usage of this instance is prohibited and may lead to unexpected results. The instance can be re-activated by calling open(), again.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

static getADC(provider=SysProvider.AUTO)[source]

Generates an ADC implementation according to the requested provider.

Parameters:

provider (SysProvider) – The low-level lib to rely on, or AUTO for automatic detection.

Returns:

An ADC implementation object, or None in case of an error.

Return type:

ADC

getDigital()[source]

Retrieve a sample and return its digital value.

Gives the most recent sample as a digital value between zero and the maximum digital value [0…DIGITAL_MAX].

Returns:

A value in the range [0, DIGITAL_MAX] and an error code indicating either success or the reason of failure.

Return type:

int, ErrorCode

getVoltage()[source]

Retrieve a sample and return it as a voltage in mV.

Gives the most recent sample as a voltage value between the lower and upper reference voltage, expressed as milli Volts. Calibration and temperature correction is at the discretion of the implementation and hence, cannot be assured.

Returns:

A mV-value in the range [vref_lower, vref_upper] and an error code indicating either success or the reason of failure.

Return type:

int, ErrorCode

open(paramDict)[source]

Opens the instance and sets it in a usable state.

Allocate necessary hardware resources and configure user-adjustable parameters to meaningful defaults. This function must be called prior to any further usage of the instance. Involving it in the system ramp-up procedure could be a good choice. After usage of this instance is finished, the application should call close().

Parameters:

paramDict (dict(str, object)) – Configuration parameters as obtained from Params_init(), possibly.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

setRunLevel(level)[source]

Select the power-saving operation mode.

Switches the instance to one of the power-saving modes or recovers from these modes. Situation-aware deployment of these modes can greatly reduce the system’s total power consumption.

Parameters:

level (RunLevel) – The level to switch to.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

toVoltage(digital)[source]

Convert a digital value to its corresponding voltage in mV.

Map the digital sample value to the range of [vref_lower, vref_upper] and return the corresponding voltage expressed in millivolts [mV].

Parameters:

digital (int) – The digital value to convert. Must be in [0, 0xFFFF].

Returns:

A mV-value in the range [vref_lower, vref_upper] and an error code indicating either success or the reason of failure.

Return type:

int, ErrorCode

philander.battery module

A module to reflect capabilities and properties of re-chargeable batteries.

class Capacity[source]

Bases: int

Absolute capacity of a battery in mAh

invalid = 65535
class Level(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Level of a battery in [0…100]%

deepDischarge = 0
empty = 5
static fromPercentage(percentage)[source]

Convert a given percentage into the corresponding level predicate.

Returns the largest level, that is less than or equal to the given percentage. So, the returned level is an underestimation. Or, to put it differently, the real capacity remaining is at least the level returned.

If the given percentage is Percentage.invalid or does not compare to a number, Level.invalid is returned.Values below zero are mapped to Level.min, while values beyond 100 are mapped to Level.max.

Parameters:

percentage (Percentage) – The percentage value to be converted.

Returns:

The largest level just under-estimating the given percentage.

Return type:

Level

full = 90
good = 70
invalid = 255
low = 20
max = 100
medium = 40
min = 0
class Status(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Flag

Container class to reflect the battery status

broken = 2

Charging takes (too) long; old/damaged battery

cold = 256

Battery is too cold

coldOrHot = 768

Battery temperature is outside its operating conditions

empty = 16

Battery empty, deep discharge

hot = 512

Battery is too hot

low = 32

Battery voltage low

normal = 0

Battery ok

overcurrent = 128

Battery current to high

overvoltage = 64

Battery voltage greater than threshold

problemElectrical = 240

Any electrical problem

problemPhysical = 15

Any physical problem

problemThermal = 3840

Any thermal problem

removed = 1

Battery removed

unknown = 65535

Battery status information is unavailable

philander.bma456 module

Driver implementation for the BMA456 3-axis digital acceleromter.

More information on the functionality of the chip can be found at the Bosch-Sensortec site: https://www.bosch-sensortec.com/products/motion-sensors/accelerometers/bma456/#documents

class BMA456[source]

Bases: BMA456_Reg, SerialBusDevice, Accelerometer, Interruptable

BMA456 driver implementation.

ADDRESSES_ALLOWED = [24, 25]

Default address is 0x18 assuming that SDO is set/tied to GND.

Alternatively, the address can be 0x19 by pulling SDO high (VDDIO).

BMA456_CHUNK_SIZE = 8

No. of bytes that can be written at once.

BMA456_FEATUREBUF_CONTENT_IDX = 1
BMA456_FEATUREBUF_HEADER_IDX = 0
BMA456_FEATUREBUF_HEADER_SIZE = 1
BMA456_FEATUREBUF_TOTAL_SIZE = 97
classmethod Params_init(paramDict)[source]

Initializes configuration parameters with defaults.

The following settings are supported:

Key name

Value type, meaning and default

SerialBusDevice.address

int I2C serial device address, one of ADDRESSES_ALLOWED; default is ADDRESSES_ALLOWED [0].

Sensor.dataRange

int Measurement range in milli-g; default corresponds to BMA456_CNT_ACC_RANGE_DEFAULT.

Sensor.dataRate

int Data rate in Hz; default corresponds to BMA456_CNT_ACC_CONF_ODR_DEFAULT.

BMA456.INT1_IO_CTRL

int Content of the INT1_IO_CTRL register; default is BMA456_CNT_INT1_IO_CTRL_DEFAULT.

BMA456.INT2_IO_CTRL

int Content of the INT2_IO_CTRL register; default is BMA456_CNT_INT2_IO_CTRL_DEFAULT.

BMA456.INT1_MAP

int Content of the INT1_MAP register; default is BMA456_CNT_INTX_MAP_DEFAULT.

BMA456.INT2_MAP

int Content of the INT2_MAP register; default is BMA456_CNT_INTX_MAP_DEFAULT.

BMA456.INT_MAP_DATA

int Content of the INT_MAP_DATA register; default is BMA456_CNT_INT_MAP_DATA_DEFAULT.

BMA456.int1.gpio.direction

see GPIO.Params_init(); default is GPIO.DIRECTION_IN.

BMA456.int2.gpio.direction

see GPIO.Params_init(); default is GPIO.DIRECTION_IN.

BMA456.int1.gpio.trigger

see GPIO.Params_init(); default is GPIO.TRIGGER_EDGE_FALLING.

BMA456.int2.gpio.trigger

see GPIO.Params_init(); default is GPIO.TRIGGER_EDGE_FALLING.

BMA456.int1.gpio.bounce

see GPIO.Params_init(); default is GPIO.BOUNCE_NONE.

BMA456.int2.gpio.bounce

see GPIO.Params_init(); default is GPIO.BOUNCE_NONE.

All other BMA456.int1.gpio.* and BMA456.int1.gpio.* settings as documented at GPIO.Params_init().

For the SerialBusDevice.address value, also 0 or 1 can be specified alternatively to the absolute addresses to reflect the level of the SDO pin. In this case, 0 will be mapped to 0x18, while 1 maps to 0x19.

Also see: Sensor.Params_init(), SerialBusDevice.Params_init(), GPIO.Params_init().

calibrate(calib)[source]

Execute a calibration.

The details for the calibration are given by the calib parameter.

Also see: Sensor.calibrate(), Calibration.

Parameters:

calib (Calibration) – The calibration data.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

close()[source]

Shut down the device after usage.

This method should be called when the device is not used, anymore, e.g. as part of the application exit procedure. The following steps are executed:

  • shut down the device by switching to RunLevel.shutdown

  • close serial communication, detach from bus.

  • close GPIO pins for int1 and int2

After return, the device can still be re-used, by calling open() again.

Also see: SerialBusDevice.close(), GPIO.close(), Module.close().

configure(config)[source]

Configure the device as specified in the config parameter.

Remember, the config parameter should be an instance of accelerometer.Configuration. Its attributes are de-multiplexed by sensor.Configuration.item. The following configuration types are supported:

ConfigItem.rate: The data rate given as an integer value in Hz is expected in Configuration.value. If it doesn’t match a supported rate value exactly, it is rounded up appropriately. So, the rate actually configured may be slightly higher than the value given here. Furthermore, the sampling mode must be specified in the Configuration.rateMode attribute. The chip supports under-sampling (SamplingMode.average), normal sampling and over-sampling (2x and 4x). For averaging mode, the number of samples to average must be given in Configuration.rateMode.mValue.

ConfigItem.range: The Configuration.value attribute is expected to carry the measurement range given as an integer in milli-g. If the given value doesn’t match one of the hardware-supported range levels, exactly, it is rounded-up accordingly.

ConfigItem.fifo: Not yet implemented.

ConfigItem.eventArm: Selectively enables or disables certain event sources (interrupts). Remember that the following conditions must be fulfilled in order to get a specific interrupt fired:

  1. Interrupts must be enabled. See enableInterrupt().

  2. That interrupt (event source) must be armed - using this method.

  3. The corresponding interrupt condition must be true.

Note that the armed events are always configured to fire on both interrupt lines interruptable.Event.evtInt1 and interruptable.Event.evtInt2. The bit mask of events to be armed is expected in accelerometer.Configuration.value as an equivalent of accelerometer.EventSource. The translation between the given event source and the underlying hardware interrupt is as follows:

Event source

Hardware interrupt mapping bit mask

dataReady

INT_MAP_DATA: (INT1_DRDY | INT2_DRDY)

fifoWatermark

INT_MAP_DATA: (INT1_FIFO_WM | INT2_FIFO_WM)

fifoFull

INT_MAP_DATA: (INT1_FIFO_FULL | INT2_FIFO_FULL)

error

INTX_MAP: ERROR

lowSlopeTime

INTX_MAP: NO_MOTION

highSlopeTime

INTX_MAP: ANY_MOTION

gesture

INTX_MAP: WRIST_WKUP

activity

INTX_MAP: ACTIVITY

step

INTX_MAP: STEP_CNT

tap

INTX_MAP: STAP (wearable), TAP (hearable, MM)

significantMotion

INTX_MAP: SIG_MOTION

highGTime

INTX_MAP: HIGH_G

lowGTime

INTX_MAP: LOW_G

orientation

INTX_MAP: ORIENT

ConfigItem.eventCondition: Configures the trigger condition for parameterized events, such as tap or lowGTime. The details, such as thresholds and delays, are expected in the given config ‘s accelerometer.Configuration.eventCondition attribute, which is de-multiplexed by its accelerometer.Configuration.CfgInterrupt.event attribute.

Note that the event sources dataReady, fifoWatermark, fifoFull and error are not parameterized. They cannot be conditioned any further.

The configuration of other event conditions is not implemented, yet.

Also see: Sensor.configure().

Parameters:

config (.accelerometer.Configuration) – Specific configuration information.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

dictAverage = <philander.dictionary.Dictionary object>

Dictionary to map config mode settings into averaging window size, i.e. the number of samples to average.

dictConfigData = <philander.dictionary.Dictionary object>
dictFeatureSetLength = <philander.dictionary.Dictionary object>
dictRange = <philander.dictionary.Dictionary object>

The dictionary to map range setting bits into the corresponding range value, meant in milli-g.

dictRate = <philander.dictionary.Dictionary object>

Dictionary to map data rate setting bits into the corresponding data rates, meant in Hz.

disableInterrupt()[source]

Disable interrupts.

Switch off the interrupt functionality both, on the GPIO and the chip level.

Note that this method is just for switching the interrupt capability off. For switching it on, see enableInterrupt().

Also see Interruptable.disableInterrupt().

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

enableInterrupt()[source]

Enable the interrupt mechanism/engine.

Clear the interrupts that possibly occurred so far. Then, enable interrupt signaling at the corresponding GPIO pin. Finally, set the OUTPUT_ENABLE bit at the involved interrupt IO_CTRL registers.

Note that this method is just for switching the interrupt capability on. For switching it off, see disableInterrupt(). For configuring interrupts, see configure() and registerInterruptHandler().

Also see Interruptable.enableInterrupt().

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

getEventContext(event, context)[source]

Retrieve more detailed information on an event.

Typically, an original event notification just carries the information, that an event/interrupt occurred. This method is to reveal more details on the cause of the interrupt.

The event parameter is an input to tell, which of the two interrupt lined actually fired. On return, the context parameter carries the resulting information. It must be an instance of accelerometer.EventContext, which is semantically multiplexed by its accelerometer.EventContext.source attribute. Depending on that event source indicator, the rest of the structure is filled as follows:

Event source (flag)

Context attribute and data

dataReady

data latest measurement as retrieved by getLatestData()

fifoWatermark, fifoFull

status fifo status retrieved from getStatus() and StatusID.fifo

activity

status activity status retrieved from getStatus() and StatusID.activity

step

status step count retrieved from getStatus() and StatusID.stepCount

highGTime

status high-G status retrieved from getStatus() and StatusID.highG

orientation

status orientation retrieved from getStatus() and StatusID.orientation

tap

status Tap instance depending on feature set and interrupt

A single interrupt may have several reasons, simultaneously. That’s why, it may be meaningful/necessary to call this method repeatedly, until all reasons were reported. Upon its first call after an event, the context’s interruptable.EventContext.control attribute must be set to interruptable.EventContextControl.evtCtxtCtrl_getFirst. Upon subsequent calls, this attribute should not be changed by the caller, anymore. In generally, event context information is retrieved in the order according to the priority of the corresponding event sources.

The return value indicates, whether or not more information is available as follows:

Return value

Meaning

ErrorCode.errOk

Success. Last context info. No more data to retrieve.

ErrorCode.errMoreData

Success. Context is valid. More data to be retrieved.

ErrorCode.errFewData

No data to retrieve. Context is invalid.

any other ErrorCode.*

Error. Context data is invalid.

Also see: Interruptable.getEventContext().

Parameters:
  • event (int) – The original event occurred, as received by the handling routine. This must be one of the event mnemonics defined by :class:.interruptable.Event.

  • context (.accelerometer.EventContext) – Context information.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

getInfo()[source]

Retrieve static information from the sensor chip.

Supported information is Info.validModelID and Info.validChipID.

Also see: Sensor.getInfo().

Returns:

The information object and an error code indicating either success or the reason of failure.

Return type:

Info, ErrorCode

getLatestData()[source]

Retrieve the most-recent available measurement data.

This method is guaranteed to be non-blocking. Therefore, the data retrieved might be /old/ or /outdated/ to some extend.

The result is given as a data object containing 3 signed integers, representing the acceleration in milli-G in the x, y and z direction, respectively.

Also see: Sensor.getLatestData().

Returns:

The measurement data and an error code indicating either success or the reason of failure.

Return type:

accelerometer.Data, ErrorCode

getNextData()[source]

Get the next-available measurement data.

This method is guaranteed to produce up-to-date measurement data. This may come at the price of a blocking delay.

As with getLatestData(), the result is given as a data object containing three integers that represent the acceleration in x, y and z direction, respectively, expressed in milli-G.

Also see: Sensor.getNextData().

Returns:

The measurement data and an error code indicating either success or the reason of failure.

Return type:

accelerometer.Data, ErrorCode

getStatus(statID)[source]

Retrieve dynamic meta information from the sensor chip.

The information requested is indicated by the parameter statID. The resulting status information is passed back as a part of the return value. The following information is available:

accelerometer.StatusID.dieTemp: The chip temperature as read from the register BMA456_REG_TEMPERATURE is returned as an Q8.8 integer given in degree Celsius.

accelerometer.StatusID.dataReady: Returns a boolean to flag whether or not new data is available. For that, evaluates the DRDY_ACC bit in BMA456_REG_STATUS

accelerometer.StatusID.interrupt: Give the pending interrupts by reading BMA456_REG_INT_STATUS. This information is cleared until interrupt conditions are fulfilled anew. The result is given as an acceleroometer.EventSource bit mask. The mapping of hardware interrupt bits to event source flags is as follows:

Interrupt (Bit)

EventSource

ACC_DRDY

dataReady

ACTIVITY

activity

ANY_MOTION

highSlopeTime

AUX_DRDY

none

DBL_TAP

tap

ERROR

error

FIFO_FULL

fifoFull

FIFO_WM

fifoWatermark

HIGH_G

highGTime

LOW_G

lowGTime

NO_MOTION

lowSlopeTime

ORIENT

orientation

SIG_MOTION

significantMotion

STEP_COUNT

step

TAP_DETECT

tap

WRIST_WKUP

gesture

accelerometer.StatusID.fifo: Retrieve the FIFO length by reading BMA456_REG_FIFO_LENGTH. The result is returned as an integer value.

accelerometer.StatusID.error: Gives the sensor health code as a 32-bit integer value, obtained by just concatenating the content of the registers BMA456_REG_INTERNAL_ERR: BMA456_REG_INTERNAL_STATUS: BMA456_REG_EVENT: BMA456_REG_ERROR in that order.

accelerometer.StatusID.activity: For the wearable and hearable feature set, read the current activity from the BMA456_FSWBL_REG_ACTIVITY_TYPE register and return the result as an instance of Activity. Indicate a failure if another feature set is active.

accelerometer.StatusID.stepCount: For the wearable and hearable feature set, return the current step count as read from the register BMA456_FSWBL_REG_STEP_COUNTER. The result is given as a 32 bit integer number.

accelerometer.StatusID.highG: For the MM feature set, retrieve the axis information for a high-G event from the BMA456_FSMM_REG_HIGH_G_OUTPUT register. The result is passed back as an AxesSign bit mask.

accelerometer.StatusID.orientation: For the MM feature set, retrieve the current orientation of the device as read from the BMA456_FSMM_REG_ORIENT_OUTPUT register. The result is given as an Orientation bit mask.

accelerometer.StatusID.tap: For the hearable and MM feature set, give the type of the recently detected tap (single, double etc.) as a Tap bit mask after reading that information from the BMA456_FSHBL_REG_FEAT_OUT and BMA456_FSMM_REG_MULTITAP_OUTPUT registers, respectively. For the wearable feature set, there are dedicated interrupts for this information, which get cleared upon reading. That’s why, getEventContext() should be intentionally used by the caller to retrieve this information.

accelerometer.StatusID.sensorTime: Retrieve the current sensor time in milli-seconds [ms]. The result is given as a Q24.8 integer value.

Also see: Sensor.getStatus().

Parameters:

statID (accelerometer.StatusID) – Identifies the status information to be retrieved.

Returns:

The status object and an error code indicating either success or the reason of failure.

Return type:

Object, ErrorCode

open(paramDict)[source]

Set up serial communication and initialize the chip.

Must be called once, before the device can be used. Carry out the following steps:

  • establish serial communication, attach device to bus, if necessary.

  • execute the device initialization procedure, see chapter 4.2 of the data sheet for more information.

  • adjust data rate and measurement range

  • set up interrupt GPIO pins - direction, trigger etc.

  • set up interrupt behavior - registers IOCTRL, INT1_MAP etc.

  • enable interrupts

Additionally to the defaults generated by Params_init(), the following configuration parameters are supported - as documented at GPIO.open():

  • BMA456.int1.gpio.pinDesignator

  • BMA456.int2.gpio.pinDesignator

Also see Sensor.open(), close().

registerInterruptHandler(onEvent=None, callerFeedBack=None, handler=None)[source]

Registers a handling routine for interrupt notification.

The caller feedback will be directly passed to the handling routine. In case that multiple different interrupts are handled by the same routine, this parameter may be used to distinguish them and remember the source of interrupt.

The handler should be a method or function that expects at least one argument. That first argument will be the callerFeedBack object given as the above-mentioned parameter. Further parameters may follow, as they were handed in to the _fire() method. The handler’s signature should look like this:

def handlingRoutine( feedback, *args) -> None:

Note that the onEvent parameter is not passed to the handler. It is eaten up by _fire() and just controls the selection of the handling routine called.

Depending on the parameter, this method behaves as follows:

onEvent

handler

semantics and action

Event.evtNone

None

All interrupts are disabled and all registrations cleared.

Event.evtNone

valid

De-register the given handler from all events {Event.evtInt1|2|Any}.

Event.evtInt1|2|*

None

De-register all handlers from the given event.

Event.evtInt1|2|*

valid

Enable interrupt and register this handler for the given event.

Event.evtAny

None

Clear the Event.evtAny registrations, only!

Event.evtAny

valid

Register the handler for any event {Event.evtInt1|2}.

For this method, Event.evtNone is a semantic equivalent to None.

Parameters:
  • onEvent (int) – Exactly one of the event mnemonics defined by the interruptable.Event enumeration.

  • callerFeedBack (object) – Arbitrary object not evaluated here, but passed on to the handler when an event is fired.

  • handler – The handling routine to be called as an immediate response to an event.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

reset()[source]

Reset the sensor to its default state.

After executing the reset command with the chip, it is re-configured using the start-up settings. Also, interrupt configuration is restored and interrupts are enabled.

Also see: Sensor.reset().

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

selfTest(tests)[source]

Execute one or more sensor self tests.

The test(s) to execute is given as a bit mask. This sensor supports the following tests:

SelfTest.CONNECTION: An attempt is made to read the sensor’s chip ID. If reading is successful, the result is compared to BMA456_CNT_CHIP_ID. On a match, the method returns successfully. Otherwise, a failure is indicated.

SelfTest.FUNCTIONAL: A functional sensor self test is executed as described in the data sheet, chapter 4.9.

Also see: Sensor.selfTest().

Parameters:

tests (int) – A bit mask to select the tests to be executed.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

setRunLevel(level)[source]

Switches the device to the desired power-save mode.

The given run level affects the hardware registers BMA456_REG_PWR_CTRL, BMA456_REG_PWR_CONF and BMA456_REG_ACC_CONF and, thus, chip behavior as follows:

RunLevel

ACC_EN

AUX_EN

FIFO_SELF_WAKEUP

ADV_POWER_SAVE

ACC_PERF_MODE

active

ENABLE

DISABLE

DISABLE

DISABLE

CONT

idle

ENABLE

DISABLE

DISABLE

DISABLE

AVG

relax

ENABLE

DISABLE

ENABLE

ENABLE

AVG

snooze

ENABLE

DISABLE

DISABLE

ENABLE

AVG

nap and below

DISABLE

DISABLE

DISABLE

ENABLE

AVG

For detailed information on the power modes of the underlying hardware, see the data shhet, chapter 4.3.

Also see Module.setRunLevel().

Parameters:

level (RunLevel) – The level to switch to.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

philander.bma456_reg module

Register definition for the BMA456 accelerometer.

Definition of registers, content masks and default values for the above mentioined chip. Externalized, just for clarity of the source code.

class BMA456_Reg[source]

Bases: object

BMA456_CNT_ACC_CONF_BWP = 112
BMA456_CNT_ACC_CONF_DEFAULT = 168
BMA456_CNT_ACC_CONF_MODE = 240
BMA456_CNT_ACC_CONF_MODE_AVG1 = 0
BMA456_CNT_ACC_CONF_MODE_AVG128 = 112
BMA456_CNT_ACC_CONF_MODE_AVG16 = 64
BMA456_CNT_ACC_CONF_MODE_AVG2 = 16
BMA456_CNT_ACC_CONF_MODE_AVG32 = 80
BMA456_CNT_ACC_CONF_MODE_AVG4 = 32
BMA456_CNT_ACC_CONF_MODE_AVG64 = 96
BMA456_CNT_ACC_CONF_MODE_AVG8 = 48
BMA456_CNT_ACC_CONF_MODE_CIC = 176
BMA456_CNT_ACC_CONF_MODE_DEFAULT = 160
BMA456_CNT_ACC_CONF_MODE_NORM = 160
BMA456_CNT_ACC_CONF_MODE_OSR2 = 144
BMA456_CNT_ACC_CONF_MODE_OSR4 = 128
BMA456_CNT_ACC_CONF_ODR = 15
BMA456_CNT_ACC_CONF_ODR_0P78 = 1
BMA456_CNT_ACC_CONF_ODR_100 = 8
BMA456_CNT_ACC_CONF_ODR_12K8 = 15
BMA456_CNT_ACC_CONF_ODR_12P5 = 5
BMA456_CNT_ACC_CONF_ODR_1K6 = 12
BMA456_CNT_ACC_CONF_ODR_1P5 = 2
BMA456_CNT_ACC_CONF_ODR_200 = 9
BMA456_CNT_ACC_CONF_ODR_25 = 6
BMA456_CNT_ACC_CONF_ODR_3K2 = 13
BMA456_CNT_ACC_CONF_ODR_3P1 = 3
BMA456_CNT_ACC_CONF_ODR_400 = 10
BMA456_CNT_ACC_CONF_ODR_50 = 7
BMA456_CNT_ACC_CONF_ODR_6K4 = 14
BMA456_CNT_ACC_CONF_ODR_6P25 = 4
BMA456_CNT_ACC_CONF_ODR_800 = 11
BMA456_CNT_ACC_CONF_ODR_DEFAULT = 8
BMA456_CNT_ACC_CONF_PERF_MODE = 128
BMA456_CNT_ACC_CONF_PERF_MODE_AVG = 0
BMA456_CNT_ACC_CONF_PERF_MODE_CONT = 128
BMA456_CNT_ACC_RANGE_16G = 3
BMA456_CNT_ACC_RANGE_2G = 0
BMA456_CNT_ACC_RANGE_4G = 1
BMA456_CNT_ACC_RANGE_8G = 2
BMA456_CNT_ACC_RANGE_DEFAULT = 1
BMA456_CNT_CHIP_ID = 22
BMA456_CNT_CMD_FIFO_FLUSH = 176
BMA456_CNT_CMD_NVM_PROG = 160
BMA456_CNT_CMD_SOFTRESET = 182
BMA456_CNT_ERROR_AUX = 128
BMA456_CNT_ERROR_CMD = 2
BMA456_CNT_ERROR_CODE = 28
BMA456_CNT_ERROR_CODE_ACC = 4
BMA456_CNT_ERROR_CODE_NONE = 0
BMA456_CNT_ERROR_FATAL = 1
BMA456_CNT_ERROR_FIFO = 64
BMA456_CNT_EVENT_POR = 1
BMA456_CNT_FEATURES_ANY_MOT1 = 0
BMA456_CNT_FEATURES_ANY_MOT2 = 2
BMA456_CNT_FEATURES_GEN_AXES_REMAP = 62
BMA456_CNT_FEATURES_GEN_CFG_ID = 60
BMA456_CNT_FEATURES_STEPBMA456_CNT1 = 4
BMA456_CNT_FEATURES_STEPBMA456_CNT10 = 22
BMA456_CNT_FEATURES_STEPBMA456_CNT11 = 24
BMA456_CNT_FEATURES_STEPBMA456_CNT12 = 26
BMA456_CNT_FEATURES_STEPBMA456_CNT13 = 28
BMA456_CNT_FEATURES_STEPBMA456_CNT14 = 30
BMA456_CNT_FEATURES_STEPBMA456_CNT15 = 32
BMA456_CNT_FEATURES_STEPBMA456_CNT16 = 34
BMA456_CNT_FEATURES_STEPBMA456_CNT17 = 36
BMA456_CNT_FEATURES_STEPBMA456_CNT18 = 38
BMA456_CNT_FEATURES_STEPBMA456_CNT19 = 40
BMA456_CNT_FEATURES_STEPBMA456_CNT2 = 6
BMA456_CNT_FEATURES_STEPBMA456_CNT20 = 42
BMA456_CNT_FEATURES_STEPBMA456_CNT21 = 44
BMA456_CNT_FEATURES_STEPBMA456_CNT22 = 46
BMA456_CNT_FEATURES_STEPBMA456_CNT23 = 48
BMA456_CNT_FEATURES_STEPBMA456_CNT24 = 50
BMA456_CNT_FEATURES_STEPBMA456_CNT25 = 52
BMA456_CNT_FEATURES_STEPBMA456_CNT26 = 54
BMA456_CNT_FEATURES_STEPBMA456_CNT3 = 8
BMA456_CNT_FEATURES_STEPBMA456_CNT4 = 10
BMA456_CNT_FEATURES_STEPBMA456_CNT5 = 12
BMA456_CNT_FEATURES_STEPBMA456_CNT6 = 14
BMA456_CNT_FEATURES_STEPBMA456_CNT7 = 16
BMA456_CNT_FEATURES_STEPBMA456_CNT8 = 18
BMA456_CNT_FEATURES_STEPBMA456_CNT9 = 20
BMA456_CNT_FEATURES_TAP_DTAP = 56
BMA456_CNT_FEATURES_WRIST_TILT = 58
BMA456_CNT_FIFO_CFG_ACC = 16384
BMA456_CNT_FIFO_CFG_ACC_DISABLE = 0
BMA456_CNT_FIFO_CFG_ACC_ENABLE = 16384
BMA456_CNT_FIFO_CFG_AUX = 8192
BMA456_CNT_FIFO_CFG_AUX_DISABLE = 0
BMA456_CNT_FIFO_CFG_AUX_ENABLE = 8192
BMA456_CNT_FIFO_CFG_HEAD = 4096
BMA456_CNT_FIFO_CFG_HEAD_DISABLE = 0
BMA456_CNT_FIFO_CFG_HEAD_ENABLE = 4096
BMA456_CNT_FIFO_CFG_INT1_TAG = 2048
BMA456_CNT_FIFO_CFG_INT1_TAG_DISABLE = 0
BMA456_CNT_FIFO_CFG_INT1_TAG_ENABLE = 2048
BMA456_CNT_FIFO_CFG_INT2_TAG = 1024
BMA456_CNT_FIFO_CFG_INT2_TAG_DISABLE = 0
BMA456_CNT_FIFO_CFG_INT2_TAG_ENABLE = 1024
BMA456_CNT_FIFO_CFG_STOP = 1
BMA456_CNT_FIFO_CFG_STOP_DISABLE = 0
BMA456_CNT_FIFO_CFG_STOP_ENABLE = 1
BMA456_CNT_FIFO_CFG_TIME = 2
BMA456_CNT_FIFO_CFG_TIME_DISABLE = 0
BMA456_CNT_FIFO_CFG_TIME_ENABLE = 2
BMA456_CNT_FIFO_DOWNS_DS0 = 0
BMA456_CNT_FIFO_DOWNS_DS1 = 16
BMA456_CNT_FIFO_DOWNS_DS2 = 32
BMA456_CNT_FIFO_DOWNS_DS3 = 48
BMA456_CNT_FIFO_DOWNS_DS4 = 64
BMA456_CNT_FIFO_DOWNS_DS5 = 80
BMA456_CNT_FIFO_DOWNS_DS6 = 96
BMA456_CNT_FIFO_DOWNS_DS7 = 112
BMA456_CNT_FIFO_DOWNS_DSAMPLING = 112
BMA456_CNT_FIFO_DOWNS_FILTER = 128
BMA456_CNT_FIFO_DOWNS_NOFILT = 0
BMA456_CNT_IF_CFG_AUX = 16
BMA456_CNT_IF_CFG_AUX_MAG = 16
BMA456_CNT_IF_CFG_AUX_OFF = 0
BMA456_CNT_IF_CFG_SPI = 1
BMA456_CNT_IF_CFG_SPI_3 = 1
BMA456_CNT_IF_CFG_SPI_4 = 0
BMA456_CNT_INIT_CTRL_LOAD_CONFIG_FILE = 0
BMA456_CNT_INIT_CTRL_START_INIT = 1
BMA456_CNT_INT1_IO_CTRL_COND = 1
BMA456_CNT_INT1_IO_CTRL_COND_EDGE = 1
BMA456_CNT_INT1_IO_CTRL_COND_LEVEL = 0
BMA456_CNT_INT1_IO_CTRL_DEFAULT = 0
BMA456_CNT_INT1_IO_CTRL_INPUT = 16
BMA456_CNT_INT1_IO_CTRL_INPUT_DISABLE = 0
BMA456_CNT_INT1_IO_CTRL_INPUT_ENABLE = 16
BMA456_CNT_INT1_IO_CTRL_LEVEL = 2
BMA456_CNT_INT1_IO_CTRL_LEVEL_ACT_HI = 2
BMA456_CNT_INT1_IO_CTRL_LEVEL_ACT_LOW = 0
BMA456_CNT_INT1_IO_CTRL_MODE = 4
BMA456_CNT_INT1_IO_CTRL_MODE_OPEN_DRAIN = 4
BMA456_CNT_INT1_IO_CTRL_MODE_PUSH_PULL = 0
BMA456_CNT_INT1_IO_CTRL_OUTPUT = 8
BMA456_CNT_INT1_IO_CTRL_OUTPUT_DISABLE = 0
BMA456_CNT_INT1_IO_CTRL_OUTPUT_ENABLE = 8
BMA456_CNT_INT2_IO_CTRL_COND = 1
BMA456_CNT_INT2_IO_CTRL_COND_EDGE = 1
BMA456_CNT_INT2_IO_CTRL_COND_LEVEL = 0
BMA456_CNT_INT2_IO_CTRL_DEFAULT = 0
BMA456_CNT_INT2_IO_CTRL_INPUT = 16
BMA456_CNT_INT2_IO_CTRL_INPUT_DISABLE = 0
BMA456_CNT_INT2_IO_CTRL_INPUT_ENABLE = 16
BMA456_CNT_INT2_IO_CTRL_LEVEL = 2
BMA456_CNT_INT2_IO_CTRL_LEVEL_ACT_HI = 2
BMA456_CNT_INT2_IO_CTRL_LEVEL_ACT_LOW = 0
BMA456_CNT_INT2_IO_CTRL_MODE = 4
BMA456_CNT_INT2_IO_CTRL_MODE_OPEN_DRAIN = 4
BMA456_CNT_INT2_IO_CTRL_MODE_PUSH_PULL = 0
BMA456_CNT_INT2_IO_CTRL_OUTPUT = 8
BMA456_CNT_INT2_IO_CTRL_OUTPUT_DISABLE = 0
BMA456_CNT_INT2_IO_CTRL_OUTPUT_ENABLE = 8
BMA456_CNT_INTERNAL_ERR_FATAL = 4
BMA456_CNT_INTERNAL_ERR_LONG = 2
BMA456_CNT_INTERNAL_STATUS_ALP_SLEEP = 16
BMA456_CNT_INTERNAL_STATUS_AXES_REMAP_ERROR = 32
BMA456_CNT_INTERNAL_STATUS_MSG = 15
BMA456_CNT_INTERNAL_STATUS_MSG_DRV_ERR = 3
BMA456_CNT_INTERNAL_STATUS_MSG_INIT_ERR = 2
BMA456_CNT_INTERNAL_STATUS_MSG_INIT_OK = 1
BMA456_CNT_INTERNAL_STATUS_MSG_NOT_INIT = 0
BMA456_CNT_INTERNAL_STATUS_MSG_SNS_STOP = 4
BMA456_CNT_INTERNAL_STATUS_ODR_50HZ_ERROR = 64
BMA456_CNT_INTERNAL_STATUS_ODR_HIGH_ERROR = 128
BMA456_CNT_INTX_MAP_ALL = 255
BMA456_CNT_INTX_MAP_DEFAULT = 0
BMA456_CNT_INTX_MAP_ERROR = 128
BMA456_CNT_INTX_MAP_NONE = 0
BMA456_CNT_INTX_MAP_TAP = 1
BMA456_CNT_INT_LATCH_NONE = 0
BMA456_CNT_INT_LATCH_PERM = 1
BMA456_CNT_INT_MAP_DATA_DEFAULT = 0
BMA456_CNT_INT_MAP_DATA_INT1_DRDY = 4
BMA456_CNT_INT_MAP_DATA_INT1_FIFO_FULL = 1
BMA456_CNT_INT_MAP_DATA_INT1_FIFO_WM = 2
BMA456_CNT_INT_MAP_DATA_INT2_DRDY = 64
BMA456_CNT_INT_MAP_DATA_INT2_FIFO_FULL = 16
BMA456_CNT_INT_MAP_DATA_INT2_FIFO_WM = 32
BMA456_CNT_INT_STATUS_ACC_DRDY = 32768
BMA456_CNT_INT_STATUS_AUX_DRDY = 8192
BMA456_CNT_INT_STATUS_ERROR = 128
BMA456_CNT_INT_STATUS_FIFO_FULL = 256
BMA456_CNT_INT_STATUS_FIFO_WM = 512
BMA456_CNT_NVM_BE_CFG_I2C_WDT = 4
BMA456_CNT_NVM_BE_CFG_I2C_WDTPER = 2
BMA456_CNT_NVM_BE_CFG_I2C_WDTPER_LONG = 2
BMA456_CNT_NVM_BE_CFG_I2C_WDTPER_SHORT = 0
BMA456_CNT_NVM_BE_CFG_I2C_WDT_DISABLE = 0
BMA456_CNT_NVM_BE_CFG_I2C_WDT_ENABLE = 4
BMA456_CNT_NVM_BE_CFG_OFFSET = 8
BMA456_CNT_NVM_BE_CFG_OFFSET_DISABLE = 0
BMA456_CNT_NVM_BE_CFG_OFFSET_ENABLE = 8
BMA456_CNT_NVM_BE_CFG_SPI = 1
BMA456_CNT_NVM_BE_CFG_SPI_DISABLE = 0
BMA456_CNT_NVM_BE_CFG_SPI_ENABLE = 1
BMA456_CNT_NVM_CFG_PPROG = 2
BMA456_CNT_NVM_CFG_PPROG_DISABLE = 0
BMA456_CNT_NVM_CFG_PPROG_ENABLE = 2
BMA456_CNT_PWR_CONF_ADV_PWR_SAVE = 1
BMA456_CNT_PWR_CONF_ADV_PWR_SAVE_DISABLE = 0
BMA456_CNT_PWR_CONF_ADV_PWR_SAVE_ENABLE = 1
BMA456_CNT_PWR_CONF_FIFO_WKUP = 2
BMA456_CNT_PWR_CONF_FIFO_WKUP_DISABLE = 0
BMA456_CNT_PWR_CONF_FIFO_WKUP_ENABLE = 2
BMA456_CNT_PWR_CTRL_ACC = 4
BMA456_CNT_PWR_CTRL_ACC_DISABLE = 0
BMA456_CNT_PWR_CTRL_ACC_ENABLE = 4
BMA456_CNT_PWR_CTRL_AUX = 1
BMA456_CNT_PWR_CTRL_AUX_DISABLE = 0
BMA456_CNT_PWR_CTRL_AUX_ENABLE = 1
BMA456_CNT_SELF_TST_AMP = 8
BMA456_CNT_SELF_TST_AMP_HI = 8
BMA456_CNT_SELF_TST_AMP_LOW = 0
BMA456_CNT_SELF_TST_DISABLE = 0
BMA456_CNT_SELF_TST_ENABLE = 1
BMA456_CNT_SELF_TST_SIGN = 4
BMA456_CNT_SELF_TST_SIGN_NEG = 0
BMA456_CNT_SELF_TST_SIGN_POS = 4
BMA456_CNT_STATUS_AUX_MAN_OP = 4
BMA456_CNT_STATUS_CMD_RDY = 16
BMA456_CNT_STATUS_DRDY_ACC = 128
BMA456_CNT_STATUS_DRDY_AUX = 32
BMA456_DEFAULT_FEATURE_SET = 0
BMA456_FEATURE_MAX_SIZE = 96
BMA456_FEATURE_SET_AN = 3
BMA456_FEATURE_SET_HEARABLE = 1
BMA456_FEATURE_SET_MM = 2
BMA456_FEATURE_SET_WEARABLE = 0
BMA456_FEAT_ANYNO_MOTION_DURATION = 8191
BMA456_FEAT_ANYNO_MOTION_DURATION_MAX_MS = 163000
BMA456_FEAT_ANYNO_MOTION_DURATION_MIN_MS = 0
BMA456_FEAT_ANYNO_MOTION_INT_BHVR = 2048
BMA456_FEAT_ANYNO_MOTION_INT_BHVR_MULTI = 0
BMA456_FEAT_ANYNO_MOTION_INT_BHVR_SINGLE = 2048
BMA456_FEAT_ANYNO_MOTION_SLOPE = 4096
BMA456_FEAT_ANYNO_MOTION_SLOPE_CONSEC = 4096
BMA456_FEAT_ANYNO_MOTION_SLOPE_LAST_TO_CURRENT = 0
BMA456_FEAT_ANYNO_MOTION_THRESHOLD = 2047
BMA456_FEAT_ANYNO_MOTION_THRESHOLD_MAX_MG = 1000
BMA456_FEAT_ANYNO_MOTION_THRESHOLD_MIN_MG = 0
BMA456_FEAT_ANYNO_MOTION_X_EN = 8192
BMA456_FEAT_ANYNO_MOTION_Y_EN = 16384
BMA456_FEAT_ANYNO_MOTION_Z_EN = 32768
BMA456_FEAT_AUTO_LOW_POWER_LP_ODR = 24576
BMA456_FEAT_AUTO_LOW_POWER_LP_ODR_12p5 = 24576
BMA456_FEAT_AUTO_LOW_POWER_LP_ODR_1p5625 = 0
BMA456_FEAT_AUTO_LOW_POWER_LP_ODR_3p125 = 8192
BMA456_FEAT_AUTO_LOW_POWER_LP_ODR_6p25 = 16384
BMA456_FEAT_AUTO_LOW_POWER_LP_ODR_MAX_HZ = 13
BMA456_FEAT_AUTO_LOW_POWER_LP_ODR_MIN_HZ = 1
BMA456_FEAT_AUTO_LOW_POWER_MGT_AUTO = 32768
BMA456_FEAT_AUTO_LOW_POWER_MGT_AUTO_DISABLE = 0
BMA456_FEAT_AUTO_LOW_POWER_MGT_AUTO_ENABLE = 32768
BMA456_FEAT_AUTO_LOW_POWER_NO_MOTION = 1
BMA456_FEAT_AUTO_LOW_POWER_TIME_OUT = 2
BMA456_FEAT_AUTO_LOW_POWER_TIME_OUT_DURATION = 4092
BMA456_FEAT_AUTO_LOW_POWER_TIME_OUT_DURATION_MAX_MS = 20460
BMA456_FEAT_AUTO_LOW_POWER_TIME_OUT_DURATION_MIN_MS = 0
BMA456_FEAT_AXES_REMAP_ALL_ON_X = 0
BMA456_FEAT_AXES_REMAP_ALL_ON_Y = 73
BMA456_FEAT_AXES_REMAP_ALL_ON_Z = 146
BMA456_FEAT_AXES_REMAP_STRAIGHT = 136
BMA456_FEAT_AXES_REMAP_X = 3
BMA456_FEAT_AXES_REMAP_X_SIGN = 4
BMA456_FEAT_AXES_REMAP_X_SIGN_INVERT = 4
BMA456_FEAT_AXES_REMAP_X_SIGN_KEEP = 0
BMA456_FEAT_AXES_REMAP_X_STRAIGHT = 0
BMA456_FEAT_AXES_REMAP_X_TO_X = 0
BMA456_FEAT_AXES_REMAP_X_TO_Y = 1
BMA456_FEAT_AXES_REMAP_X_TO_Z = 2
BMA456_FEAT_AXES_REMAP_Y = 24
BMA456_FEAT_AXES_REMAP_Y_SIGN = 32
BMA456_FEAT_AXES_REMAP_Y_SIGN_INVERT = 32
BMA456_FEAT_AXES_REMAP_Y_SIGN_KEEP = 0
BMA456_FEAT_AXES_REMAP_Y_STRAIGHT = 8
BMA456_FEAT_AXES_REMAP_Y_TO_X = 0
BMA456_FEAT_AXES_REMAP_Y_TO_Y = 8
BMA456_FEAT_AXES_REMAP_Y_TO_Z = 16
BMA456_FEAT_AXES_REMAP_Z = 192
BMA456_FEAT_AXES_REMAP_Z_SIGN = 256
BMA456_FEAT_AXES_REMAP_Z_SIGN_INVERT = 256
BMA456_FEAT_AXES_REMAP_Z_SIGN_KEEP = 0
BMA456_FEAT_AXES_REMAP_Z_STRAIGHT = 128
BMA456_FEAT_AXES_REMAP_Z_TO_X = 0
BMA456_FEAT_AXES_REMAP_Z_TO_Y = 64
BMA456_FEAT_AXES_REMAP_Z_TO_Z = 128
BMA456_FEAT_HIGH_G_ENABLE = 32768
BMA456_FEAT_HIGH_G_ENABLE_X = 4096
BMA456_FEAT_HIGH_G_ENABLE_Y = 8192
BMA456_FEAT_HIGH_G_ENABLE_Z = 16384
BMA456_FEAT_HIGH_G_HYSTERESIS_RCMD_MAX_MG = 2000
BMA456_FEAT_HIGH_G_HYSTERESIS_RCMD_MIN_MG = 0
BMA456_FEAT_HIGH_G_THRESHOLD_RCMD_MAX_MG = 16000
BMA456_FEAT_HIGH_G_THRESHOLD_RCMD_MIN_MG = 0
BMA456_FEAT_HILOW_G_DURATION = 4095
BMA456_FEAT_HILOW_G_DURATION_MAX_MS = 81900
BMA456_FEAT_HILOW_G_DURATION_MIN_MS = 0
BMA456_FEAT_HILOW_G_HYSTERESIS = 4095
BMA456_FEAT_HILOW_G_HYSTERESIS_MAX_MG = 2000
BMA456_FEAT_HILOW_G_HYSTERESIS_MIN_MG = 0
BMA456_FEAT_HILOW_G_SIG_THRESHOLD = 32767
BMA456_FEAT_HILOW_G_SIG_THRESHOLD_MAX_MG = 16000
BMA456_FEAT_HILOW_G_SIG_THRESHOLD_MIN_MG = 0
BMA456_FEAT_LOW_G_ENABLE = 4096
BMA456_FEAT_LOW_G_HYSTERESIS_RCMD_MAX_MG = 500
BMA456_FEAT_LOW_G_HYSTERESIS_RCMD_MIN_MG = 0
BMA456_FEAT_LOW_G_THRESHOLD_RCMD_MAX_MG = 1000
BMA456_FEAT_LOW_G_THRESHOLD_RCMD_MIN_MG = 0
BMA456_FEAT_MULTITAP_AXIS_SELECT = 3
BMA456_FEAT_MULTITAP_AXIS_SELECT_X = 0
BMA456_FEAT_MULTITAP_AXIS_SELECT_Y = 1
BMA456_FEAT_MULTITAP_AXIS_SELECT_Z = 2
BMA456_FEAT_MULTITAP_DURATION = 65535
BMA456_FEAT_MULTITAP_DURATION_GEST_RCMD_MAX_MS = 1000
BMA456_FEAT_MULTITAP_DURATION_GEST_RCMD_MIN_MS = 250
BMA456_FEAT_MULTITAP_DURATION_QUIET_RCMD_MAX_MS = 500
BMA456_FEAT_MULTITAP_DURATION_QUIET_RCMD_MIN_MS = 250
BMA456_FEAT_MULTITAP_DURATION_SHOCK_RCMD_MAX_MS = 100
BMA456_FEAT_MULTITAP_DURATION_SHOCK_RCMD_MIN_MS = 20
BMA456_FEAT_MULTITAP_ENABLE_AVERAGING2 = 8
BMA456_FEAT_MULTITAP_ENABLE_DOUBLE_TAP = 2
BMA456_FEAT_MULTITAP_ENABLE_SINGLE_TAP = 1
BMA456_FEAT_MULTITAP_ENABLE_TRIPLE_TAP = 4
BMA456_FEAT_MULTITAP_SENSITIVITY = 65535
BMA456_FEAT_MULTITAP_SENSITIVITY_RCMD_MAX_MG = 1200
BMA456_FEAT_MULTITAP_SENSITIVITY_RCND_MIN_MG = 0
BMA456_FEAT_MULTITAP_TIMEOUT = 65535
BMA456_FEAT_MULTITAP_TIMEOUT_DISABLE = 0
BMA456_FEAT_MULTITAP_TIMEOUT_ENABLE = 1
BMA456_FEAT_ORIENTATION_BLOCKING = 48
BMA456_FEAT_ORIENTATION_BLOCKING_MOST = 48
BMA456_FEAT_ORIENTATION_BLOCKING_NONE = 0
BMA456_FEAT_ORIENTATION_BLOCKING_SHAKE = 32
BMA456_FEAT_ORIENTATION_BLOCKING_SHOCK = 16
BMA456_FEAT_ORIENTATION_ENABLE = 1
BMA456_FEAT_ORIENTATION_FACE_UPDOWN_ENABLE = 2
BMA456_FEAT_ORIENTATION_HYSTERESIS = 2047
BMA456_FEAT_ORIENTATION_HYSTERESIS_MAX_MG = 1000
BMA456_FEAT_ORIENTATION_HYSTERESIS_MIN_MG = 0
BMA456_FEAT_ORIENTATION_MODE = 12
BMA456_FEAT_ORIENTATION_MODE_ASYMMETRIC_HI = 4
BMA456_FEAT_ORIENTATION_MODE_ASYMMETRIC_LO = 8
BMA456_FEAT_ORIENTATION_MODE_SYMMETRIC = 0
BMA456_FEAT_ORIENTATION_THETA = 4032
BMA456_FEAT_ORIENTATION_THETA_BITSHIFT = 6
BMA456_FEAT_ORIENTATION_THETA_DEG_0 = 0
BMA456_FEAT_ORIENTATION_THETA_DEG_0p0 = 0
BMA456_FEAT_ORIENTATION_THETA_DEG_10 = 128
BMA456_FEAT_ORIENTATION_THETA_DEG_10p0 = 128
BMA456_FEAT_ORIENTATION_THETA_DEG_12p2 = 192
BMA456_FEAT_ORIENTATION_THETA_DEG_14p0 = 256
BMA456_FEAT_ORIENTATION_THETA_DEG_15 = 320
BMA456_FEAT_ORIENTATION_THETA_DEG_15p6 = 320
BMA456_FEAT_ORIENTATION_THETA_DEG_17p0 = 384
BMA456_FEAT_ORIENTATION_THETA_DEG_18p3 = 448
BMA456_FEAT_ORIENTATION_THETA_DEG_19p5 = 512
BMA456_FEAT_ORIENTATION_THETA_DEG_20 = 512
BMA456_FEAT_ORIENTATION_THETA_DEG_20p6 = 576
BMA456_FEAT_ORIENTATION_THETA_DEG_21p6 = 640
BMA456_FEAT_ORIENTATION_THETA_DEG_22p5 = 704
BMA456_FEAT_ORIENTATION_THETA_DEG_23p4 = 768
BMA456_FEAT_ORIENTATION_THETA_DEG_24p3 = 832
BMA456_FEAT_ORIENTATION_THETA_DEG_25 = 896
BMA456_FEAT_ORIENTATION_THETA_DEG_25p1 = 896
BMA456_FEAT_ORIENTATION_THETA_DEG_25p8 = 960
BMA456_FEAT_ORIENTATION_THETA_DEG_26p6 = 1024
BMA456_FEAT_ORIENTATION_THETA_DEG_27p3 = 1088
BMA456_FEAT_ORIENTATION_THETA_DEG_27p9 = 1152
BMA456_FEAT_ORIENTATION_THETA_DEG_28p6 = 1216
BMA456_FEAT_ORIENTATION_THETA_DEG_29p2 = 1280
BMA456_FEAT_ORIENTATION_THETA_DEG_29p8 = 1344
BMA456_FEAT_ORIENTATION_THETA_DEG_30 = 1344
BMA456_FEAT_ORIENTATION_THETA_DEG_30p4 = 1408
BMA456_FEAT_ORIENTATION_THETA_DEG_30p9 = 1472
BMA456_FEAT_ORIENTATION_THETA_DEG_31p5 = 1536
BMA456_FEAT_ORIENTATION_THETA_DEG_32p0 = 1600
BMA456_FEAT_ORIENTATION_THETA_DEG_32p5 = 1664
BMA456_FEAT_ORIENTATION_THETA_DEG_33p0 = 1728
BMA456_FEAT_ORIENTATION_THETA_DEG_33p5 = 1792
BMA456_FEAT_ORIENTATION_THETA_DEG_33p9 = 1856
BMA456_FEAT_ORIENTATION_THETA_DEG_34p4 = 1920
BMA456_FEAT_ORIENTATION_THETA_DEG_34p8 = 1984
BMA456_FEAT_ORIENTATION_THETA_DEG_35 = 1984
BMA456_FEAT_ORIENTATION_THETA_DEG_35p3 = 2048
BMA456_FEAT_ORIENTATION_THETA_DEG_35p7 = 2112
BMA456_FEAT_ORIENTATION_THETA_DEG_36p1 = 2176
BMA456_FEAT_ORIENTATION_THETA_DEG_36p5 = 2240
BMA456_FEAT_ORIENTATION_THETA_DEG_36p9 = 2304
BMA456_FEAT_ORIENTATION_THETA_DEG_37p2 = 2368
BMA456_FEAT_ORIENTATION_THETA_DEG_37p6 = 2432
BMA456_FEAT_ORIENTATION_THETA_DEG_38p0 = 2496
BMA456_FEAT_ORIENTATION_THETA_DEG_38p3 = 2560
BMA456_FEAT_ORIENTATION_THETA_DEG_38p7 = 2624
BMA456_FEAT_ORIENTATION_THETA_DEG_39p0 = 2688
BMA456_FEAT_ORIENTATION_THETA_DEG_39p3 = 2752
BMA456_FEAT_ORIENTATION_THETA_DEG_39p7 = 2816
BMA456_FEAT_ORIENTATION_THETA_DEG_40 = 2880
BMA456_FEAT_ORIENTATION_THETA_DEG_40p0 = 2880
BMA456_FEAT_ORIENTATION_THETA_DEG_40p3 = 2944
BMA456_FEAT_ORIENTATION_THETA_DEG_40p6 = 3008
BMA456_FEAT_ORIENTATION_THETA_DEG_40p9 = 3072
BMA456_FEAT_ORIENTATION_THETA_DEG_41p2 = 3136
BMA456_FEAT_ORIENTATION_THETA_DEG_41p5 = 3200
BMA456_FEAT_ORIENTATION_THETA_DEG_41p8 = 3264
BMA456_FEAT_ORIENTATION_THETA_DEG_42p0 = 3328
BMA456_FEAT_ORIENTATION_THETA_DEG_42p3 = 3392
BMA456_FEAT_ORIENTATION_THETA_DEG_42p6 = 3456
BMA456_FEAT_ORIENTATION_THETA_DEG_42p8 = 3520
BMA456_FEAT_ORIENTATION_THETA_DEG_43p1 = 3584
BMA456_FEAT_ORIENTATION_THETA_DEG_43p3 = 3648
BMA456_FEAT_ORIENTATION_THETA_DEG_43p6 = 3712
BMA456_FEAT_ORIENTATION_THETA_DEG_43p8 = 3776
BMA456_FEAT_ORIENTATION_THETA_DEG_44p1 = 3840
BMA456_FEAT_ORIENTATION_THETA_DEG_44p3 = 3904
BMA456_FEAT_ORIENTATION_THETA_DEG_44p5 = 3968
BMA456_FEAT_ORIENTATION_THETA_DEG_44p8 = 4032
BMA456_FEAT_ORIENTATION_THETA_DEG_45 = 4032
BMA456_FEAT_ORIENTATION_THETA_DEG_5 = 64
BMA456_FEAT_ORIENTATION_THETA_DEG_7p1 = 64
BMA456_FEAT_ORIENTATION_THETA_MAX = 4032
BMA456_FEAT_ORIENTATION_THETA_MAX_DEG = 45
BMA456_FEAT_ORIENTATION_THETA_MIN = 0
BMA456_FEAT_ORIENTATION_THETA_MIN_DEG = 0
BMA456_FEAT_ORIENTATION_THETA_UNIT = 64
BMA456_FEAT_PROOF_TIME = 127
BMA456_FEAT_PROOF_TIME_MAX_MS = 2540
BMA456_FEAT_PROOF_TIME_MIN_MS = 0
BMA456_FEAT_SKIP_TIME = 511
BMA456_FEAT_SKIP_TIME_MAX_MS = 10220
BMA456_FEAT_SKIP_TIME_MIN_MS = 0
BMA456_FEAT_STEP_COUNTER_ENABLE_ACTIVITY = 8192
BMA456_FEAT_STEP_COUNTER_ENABLE_COUNT = 4096
BMA456_FEAT_STEP_COUNTER_ENABLE_DETECT = 2048
BMA456_FEAT_STEP_COUNTER_RESET_COUNTER = 1024
BMA456_FEAT_STEP_COUNTER_WATERMARK_LEVEL = 1023
BMA456_FEAT_STEP_COUNTER_WATERMARK_MAX_STEPS = 20460
BMA456_FEAT_STEP_COUNTER_WATERMARK_MIN_STEPS = 20
BMA456_FEAT_TAP_ENABLE = 1
BMA456_FEAT_TAP_SENSITIVITY = 14
BMA456_FEAT_TAP_SENSITIVITY_0 = 0
BMA456_FEAT_TAP_SENSITIVITY_1 = 2
BMA456_FEAT_TAP_SENSITIVITY_2 = 4
BMA456_FEAT_TAP_SENSITIVITY_3 = 6
BMA456_FEAT_TAP_SENSITIVITY_4 = 8
BMA456_FEAT_TAP_SENSITIVITY_5 = 10
BMA456_FEAT_TAP_SENSITIVITY_6 = 12
BMA456_FEAT_TAP_SENSITIVITY_7 = 14
BMA456_FEAT_TAP_SENSITIVITY_HIGHEST = 0
BMA456_FEAT_TAP_SENSITIVITY_LOWEST = 14
BMA456_FEAT_TAP_SENSITIVITY_MAX_VAL = 7
BMA456_FEAT_TAP_SENSITIVITY_MIN_VAL = 0
BMA456_FEAT_WRIST_WAKEUP_ANGLE_LANDSCAPE_LEFT = 65280
BMA456_FEAT_WRIST_WAKEUP_ANGLE_LANDSCAPE_RIGHT = 255
BMA456_FEAT_WRIST_WAKEUP_ANGLE_PORTRAIT_DOWN = 255
BMA456_FEAT_WRIST_WAKEUP_ANGLE_PORTRAIT_UP = 65280
BMA456_FEAT_WRIST_WAKEUP_DURATION_MOVED = 255
BMA456_FEAT_WRIST_WAKEUP_DURATION_QUIET = 65280
BMA456_FEAT_WRIST_WAKEUP_ENABLE = 16
BMA456_FSAN_CNT_INTX_MAP_ANY_MOTION = 32
BMA456_FSAN_CNT_INTX_MAP_ERROR = 128
BMA456_FSAN_CNT_INTX_MAP_NO_MOTION = 64
BMA456_FSAN_CNT_INT_STATUS_ANY_MOTION = 32
BMA456_FSAN_CNT_INT_STATUS_ERROR = 128
BMA456_FSAN_CNT_INT_STATUS_NO_MOTION = 64
BMA456_FSAN_IDX_ANY_MOTION_1 = 0
BMA456_FSAN_IDX_ANY_MOTION_2 = 2
BMA456_FSAN_IDX_GENERAL_AXES_REMAP = 10
BMA456_FSAN_IDX_GENERAL_CONFIG_ID = 8
BMA456_FSAN_IDX_NO_MOTION_1 = 4
BMA456_FSAN_IDX_NO_MOTION_2 = 6
BMA456_FSAN_TOTAL_SIZE = 12
BMA456_FSHBL_CNT_FEAT_EN1_ANYMO = 56
BMA456_FSHBL_CNT_FEAT_EN1_ANYMO_ALL = 56
BMA456_FSHBL_CNT_FEAT_EN1_ANYMO_NONE = 0
BMA456_FSHBL_CNT_FEAT_EN1_ANYMO_X = 8
BMA456_FSHBL_CNT_FEAT_EN1_ANYMO_Y = 16
BMA456_FSHBL_CNT_FEAT_EN1_ANYMO_Z = 32
BMA456_FSHBL_CNT_FEAT_EN1_NOMO = 7
BMA456_FSHBL_CNT_FEAT_EN1_NOMO_ALL = 7
BMA456_FSHBL_CNT_FEAT_EN1_NOMO_NONE = 0
BMA456_FSHBL_CNT_FEAT_EN1_NOMO_X = 1
BMA456_FSHBL_CNT_FEAT_EN1_NOMO_Y = 2
BMA456_FSHBL_CNT_FEAT_EN1_NOMO_Z = 4
BMA456_FSHBL_CNT_FEAT_EN1_SW_LOCK = 192
BMA456_FSHBL_CNT_FEAT_EN1_SW_LOCK_CALC = 192
BMA456_FSHBL_CNT_FEAT_EN1_SW_LOCK_CLEAR = 0
BMA456_FSHBL_CNT_FEAT_EN2_ACTIVITY_DETECT = 4
BMA456_FSHBL_CNT_FEAT_EN2_AUTO_LOW_POW = 8
BMA456_FSHBL_CNT_FEAT_EN2_AVERAGING2 = 128
BMA456_FSHBL_CNT_FEAT_EN2_DTAP = 32
BMA456_FSHBL_CNT_FEAT_EN2_STAP = 16
BMA456_FSHBL_CNT_FEAT_EN2_STEP_COUNT = 2
BMA456_FSHBL_CNT_FEAT_EN2_STEP_DETECT = 1
BMA456_FSHBL_CNT_FEAT_EN2_TTAP = 64
BMA456_FSHBL_CNT_FEAT_OUT_ACTTYPE = 3
BMA456_FSHBL_CNT_FEAT_OUT_ACTTYPE_RUN = 2
BMA456_FSHBL_CNT_FEAT_OUT_ACTTYPE_STILL = 0
BMA456_FSHBL_CNT_FEAT_OUT_ACTTYPE_UNKNOWN = 3
BMA456_FSHBL_CNT_FEAT_OUT_ACTTYPE_WALK = 1
BMA456_FSHBL_CNT_FEAT_OUT_DTAP = 8
BMA456_FSHBL_CNT_FEAT_OUT_STAP = 4
BMA456_FSHBL_CNT_FEAT_OUT_TTAP = 16
BMA456_FSHBL_CNT_INTX_MAP_ACTIVITY = 4
BMA456_FSHBL_CNT_INTX_MAP_ANY_MOTION = 16
BMA456_FSHBL_CNT_INTX_MAP_ERROR = 128
BMA456_FSHBL_CNT_INTX_MAP_NO_MOTION = 32
BMA456_FSHBL_CNT_INTX_MAP_STEP_CNT = 2
BMA456_FSHBL_CNT_INTX_MAP_TAP = 1
BMA456_FSHBL_CNT_INT_STATUS_ACTIVITY = 4
BMA456_FSHBL_CNT_INT_STATUS_ANY_MOTION = 16
BMA456_FSHBL_CNT_INT_STATUS_ERROR = 128
BMA456_FSHBL_CNT_INT_STATUS_NO_MOTION = 32
BMA456_FSHBL_CNT_INT_STATUS_STEP_COUNT = 2
BMA456_FSHBL_CNT_INT_STATUS_TAP_DETECT = 1
BMA456_FSHBL_DEF_AUTO_LOW_POWER_TIME_OUT_DURATION = 8188
BMA456_FSHBL_DEF_AUTO_LOW_POWER_TIME_OUT_DURATION_MAX_MS = 40940
BMA456_FSHBL_DEF_AUTO_LOW_POWER_TIME_OUT_DURATION_MIN_MS = 0
BMA456_FSHBL_IDX_ANY_MOTION_1 = 0
BMA456_FSHBL_IDX_ANY_MOTION_2 = 2
BMA456_FSHBL_IDX_AUTO_LOW_POWER = 88
BMA456_FSHBL_IDX_GENERAL_AXES_REMAP = 92
BMA456_FSHBL_IDX_GENERAL_CONFIG_ID = 90
BMA456_FSHBL_IDX_MULTI_TAP_1 = 60
BMA456_FSHBL_IDX_MULTI_TAP_10 = 78
BMA456_FSHBL_IDX_MULTI_TAP_11 = 80
BMA456_FSHBL_IDX_MULTI_TAP_12 = 82
BMA456_FSHBL_IDX_MULTI_TAP_2 = 62
BMA456_FSHBL_IDX_MULTI_TAP_3 = 64
BMA456_FSHBL_IDX_MULTI_TAP_4 = 66
BMA456_FSHBL_IDX_MULTI_TAP_5 = 68
BMA456_FSHBL_IDX_MULTI_TAP_6 = 70
BMA456_FSHBL_IDX_MULTI_TAP_7 = 72
BMA456_FSHBL_IDX_MULTI_TAP_8 = 74
BMA456_FSHBL_IDX_MULTI_TAP_9 = 76
BMA456_FSHBL_IDX_NO_MOTION_1 = 4
BMA456_FSHBL_IDX_NO_MOTION_2 = 6
BMA456_FSHBL_IDX_SOFTWARE_LOCK_IN = 84
BMA456_FSHBL_IDX_SOFTWARE_LOCK_OUT = 86
BMA456_FSHBL_IDX_STEP_COUNTER_1 = 8
BMA456_FSHBL_IDX_STEP_COUNTER_10 = 26
BMA456_FSHBL_IDX_STEP_COUNTER_11 = 28
BMA456_FSHBL_IDX_STEP_COUNTER_12 = 30
BMA456_FSHBL_IDX_STEP_COUNTER_13 = 32
BMA456_FSHBL_IDX_STEP_COUNTER_14 = 34
BMA456_FSHBL_IDX_STEP_COUNTER_15 = 36
BMA456_FSHBL_IDX_STEP_COUNTER_16 = 38
BMA456_FSHBL_IDX_STEP_COUNTER_17 = 40
BMA456_FSHBL_IDX_STEP_COUNTER_18 = 42
BMA456_FSHBL_IDX_STEP_COUNTER_19 = 44
BMA456_FSHBL_IDX_STEP_COUNTER_2 = 10
BMA456_FSHBL_IDX_STEP_COUNTER_20 = 46
BMA456_FSHBL_IDX_STEP_COUNTER_21 = 48
BMA456_FSHBL_IDX_STEP_COUNTER_22 = 50
BMA456_FSHBL_IDX_STEP_COUNTER_23 = 52
BMA456_FSHBL_IDX_STEP_COUNTER_24 = 54
BMA456_FSHBL_IDX_STEP_COUNTER_25 = 56
BMA456_FSHBL_IDX_STEP_COUNTER_26 = 58
BMA456_FSHBL_IDX_STEP_COUNTER_3 = 12
BMA456_FSHBL_IDX_STEP_COUNTER_4 = 14
BMA456_FSHBL_IDX_STEP_COUNTER_5 = 16
BMA456_FSHBL_IDX_STEP_COUNTER_6 = 18
BMA456_FSHBL_IDX_STEP_COUNTER_7 = 20
BMA456_FSHBL_IDX_STEP_COUNTER_8 = 22
BMA456_FSHBL_IDX_STEP_COUNTER_9 = 24
BMA456_FSHBL_REG_FEAT_EN1 = 40
BMA456_FSHBL_REG_FEAT_EN2 = 41
BMA456_FSHBL_REG_FEAT_OUT = 39
BMA456_FSHBL_REG_STEP_COUNTER = 30
BMA456_FSHBL_REG_STEP_COUNTER0 = 30
BMA456_FSHBL_REG_STEP_COUNTER1 = 31
BMA456_FSHBL_REG_STEP_COUNTER2 = 32
BMA456_FSHBL_REG_STEP_COUNTER3 = 33
BMA456_FSHBL_TOTAL_SIZE = 94
BMA456_FSMM_CNT_HIGH_G_OUTPUT_AXES = 7
BMA456_FSMM_CNT_HIGH_G_OUTPUT_AXES_X = 1
BMA456_FSMM_CNT_HIGH_G_OUTPUT_AXES_Y = 2
BMA456_FSMM_CNT_HIGH_G_OUTPUT_AXES_Z = 4
BMA456_FSMM_CNT_HIGH_G_OUTPUT_SIGN = 8
BMA456_FSMM_CNT_HIGH_G_OUTPUT_SIGN_NEG = 8
BMA456_FSMM_CNT_HIGH_G_OUTPUT_SIGN_POS = 0
BMA456_FSMM_CNT_INTX_MAP_ANY_MOTION = 32
BMA456_FSMM_CNT_INTX_MAP_ERROR = 128
BMA456_FSMM_CNT_INTX_MAP_HIGH_G = 8
BMA456_FSMM_CNT_INTX_MAP_LOW_G = 4
BMA456_FSMM_CNT_INTX_MAP_NO_MOTION = 64
BMA456_FSMM_CNT_INTX_MAP_ORIENT = 2
BMA456_FSMM_CNT_INTX_MAP_SIG_MOTION = 16
BMA456_FSMM_CNT_INTX_MAP_TAP = 1
BMA456_FSMM_CNT_INT_STATUS_ANY_MOTION = 32
BMA456_FSMM_CNT_INT_STATUS_ERROR = 128
BMA456_FSMM_CNT_INT_STATUS_HIGH_G = 8
BMA456_FSMM_CNT_INT_STATUS_LOW_G = 4
BMA456_FSMM_CNT_INT_STATUS_NO_MOTION = 64
BMA456_FSMM_CNT_INT_STATUS_ORIENT = 2
BMA456_FSMM_CNT_INT_STATUS_SIG_MOTION = 16
BMA456_FSMM_CNT_INT_STATUS_TAP_DETECT = 1
BMA456_FSMM_CNT_MULTITAP_OUTPUT_DTAP = 2
BMA456_FSMM_CNT_MULTITAP_OUTPUT_STAP = 1
BMA456_FSMM_CNT_MULTITAP_OUTPUT_TTAP = 4
BMA456_FSMM_CNT_ORIENT_OUTPUT_FACE = 4
BMA456_FSMM_CNT_ORIENT_OUTPUT_FACE_DOWN = 4
BMA456_FSMM_CNT_ORIENT_OUTPUT_FACE_UP = 0
BMA456_FSMM_CNT_ORIENT_OUTPUT_STAND = 3
BMA456_FSMM_CNT_ORIENT_OUTPUT_STAND_LAND_LEFT = 1
BMA456_FSMM_CNT_ORIENT_OUTPUT_STAND_LAND_RIGHT = 3
BMA456_FSMM_CNT_ORIENT_OUTPUT_STAND_PORT_DOWN = 2
BMA456_FSMM_CNT_ORIENT_OUTPUT_STAND_PORT_UP = 0
BMA456_FSMM_DEF_AUTO_LOW_POWER_ENABLE = 4096
BMA456_FSMM_DEF_AUTO_LOW_POWER_TIME_OUT_DURATION = 4092
BMA456_FSMM_DEF_AUTO_LOW_POWER_TIME_OUT_DURATION_MAX_MS = 20460
BMA456_FSMM_DEF_AUTO_LOW_POWER_TIME_OUT_DURATION_MIN_MS = 0
BMA456_FSMM_DEF_SIG_MOTION_ENABLE = 512
BMA456_FSMM_IDX_ANY_MOTION_1 = 0
BMA456_FSMM_IDX_ANY_MOTION_2 = 2
BMA456_FSMM_IDX_AUTO_LOW_POWER = 44
BMA456_FSMM_IDX_GENERAL_AXES_REMAP = 60
BMA456_FSMM_IDX_GENERAL_CONFIG_ID = 58
BMA456_FSMM_IDX_HIGH_G_1 = 46
BMA456_FSMM_IDX_HIGH_G_2 = 48
BMA456_FSMM_IDX_HIGH_G_3 = 50
BMA456_FSMM_IDX_LOW_G_1 = 12
BMA456_FSMM_IDX_LOW_G_2 = 14
BMA456_FSMM_IDX_LOW_G_3 = 16
BMA456_FSMM_IDX_MULTI_TAP_1 = 18
BMA456_FSMM_IDX_MULTI_TAP_2 = 22
BMA456_FSMM_IDX_MULTI_TAP_3 = 24
BMA456_FSMM_IDX_MULTI_TAP_4 = 28
BMA456_FSMM_IDX_MULTI_TAP_5 = 32
BMA456_FSMM_IDX_MULTI_TAP_6 = 34
BMA456_FSMM_IDX_MULTI_TAP_7 = 38
BMA456_FSMM_IDX_NO_MOTION_1 = 4
BMA456_FSMM_IDX_NO_MOTION_2 = 6
BMA456_FSMM_IDX_ORIENT_1 = 8
BMA456_FSMM_IDX_ORIENT_2 = 10
BMA456_FSMM_IDX_SIG_MOTION_1 = 52
BMA456_FSMM_IDX_SIG_MOTION_2 = 54
BMA456_FSMM_IDX_SIG_MOTION_3 = 56
BMA456_FSMM_REG_HIGH_G_OUTPUT = 31
BMA456_FSMM_REG_MULTITAP_OUTPUT = 32
BMA456_FSMM_REG_ORIENT_OUTPUT = 30
BMA456_FSMM_TOTAL_SIZE = 62
BMA456_FSWBL_CNT_ACTIVITY_TYPE = 3
BMA456_FSWBL_CNT_ACTIVITY_TYPE_RUN = 2
BMA456_FSWBL_CNT_ACTIVITY_TYPE_STILL = 0
BMA456_FSWBL_CNT_ACTIVITY_TYPE_UNKNOWN = 3
BMA456_FSWBL_CNT_ACTIVITY_TYPE_WALK = 1
BMA456_FSWBL_CNT_INTX_MAP_ACTIVITY = 4
BMA456_FSWBL_CNT_INTX_MAP_ANY_MOTION = 32
BMA456_FSWBL_CNT_INTX_MAP_DTAP = 16
BMA456_FSWBL_CNT_INTX_MAP_ERROR = 128
BMA456_FSWBL_CNT_INTX_MAP_NO_MOTION = 64
BMA456_FSWBL_CNT_INTX_MAP_STAP = 1
BMA456_FSWBL_CNT_INTX_MAP_STEP_CNT = 2
BMA456_FSWBL_CNT_INTX_MAP_WRIST_WKUP = 8
BMA456_FSWBL_CNT_INT_STATUS_ACTIVITY = 4
BMA456_FSWBL_CNT_INT_STATUS_ANY_MOTION = 32
BMA456_FSWBL_CNT_INT_STATUS_DBL_TAP = 16
BMA456_FSWBL_CNT_INT_STATUS_ERROR = 128
BMA456_FSWBL_CNT_INT_STATUS_NO_MOTION = 64
BMA456_FSWBL_CNT_INT_STATUS_STEP_COUNT = 2
BMA456_FSWBL_CNT_INT_STATUS_TAP_DETECT = 1
BMA456_FSWBL_CNT_INT_STATUS_WRIST_WKUP = 8
BMA456_FSWBL_IDX_ANY_MOTION_1 = 0
BMA456_FSWBL_IDX_ANY_MOTION_2 = 2
BMA456_FSWBL_IDX_GENERAL_AXES_REMAP = 74
BMA456_FSWBL_IDX_GENERAL_CONFIG_ID = 72
BMA456_FSWBL_IDX_NO_MOTION_1 = 4
BMA456_FSWBL_IDX_NO_MOTION_2 = 6
BMA456_FSWBL_IDX_STEP_COUNTER_1 = 8
BMA456_FSWBL_IDX_STEP_COUNTER_10 = 26
BMA456_FSWBL_IDX_STEP_COUNTER_11 = 28
BMA456_FSWBL_IDX_STEP_COUNTER_12 = 30
BMA456_FSWBL_IDX_STEP_COUNTER_13 = 32
BMA456_FSWBL_IDX_STEP_COUNTER_14 = 34
BMA456_FSWBL_IDX_STEP_COUNTER_15 = 36
BMA456_FSWBL_IDX_STEP_COUNTER_16 = 38
BMA456_FSWBL_IDX_STEP_COUNTER_17 = 40
BMA456_FSWBL_IDX_STEP_COUNTER_18 = 42
BMA456_FSWBL_IDX_STEP_COUNTER_19 = 44
BMA456_FSWBL_IDX_STEP_COUNTER_2 = 10
BMA456_FSWBL_IDX_STEP_COUNTER_20 = 46
BMA456_FSWBL_IDX_STEP_COUNTER_21 = 48
BMA456_FSWBL_IDX_STEP_COUNTER_22 = 50
BMA456_FSWBL_IDX_STEP_COUNTER_23 = 52
BMA456_FSWBL_IDX_STEP_COUNTER_24 = 54
BMA456_FSWBL_IDX_STEP_COUNTER_25 = 56
BMA456_FSWBL_IDX_STEP_COUNTER_26 = 58
BMA456_FSWBL_IDX_STEP_COUNTER_3 = 12
BMA456_FSWBL_IDX_STEP_COUNTER_4 = 14
BMA456_FSWBL_IDX_STEP_COUNTER_5 = 16
BMA456_FSWBL_IDX_STEP_COUNTER_6 = 18
BMA456_FSWBL_IDX_STEP_COUNTER_7 = 20
BMA456_FSWBL_IDX_STEP_COUNTER_8 = 22
BMA456_FSWBL_IDX_STEP_COUNTER_9 = 24
BMA456_FSWBL_IDX_WRIST_WAKEUP = 60
BMA456_FSWBL_IDX_WRIST_WAKEUP_ANGLE_LANDSCAPE = 66
BMA456_FSWBL_IDX_WRIST_WAKEUP_ANGLE_PORTRAIT = 68
BMA456_FSWBL_IDX_WRIST_WAKEUP_DURATION = 70
BMA456_FSWBL_IDX_WRIST_WAKEUP_MINANGLE_FOCUS = 62
BMA456_FSWBL_IDX_WRIST_WAKEUP_MINANGLE_NONFOCUS = 64
BMA456_FSWBL_REG_ACTIVITY_TYPE = 39
BMA456_FSWBL_REG_STEP_COUNTER = 30
BMA456_FSWBL_REG_STEP_COUNTER0 = 30
BMA456_FSWBL_REG_STEP_COUNTER1 = 31
BMA456_FSWBL_REG_STEP_COUNTER2 = 32
BMA456_FSWBL_REG_STEP_COUNTER3 = 33
BMA456_FSWBL_TOTAL_SIZE = 76
BMA456_NUM_FEATURE_SETS = 4
BMA456_REG_ACC_CONF = 64
BMA456_REG_ACC_RANGE = 65
BMA456_REG_ACC_X = 18
BMA456_REG_ACC_X_HI = 19
BMA456_REG_ACC_X_LOW = 18
BMA456_REG_ACC_Y = 20
BMA456_REG_ACC_Y_HI = 21
BMA456_REG_ACC_Y_LOW = 20
BMA456_REG_ACC_Z = 22
BMA456_REG_ACC_Z_HI = 23
BMA456_REG_ACC_Z_LOW = 22
BMA456_REG_AUX_CONF = 68
BMA456_REG_AUX_DEV_ID = 75
BMA456_REG_AUX_IF_CONF = 76
BMA456_REG_AUX_R = 16
BMA456_REG_AUX_RD_ADDR = 77
BMA456_REG_AUX_R_HI = 17
BMA456_REG_AUX_R_LOW = 16
BMA456_REG_AUX_WR_ADDR = 78
BMA456_REG_AUX_WR_DATA = 79
BMA456_REG_AUX_X = 10
BMA456_REG_AUX_X_HI = 11
BMA456_REG_AUX_X_LOW = 10
BMA456_REG_AUX_Y = 12
BMA456_REG_AUX_Y_HI = 13
BMA456_REG_AUX_Y_LOW = 12
BMA456_REG_AUX_Z = 14
BMA456_REG_AUX_Z_HI = 15
BMA456_REG_AUX_Z_LOW = 14
BMA456_REG_CHIP_ID = 0
BMA456_REG_CMD = 126
BMA456_REG_DATA0 = 10
BMA456_REG_DATA1 = 11
BMA456_REG_DATA10 = 20
BMA456_REG_DATA11 = 21
BMA456_REG_DATA12 = 22
BMA456_REG_DATA13 = 23
BMA456_REG_DATA2 = 12
BMA456_REG_DATA3 = 13
BMA456_REG_DATA4 = 14
BMA456_REG_DATA5 = 15
BMA456_REG_DATA6 = 16
BMA456_REG_DATA7 = 17
BMA456_REG_DATA8 = 18
BMA456_REG_DATA9 = 19
BMA456_REG_DMA_HI = 92
BMA456_REG_DMA_LOW = 91
BMA456_REG_ERROR = 2
BMA456_REG_EVENT = 27
BMA456_REG_FEATURES = 94
BMA456_REG_FIFO_CFG = 72
BMA456_REG_FIFO_CFG0 = 72
BMA456_REG_FIFO_CFG1 = 73
BMA456_REG_FIFO_DATA = 38
BMA456_REG_FIFO_DOWNS = 69
BMA456_REG_FIFO_LENGTH = 36
BMA456_REG_FIFO_LENGTH_HI = 37
BMA456_REG_FIFO_LENGTH_LOW = 36
BMA456_REG_FIFO_WM = 70
BMA456_REG_FIFO_WM_HI = 71
BMA456_REG_FIFO_WM_LOW = 70
BMA456_REG_IF_CFG = 107
BMA456_REG_INIT_CTRL = 89
BMA456_REG_INT1_IO_CTRL = 83
BMA456_REG_INT1_MAP = 86
BMA456_REG_INT2_IO_CTRL = 84
BMA456_REG_INT2_MAP = 87
BMA456_REG_INTERNAL_ERR = 95
BMA456_REG_INTERNAL_STATUS = 42
BMA456_REG_INT_LATCH = 85
BMA456_REG_INT_MAP_DATA = 88
BMA456_REG_INT_STATUS = 28
BMA456_REG_INT_STATUS0 = 28
BMA456_REG_INT_STATUS1 = 29
BMA456_REG_NVM_BE_CFG = 112
BMA456_REG_NVM_CFG = 106
BMA456_REG_OFFSET_X = 113
BMA456_REG_OFFSET_Y = 114
BMA456_REG_OFFSET_Z = 115
BMA456_REG_PWR_CONF = 124
BMA456_REG_PWR_CTRL = 125
BMA456_REG_SELF_TST = 109
BMA456_REG_SENSOR_TIME = 24
BMA456_REG_SENSOR_TIME0 = 24
BMA456_REG_SENSOR_TIME1 = 25
BMA456_REG_SENSOR_TIME2 = 26
BMA456_REG_STATUS = 3
BMA456_REG_TEMPERATURE = 34
BMA456_SELFTEST_DELAY_CONFIG = 2000
BMA456_SELFTEST_DELAY_MEASURE = 50000
BMA456_SELFTEST_RANGE = 8000
BMA456_SELFTEST_THRESHOLD = 1800
BMA456_TEMPERATURE_SHIFT = 23

philander.button module

Module to provide access to and control over push buttons.

class Button[source]

Bases: Module, EventEmitter

Generic push button driver class.

EVENT_PRESSED = 'buttonPressed'
LABEL_DEFAULT = 'Button'
classmethod Params_init(paramDict)[source]

Initializes configuration parameters with defaults.

The following settings are supported:

Key name

Value type, meaning and default

Button.label

str; A descriptive string label; LABEL_DEFAULT.

All Button.gpio.* settings as documented at GPIO.Params_init().

Also see: Module.Params_init(), GPIO.Params_init().

close()[source]

Close this instance and release associated hardware resources.

This is the counterpart of open(). Upon return, further usage of this instance is prohibited and may lead to unexpected results. The instance can be re-activated by calling open(), again.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

get()[source]
open(paramDict)[source]

Open the instance and set it in a usable state.

Allocate necessary hardware resources and configure user-adjustable parameters to meaningful defaults. This function must be called prior to any further usage of the instance. Involving it in the system ramp-up procedure could be a good choice. After usage of this instance is finished, the application should call close().

Parameters:

paramDict (dict(str, object)) – Configuration parameters as obtained from module.Module.Params_init(), possibly.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

setLabel(label)[source]
setRunLevel(level)[source]

Select the power-saving operation mode.

Switches the instance to one of the power-saving modes or recovers from these modes. Situation-aware deployment of these modes can greatly reduce the system’s total power consumption.

Parameters:

level (RunLevel) – The level to switch to.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

philander.charger module

Abstract base types for implementations of battery chargers.

class Charger[source]

Bases: object

Abstract base class to describe a battery charger.

getBatStatus()[source]

Get the battery status to tell about the health and state of the battery.

Returns one of the battery.Status values to indicate battery voltage level or presence or health state.

Returns:

The battery state.

Return type:

battery.Status

getBatteryTempStatus()[source]

Retrieves the battery’s temperature status.

Returns:

A rating code to indicate the temperature rating of the battery element.

Return type:

TemperatureRating

getChargerTempStatus()[source]

Retrieves the charger’s temperature state.

Returns:

A rating code to indicate the temperature rating of the charger chip.

Return type:

TemperatureRating

getChgStatus()[source]

Retrieves the charging phase or status.

Returns:

A charger status code to indicate the current charger status.

Return type:

charger.Status

getDCStatus()[source]

Retrieves the DC supply status.

Returns:

A status code to indicate the DC supply status.

Return type:

DCStatus

getError()[source]

Determines the error state for the charger chip, if one.

Returns:

A charger error code to further describe reason for the error.

Return type:

ChargerError

getInfo()[source]

Retrieves an information block from the charging device.

Typically, this kind of information is rather static in that, it does not change over time. Usually, this information is somewhat unique for the charger origin, manufacturing date, hardware/firmware revision, product/model ID, chip series and alike. For that reason, this function can be used to see, if communication works reliably.

Returns:

The information object and an error code indicating either success or the reason of failure.

Return type:

Info, ErrorCode

getNumCells()[source]

Retrieves the number of battery cells configured.

Returns the number of battery cells or a negative number if this information could not be retrieved.

Returns:

The number of cells.

Return type:

int

getPowerSrc()[source]

Retrieves the power source, that presumably drives the system at the moment that this function is executed.

Returns:

A code to indicate the power source.

Return type:

PowerSrc

isBatteryPresent()[source]

Checks, if the battery is present.

This does not tell anything about whether the battery is charged or not.

Returns ErrorCode.errOk if a battery is present, ErrorCode.errUnavailable if the battery is not present and any other value to indicate the reason, why this information could not be retrieved.

See also: getChgStatus().

Returns:

An error code.

Return type:

ErrorCode

reset()[source]

Soft resets the device.

The device is in some default state, afterwards and must be re-configured according to the application’s needs. :return: An error code indicating either success or the reason of failure. :rtype: ErrorCode

restartCharging()[source]

Tries to restart the charging phase.

This could be necessary, e.g. after recovering from a thermal shutdown.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

class ChargerError(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

A type to describe the charger’s error condition more precisely.

This is to detail the reason, why charging was stopped or is not going to start.

bat = 40
batBroken = 42
batLow = 41
batRemoved = 43
config = 10
dc = 30
dcHigh = 32
dcLow = 31
ok = 0
temp = 20
tempBat = 22
tempChg = 21
timer = 50
unknown = 100
class DCStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Wrapper to hold status information of a DC supply.

off = 1
overvoltage = 4
undervoltage = 2
unknown = 5
valid = 3
class EventContext(source: EventSource = EventSource.none)[source]

Bases: EventContext

Data class holding the context information of an event (interrupt).

Use the source attribute to de-multiplex the inner data items.

source: EventSource = 0
class EventSource(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Flag

Event source type to detail the reason for an interrupt occurrence.

It’s ok for an implementation to not support every type of interrupt.

all = 2047
batteryOvercurrent = 128
batteryTemperature = 64
chargingPhase = 4
inputCurrentLimitOwn = 16
inputCurrentLimitSrc = 32
inputVoltage = 8
internal = 1
none = 0
onOff = 2
systemOvervoltage = 512
systemUndervoltage = 256
thermalShutdown = 1024
unknown = 32768
class PowerSrc(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Flag

A power source describes a supplier of electrical energy that can be used, e.g. to drive the system.

bat = 2
dc = 1
dcBat = 3
unknown = 0
class Status(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Data class to describe the status or mode of a charging circuitry. This is mainly specified by the phase of a charging cycle.

done = 8
fastCharge = 4
fastChargeConstCurrent = 5
fastChargeConstVoltage = 6
off = 1
preCharge = 2
topOff = 7
trickle = 3
unknown = 9
class TemperatureRating(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

This type qualitatively describes a temperature, e.g. of a chip.

cold = 2
coldOrHot = 34
cool = 1
coolOrWarm = 17
hot = 32
ok = 0
unknown = 255
warm = 16

philander.configurable module

Module to provide helper classes related to configuration.

class ConfigItem(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Mnemonic type to identify a specific kind of configuration. This helps interpreting configuration data, correctly. The meaning is as follows:

Item

Meaning

rate

Data rate as a frequency in Hz.

range

Data measurement range, depending on the physical dimension.

resolution

Resolution of a measurement result in bits.

fifo

Fifo low/hogh water marks, empty signals etc.

eventArm

Arming the event machine, enabling interrupt(s).

eventCondition

Thresholds and counts to define event conditions.

implicit

Configured property is implicitly given by the enclosing type.

eventArm = 5
eventCondition = 6
fifo = 4
implicit = 7
range = 2
rate = 1
resolution = 3
class Configurable[source]

Bases: object

Generic interface for configurable objects.

Unless described otherwise by sub-classes, the exact interpretation of configuration parameters as well as the behavior of the configure() method is at the discretion of the implementation.

configure(configData)[source]

Configures the device as described by the given configuration data.

Note that the type of the provided data and its interpretation will depend on the actual implementation.

Also see: Configuration.

Parameters:

configData (.Configuration) – Specific configuration information.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

class Configuration(item: ConfigItem = ConfigItem.implicit, value: int = 1, fifo: CfgFifo = None)[source]

Bases: object

Container structure to hold common configuration data.

Instances of this class will be passed to the Configurable.configure() method. Use the item attribute to de-multiplex the inner data attributes.

class CfgFifo(watermark: int = 4, control: int = 0)[source]

Bases: object

control: int = 0
watermark: int = 4
fifo: CfgFifo = None
item: ConfigItem = 7

Multiplex configured item and data attribute interpretation as follows:

Value

Attribute valid

ConfigItem.rate

value

ConfigItem.range

value

ConfigItem.resolution

value

ConfigItem.fifo

fifo

ConfigItem.eventArm

value

ConfigItem.eventCondition

to be defined in subclass

ConfigItem.implicit

to be defined in subclass

value: int = 1

philander.dictionary module

Types and functions making up the dictionary module.

class Dictionary(myMap={}, mode=12)[source]

Bases: object

A dictionary is meant to translate keys to values, both of them being integers.

For example, a certain configuration register content could be translated into its physical data domain by means of a dictionary. The BMA456 acceleration sensor can adjust its measurement range to +/- 2g, 4g, 8g or even 16g by setting its ACC_RANGE register to either 0, 1, 2 or 3, respectively. Considering the register content to be the key domain, whereas the corresponding range limits are the values, a dictionary would translate as follows:

Key

Value

0

2000

1

4000

2

8000

3

16000

It is also possible to translate vice-versa, i.e. from the value-domain into keys by finding the nearest matching key. The behavior of this search algorithm can be controlled by the dictionary’s mode attribute.

Note that at the advantage of runtime speed, this implementation assumes the dictionary be sorted by values in ascending order.

DICT_MODE_MAP = 12

Bitmask for the mode particle to define the mapping for values that are in the range defined by the minimum and maximum values in the dictionary.

DICT_MODE_MAP_NEAREST = 12

Map by ordinary rounding: A value is mapped to the key that corresponds to the nearest value in dictionary.

DICT_MODE_MAP_NEAREST_HIGHER = 8

Map by rounding up: A value is mapped to the key that corresponds to the smallest value, that is larger than (or equal to) it.

DICT_MODE_MAP_NEAREST_LOWER = 4

Map by rounding down: A value is mapped to the key that corresponds to the largest value, that is smaller than (or equal to) it.

DICT_MODE_MAP_STRICTLY = 0

Strict mapping: Only those values, that are contained in the dictionary will be mapped to their corresponding keys. Other values will produce errors.

DICT_MODE_OVERRUN = 2

Bitmask for the mode particle to define the mapping for values above the highest value in the dictionary, a so-called overrun.

DICT_MODE_OVERRUN_ERROR = 2

Values larger than the highest value in dictionary will not be mapped, but cause an error when trying to find a matching key.

DICT_MODE_OVERRUN_MAP = 0

Values above the highest value will be mapped to the key corresponding to that highest value.

DICT_MODE_UNDERRUN = 1

Bitmask for the mode particle to define the mapping for values below the lowest value (!) in the dictionary, a so-called underrun.

DICT_MODE_UNDERRUN_ERROR = 1

Values below the lowest value in the dictionary are not mapped, but cause an error when trying to find a matching key.

DICT_MODE_UNDERRUN_MAP = 0

Make values below the lowest value be mapped to the key corresponding to that lowest value.

DICT_STDMODE_CLIP = 15

Shortcut, just for convenience. Clip mode maps to the nearest possible key, but generates errors for underruns and overruns.

DICT_STDMODE_DOWN = 4

Shortcut, just for convenience. Downward mode rounds down to the nearest key and maps underruns and overruns without errors.

DICT_STDMODE_NORMAL = 12

Shortcut, just for convenience. Normal mode maps to the nearest possible key, as well as underruns and overruns without errors.

DICT_STDMODE_STRICT = 3

Shortcut, just for convenience. Strict mode just maps to the matching key and generates errors for all values that are not in the dictionary.

DICT_STDMODE_UP = 8

Shortcut, just for convenience. Upward mode rounds up to the nearest key and maps underruns and overruns without errors.

findKey(value)[source]

Given a value, finds the (nearest) key according to the dictionary’s mode.

The value-to-key mapping behavior can be controlled by the dictionary mode as defined during object construction.

Parameters:

value (int) – The value for which to find the corresponding key.

Returns:

The key and an error code indicating either success or the reason of failure.

Return type:

int, ErrorCode

getValue(inKey)[source]

Given a key, retrieves the corresponding value.

The first key in the dictionary exactly matching the given argument, delivers the value returned by this function. If no matching key is found, an error is returned.

Parameters:

inKey (int) – Key value for which to find the corresponding value.

Returns:

The key’s value and an error code indicating either success or the reason of failure.

Return type:

int, ErrorCode

philander.gasgauge module

A module to provide base classes and data types for gas gauge driver implementations.

class EventContext(source: EventSource = EventSource.none, soc: Percentage = 255, voltage: Voltage = 65535, batStatus: Status = Status.unknown)[source]

Bases: object

Event context type to detail the context information for an interrupt occurrence.

batStatus: Status = 65535
soc: Percentage = 255
source: EventSource = (1,)
voltage: Voltage = 65535
class EventSource(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

  • Event source type to detail the reason for an interrupt occurrence.

Not all implementations will support all types of interrupt.

batFail = (5,)

General battery failure, e.g. battery swapped

hardReset = (7,)

Power-on reset detected

highSOC = (3,)

SOC reached a high/full info level

lowSOC = (2,)

SOC dropped below a threshold

lowVolt = (4,)

Battery voltage dropped below a threshold

none = (1,)

No event reason

undervoltage = (6,)

Brown-out/Lockout due to low voltage

unknown = (8,)

Unknown event reason

class GasGauge[source]

Bases: object

This is a driver base class for a gas gauge IC.

A gas gauge allows to keep track of the state of charge (SOC), remaining capacity, current voltage etc. of a battery.

getBatteryCurrent()[source]

Retrieves the battery current in micro Ampere at the time this function is executed.

See also: getBatteryCurrentAvg()

Returns:

A on-negative integer value [µA] or Current.invalid to indicate that this information could not be retrieved.

Return type:

Current

getBatteryCurrentAvg()[source]

Retrieves the average battery current.

The average is taken over some time interval, e.g. 2 seconds. The length of the time window is at the discretion of the implementation and cannot be adjusted by the caller.

See also: getBatteryCurrent()

Returns:

A on-negative integer value [�A] or Current.invalid to indicate that this information could not be retrieved.

Return type:

Current

getBatteryVoltage()[source]

Retrieves the battery voltage in milli Volt.

Returns:

A on-negative integer value [mV] or Voltage.invalid to indicate that this information could not be retrieved.

Return type:

Voltage

getChangeRate()[source]

Retrieves the SOC change rate in milli C.

Remember that 1C = 100% in 1 hour. This information may be used to estimate the remaining stamina or how long the charging process will still take. :return: A SOC change rate (non-negative) or :attr:’SOCChangeRate.invalid` to indicate that this information could not be retrieved. :rtype: SOCChangeRate

getInfo()[source]

Retrieves an information block from the gas gauge device.

Typically, this kind of information is rather static in that, it does not change over time. Usually, this information is somewhat unique for the charger origin, manufacturing date, hardware/firmware revision, product/model ID, chip series and alike. For that reason, this function can be used to see, if communication works reliably.

For more dynamic meta-information see getStatus().

The method returns both, an instance of Info, carrying the information block as well as an error code, indicating success or failure. The info block shall be evaluated only, if the method returned successfully. Even then, the caller should still evaluate the validity attribute of the returned info block to find out, which of the information is actually valid.

Returns:

The information object and an error code indicating either success or the reason of failure.

Return type:

Info, ErrorCode

getRatedSOC()[source]

Retrieve the current state of charge as a discrete battery level predicate.

Returns:

The next-lower battery level corresponding to the current SOC.

Return type:

battery.Level

getRatedSOCStr()[source]

Retrieve the remaining capacity as a battery level string.

Returns:

The next-lower battery level corresponding to the current SOC.

Return type:

String

getStateOfCharge()[source]

Retrieves the state of charge.

That is the fraction of electric energy from the total capacity, that is still or already stored in the battery. This information is valid for both, the charging as well as the discharging process.

Returns:

A percentage [0…100] value or Percentage.invalid to indicate that this information could not be retrieved.

Return type:

Percentage

getStatus(statusID)[source]

Retrieves status data from the device.

Typically, this kind of information is more dynamic in that, it changes (much) over time. Usually, it further describes the IC’s current shape and condition, such as the availability of new data, the cause of an interrupt or the status of certain hardware functions. Also, secondary measurements such as the die temperature could be subject to status data.

For more static meta-information see getInfo().

The given statusID parameter specifies, exactly which status information should be retrieved. Its type and interpretation depends on the implementation.

The method returns both, resulting status data and an error code indicating success or failure. The status data should be considered valid only, if the error code indicates a successful execution of this method.

The type and interpretation of the status data depends on the specific implementation.

Parameters:

statusID (int) – Identifies the status information to be retrieved.

Returns:

The status object and an error code indicating either success or the reason of failure.

Return type:

Object, ErrorCode

reset()[source]

Soft resets the device.

The device is in some default state, afterwards and must be re-configured according to the application’s needs. :return: An error code indicating either success or the reason of failure. :rtype: ErrorCode

class SOCChangeRate[source]

Bases: int

State of charge (SOC) change rate, given in milli-C rate [mC].

Remember 1C = 100% per 1 hour.

invalid = 65535
class StatusID(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Data class to comprise different types of status information.

batTemp = 1
dieTemp = 2

philander.gpio module

General-purpose I/O abstraction module.

Provide a convergence layer API to abstract from several different GPIO implementing driver modules possibly installed on the target system.

class GPIO[source]

Bases: Module, Interruptable

General-purpose I/O abstraction class.

Provide access to and control over the underlying GPIO hardware. For that, an implementing driver module is used. As a convergence layer, this class is to hide specifics and level syntactic requirements of the implementing package.

BOUNCE_DEFAULT = 200
BOUNCE_NONE = 0
DIRECTION_IN = 1
DIRECTION_OUT = 2
EVENT_DEFAULT = 'gpioFired'
LEVEL_HIGH = 1
LEVEL_LOW = 0
PINNUMBERING_BCM = 'BCM'
PINNUMBERING_BOARD = 'BOARD'
PULL_DEFAULT = 0
PULL_DOWN = 3
PULL_NONE = 1
PULL_UP = 2
classmethod Params_init(paramDict)[source]

Initialize parameters with their defaults.

The given dictionary should not be None, on entry. Options not present in the dictionary will be added and set to their defaults on return. The following options are supported.

Key

Range

Default

gpio.pinNumbering

GPIO.PINNUMBERING_[BCM | BOARD]

GPIO.PINNUMBERING_BCM

gpio.pinDesignator

pin name or number (e.g. 17 or “GPIO17”)

None

gpio.direction

GPIO.DIRECTION_[IN | OUT]

GPIO.DIRECTION_OUT

gpio.inverted

[True | False]

False

gpio.level

GPIO.LEVEL_[LOW | HIGH]

GPIO.LEVEL_LOW

gpio.pull

GPIO.PULL_[DEFAULT | NONE | UP | DOWN]

GPIO.PULL_DEFAULT (NONE)

gpio.trigger

GPIO.TRIGGER_EDGE_[RISING | FALLING | ANY]

GPIO.TRIGGER_EDGE_RISING

gpio.bounce

integer number, delay in milliseconds [ms]

GPIO.BOUNCE_DEFAULT

gpio.feedback

Arbitrary. Passed on to the interrupt handler.

None

gpio.handler

Handling routine reference.

None

Parameters:

paramDict (dict(str, object)) – Configuration parameters as obtained from Params_init(), possibly.

Returns:

none

Return type:

None

TRIGGER_EDGE_ANY = 3
TRIGGER_EDGE_FALLING = 2
TRIGGER_EDGE_RISING = 1
TRIGGER_LEVEL_HIGH = 4
TRIGGER_LEVEL_LOW = 5
close()[source]

Closes this instance and releases associated hardware resources.

This is the counterpart of open(). Upon return, further usage of this instance is prohibited and may lead to unexpected results. The instance can be re-activated by calling open(), again.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

disableInterrupt()[source]

Disables the gpio interrupt for that pin.

Immediately disables the interrupt for that pin. It will not _fire an event anymore, unless enableInterrupt() is called anew.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

enableInterrupt()[source]

Enables the gpio interrupt for that pin.

If the pin is configured for input, enables the interrupt for that pin. Depending on the trigger configured during open(), an event will be fired the next time when the condition is satisfied.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

get()[source]

Retrieve the pin level.

Gives the pin level, independent of whether the pin direction is set to input or output.

Returns:

GPIO.LEVEL_HIGH, if the pin is at high level. Otherwise, GPIO.LEVEL_LOW.

Return type:

int

static getGPIO(provider=SysProvider.AUTO)[source]

Generates a GPIO implementation according to the requested provider.

Parameters:

provider (SysProvider) – The low-level lib to rely on, or AUTO for automatic detection.

Returns:

A GPIO implementation object, or None in case of an error.

Return type:

GPIO

open(paramDict)[source]

Opens the instance and sets it in a usable state.

Allocate necessary hardware resources and configure user-adjustable parameters to meaningful defaults. This function must be called prior to any further usage of the instance. Involving it in the system ramp-up procedure could be a good choice. After usage of this instance is finished, the application should call close().

Parameters:

paramDict (dict(str, object)) – Configuration parameters as obtained from Params_init(), possibly.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

set(newLevel)[source]

Sets the pin to the given level.

Outputs the given level at this pin. Does not work, if this pin is set to input direction.

Parameters:

newLevel (int) – The new level to set this pin to. Must be one of GPIO.LEVEL_[HIGH | LOW].

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

setRunLevel(level)[source]

Select the power-saving operation mode.

Switches the instance to one of the power-saving modes or recovers from these modes. Situation-aware deployment of these modes can greatly reduce the system’s total power consumption.

Parameters:

level (RunLevel) – The level to switch to.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

philander.htu21d module

Driver implementation for the HTU21D relative humidity and temperature sensor.

More information on the functionality of the chip can be found at the TE site: https://www.te.com/deu-de/product-CAT-HSC0004.html

class Data(humidity: Percentage = 0, temperature: PreciseTemperature = 0)[source]

Bases: Data, Data

Container type to wrap this sensor’s measurement result.

This data type carries both, temperature and humidity measurement results. Also see: thermometer.Data, hygrometer.Data

class HTU21D[source]

Bases: Sensor, SerialBusDevice

HTU21D driver implementation.

ADDRESS = 64
CFG_RESOLUTION_DEFAULT = 14
CFG_RESOLUTION_HUM10_TEMP13 = 13
CFG_RESOLUTION_HUM11_TEMP11 = 11
CFG_RESOLUTION_HUM12_TEMP14 = 14
CFG_RESOLUTION_HUM8_TEMP12 = 12
CMD_GET_HUM = 245
CMD_GET_HUM_HOLD = 229
CMD_GET_TEMP = 243
CMD_GET_TEMP_HOLD = 227
CMD_READ_USR_REG = 231
CMD_SOFT_RESET = 254
CMD_WRITE_USR_REG = 230
CNT_USR_CHIP_HEATER = 4
CNT_USR_CHIP_HEATER_OFF = 0
CNT_USR_CHIP_HEATER_ON = 4
CNT_USR_DEFAULT = 2
CNT_USR_OTP_RELOAD = 2
CNT_USR_OTP_RELOAD_DISABLE = 2
CNT_USR_OTP_RELOAD_ENABLE = 0
CNT_USR_POWER = 64
CNT_USR_POWER_GOOD = 0
CNT_USR_POWER_LOW = 64
CNT_USR_RESERVED = 56
CNT_USR_RESOLUTION = 129
CNT_USR_RESOLUTION_DEFAULT = 0
CNT_USR_RESOLUTION_RH10_T13 = 128
CNT_USR_RESOLUTION_RH11_T11 = 129
CNT_USR_RESOLUTION_RH12_T14 = 0
CNT_USR_RESOLUTION_RH8_T12 = 1
DIAG_CIRC_OPEN = 0
DIAG_CIRC_SHORT = 3
DIAG_HUM_OK = 2
DIAG_TEMP_OK = 1
MEAS_TIME_MAX_MS_RH10 = 5
MEAS_TIME_MAX_MS_RH11 = 8
MEAS_TIME_MAX_MS_RH12 = 16
MEAS_TIME_MAX_MS_RH8 = 3
MEAS_TIME_MAX_MS_T11 = 7
MEAS_TIME_MAX_MS_T12 = 13
MEAS_TIME_MAX_MS_T13 = 25
MEAS_TIME_MAX_MS_T14 = 50
classmethod Params_init(paramDict)[source]

Initializes configuration parameters with defaults.

The following settings are supported:

Key name

Value type, meaning and default

SerialBusDevice.address

int I2C serial device address, must be ADDRESS; default is ADDRESS.

Sensor.dataRate

int Data rate in Hz; default is set by Sensor.Params_init().

HTU21D.resolution

int Resolution in bits; default is CFG_RESOLUTION_HUM12_TEMP14.

Also see: Sensor.Params_init(), SerialBusDevice.Params_init().

RESET_TIME_MAX_MS = 15
SELFTEST_TIME_WAIT_S = 5
close()[source]

Close this instance and release associated hardware resources.

This is the counterpart of open(). Upon return, further usage of this instance is prohibited and may lead to unexpected results. The instance can be re-activated by calling open(), again.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

configure(configData)[source]

Configures the sensor device as described by the given configuration data.

Note that the type of the provided data and its interpretation will depend on the sensor implementation. Also see: Configuration.

Parameters:

configData (.sensor.Configuration) – Specific configuration information.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

getLatestData()[source]

Retrieves the most recent data.

If the data is older than the measurement interval indicated by the configured data rate, a new measurement sample is retrieved from the sensor.

Also see: Sensor.getLatestData().

Returns:

The measurement data object and an error code indicating either success or the reason of failure.

Return type:

Object, ErrorCode

getNextData()[source]

Wait for the next sample and retrieve that measurement.

If a full measurement interval, as defined by the configured data rate, has not yet elapsed, wait until that point. Then, retrieve a fresh measurement sample.

Also see: Sensor.getNextData().

Returns:

The measurement data object and an error code indicating either success or the reason of failure.

Return type:

Object, ErrorCode

getStatus(statusID)[source]

Retrieve dynamic status info from the sensor.

The resulting status data object depends on the requested info as follows:

htu21d.StatusID.powerOk: Reads the power indicator bit (#6, End-of-Battery) and returns a boolean True, if the VDD power is above the minimum required, or False otherwise.

Also see: Sensor.getStatus().

Parameters:

statusID (int) – Identifies the status information to be retrieved.

Returns:

The status object and an error code indicating either success or the reason of failure.

Return type:

Object, ErrorCode

open(paramDict)[source]

Opens an instance and puts it into a usable state.

Configures the sensor by reading the supported parameters or applying default values and calling configure(). Also see: module.Module.open().

Parameters:

paramDict (dict(str, object)) – Configuration parameters as obtained from module.Module.Params_init(), possibly.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

reset()[source]

Reboots the sensor.

Power-cycles the chip and restarts it with the default configuration. So, any user configuration applied before, will be lost.

Also see: Sensor.reset().

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

selfTest(tests)[source]

Execute one or more sensor self tests.

SelfTest.FUNCTIONAL: The on-chip heater is used to check if the sensor shows the expected temperature raise and humidity drop. The heater consumes ~5.5mW and the test takes about 5 seconds.

Also see: Sensor.selfTest().

Parameters:

tests (int) – A bit mask to select the tests to be executed.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

class StatusID(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Data class to comprise different types of status information.

powerOk = 1

philander.hygrometer module

Abstract interface for humidity sensors accessible via serial communication.

Provide an API to abstract from relative humidity measurement devices.

class Data(humidity: Percentage = 0)[source]

Bases: object

Container type to wrap a hygrometer’s primary measurement result.

Measurement data should always be expressed as percentage.

humidity: Percentage = 0

philander.imath module

Integer mathematics helper functions.

Provide mathematical functions implementing bit-twiddling hacks, such as ispowtwo, iprevpowtwo and vlbs or ffs.

ctz(x: int)[source]

Count trailing zeroes.

Count the number of zero-bits following the least-significant set bit. Note that ffs(x) = ctz(x) + 1. To maintain this relation when the argument is zero, this function returns -1 in this case.

Example: For x=24 the result is 3. For x=25 the result is 0.

Parameters:

x (int) – The input argument, interpreted as an unsigned integer.

Returns:

The number of trailing zeroes after the least-significant set bit.

Return type:

int

ffs(x: int)[source]

Find first set.

Finds the first, i.e. least-significant bit set and returns its index number, where counting starts from 1. For an input of zero, the result is zero, by definition. Note that ffs(x) = ctz(x) + 1.

Example: For x=24 the result is 4. For x=25 the result is 1.

Parameters:

x (int) – The input argument, interpreted as an unsigned integer.

Returns:

The one-based position index of the least-significant set bit.

Return type:

int

iprevpowtwo(n: int)[source]

Gives the previous power of two for the given argument.

Returns the greatest power of two, that is less than or equal to the provided argument. For zero, the function returns zero.

Example: For n=32 the result is 32. For n=47 the result is 32, too.

Parameters:

n (int) – The argument, interpreted as an unsigned integer.

Returns:

The previous power of two for that argument, or zero if n=0.

Return type:

int

ispowtwo(x: int)[source]

Checks if the argument is a power of two, i.e. has exactly one bit set.

Note that one (1) is considered a power of two, while zero (0) is not.

Example: For x=32 the result is True. For x=47 the result is False.

Parameters:

x (int) – The argument to check, interpreted as an unsigned integer.

Returns:

True, if the argument is a power of two, False otherwise.

Return type:

Boolean

vlbs(x: int)[source]

For a given integer, find the value of the least bit set.

If no bit of the argument is set, i.e. for zero (0), the result is zero (0). Otherwise, the result is a bit value and not a bit number! That’s why, the return value is always a power of two - or zero.

Example: For x=32 the result is 32. For x=47 the result is 1.

Parameters:

x (int) – The input argument, interpreted as an unsigned integer.

Returns:

The value of the least bit set, or zero.

Return type:

int

philander.interruptable module

Module to provide interrupt-related interfaces and helper classes.

This is to support event-based programming techniques, also referred to as publish-subscribe, asynchronous, event-driven behavior and so on. The central interface is Interruptable, which is meant to be sub-classed by implementing devices. It can be registered with interrupt handling routines and used to enable or disable interrupts on that device.

Upon an interrupt occurrence, the registered handler is called with an interruptable.Event argument. It is intended to carry all information available at no extra price in the moment of interrupt occurrence. For that reason, it is likely to represent no more information than just the fact, that an interrupt occurred. If a device supports multiple INT lines, it can identify which one exactly caused the interrupt.

All further information beyond that immediate response, especially if requiring extra communication with the device, is considered to be event context information and is represented by an EventContext object. This kind of data must be explicitly polled by the subscriber. Whenever possible, that context polling should be done outside of the handling routine as part of the response action.

EventContextControl objects are used to control the order/priority of context items while retrieving them from the device.

class Event[source]

Bases: object

Generic class to indicate the nature of an interrupt (source).

Instances of this class are meant to be passed to the handling routine as an immediate response to interrupts.

evtAny = 'EventAny'
evtInt1 = 'EventInt1'
evtInt2 = 'EventInt2'
evtNone = 'EventNone'
class EventContext(control: EventContextControl = 1, remainInt: int = 0)[source]

Bases: object

Details or quantifies the reason for an interrupt occurrence.

Will probably be sub-classed to represent specifics of the implementing Interruptable device.

class EventContextControl[source]

Bases: object

Control data to navigate through the list of event context items.

clearAll = 0
getFirst = 1
getLast = 3
getNext = 2
getPrevious = 4
class Interruptable[source]

Bases: object

Generic interface to describe the capabilities of an event or interrupt source.

This is an abstract base class to define common methods for enabling and disabling events as well as for managing event information of a specific device (implementation).

disableInterrupt()[source]

Disables the interrupt(s) of the implementing device.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

enableInterrupt()[source]

Enables the interrupt(s) of the implementing device.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

getEventContext(event, context)[source]

After an event occurred, retrieves more detailed information on the reason(s) for that interrupt.

If a device supports more interrupt conditions than physical interrupt signalling lines, this is the way to find out, which of the condition(s) were met causing the last interrupt to _fire. For example, a temperature sensor could _fire its (one and only) interrupt line, if: * a high-temperature threshold is exceeded * a low-temperature threshold is undercut * the temperature didn’t change (much) for some time interval * a new temperature measurement is available And some of these conditions could hold true simultaneously. Then, this function is to reveal more information on each single condition. E.g. the /new measurement available/ condition will deliver that new measurement data.

That’s why, it may be meaningful/necessary to call this method repeatedly, until all reasons were reported. Upon its first call after an event, the context’s interruptable.EventContext.control attribute must be set to interruptable.EventContextControl.getFirst. Upon subsequent calls, this attribute should not be changed by the caller, anymore. In generally, event context information is retrieved in the order according to the priority of the corresponding event sources.

The return value indicates, whether or not more information is available as follows:

Return value

Meaning

ErrorCode.errOk

Success. Last context info. No more data to retrieve.

ErrorCode.errMoreData

Success. Context is valid. More data to be retrieved.

ErrorCode.errFewData

No data to retrieve. Context is invalid.

any other ErrorCode.*

Error. Context data is invalid.

Parameters:
  • event (int) – The original event occurred, as recieved by the handling routine. This must be one of the event mnemonics defined by :class:.interruptable.Event.

  • context (EventContext) – A representation of the context information. The appropriate sub-class must be provided by the device implementation. Upon the first call for each interrupt, the control attribute must be set to either one of evtCtxtCtrl_[clearAll | getFirst | getLast]. In subsequent calls, this attribute is updated automatically. Upon return, this parameter contains the desired context information.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

registerInterruptHandler(onEvent=None, callerFeedBack=None, handler=None)[source]

Registers a handling routine for interrupt notification.

The caller feedback will be directly passed to the handling routine. In case that multiple different interrupts are handled by the same routine, this parameter may be used to distinguish them and remember the source of interrupt.

The handler should be a method or function that expects at least one argument. That first argument will be the callerFeedBack object given as the above-mentioned parameter. Further parameters may follow, as they were handed in to the _fire() method. The handler’s signature should look like this:

def handlingRoutine( feedback, *args) -> None:

Note that the onEvent parameter is not passed to the handler. It is eaten up by _fire() and just controls the selection of the handling routine called.

Depending on the parameter, this method behaves as follows:

onEvent

handler

semantics and action

Event.evtNone

None

All interrupts are disabled and all registrations cleared.

Event.evtNone

valid

De-register the given handler from all events {Event.evtInt1|2|Any}.

Event.evtInt1|2|*

None

De-register all handlers from the given event.

Event.evtInt1|2|*

valid

Enable interrupt and register this handler for the given event.

Event.evtAny

None

Clear the Event.evtAny registrations, only!

Event.evtAny

valid

Register the handler for any event {Event.evtInt1|2}.

For this method, Event.evtNone is a semantic equivalent to None.

Parameters:
  • onEvent (int) – Exactly one of the event mnemonics defined by the interruptable.Event enumeration.

  • callerFeedBack (object) – Arbitrary object not evaluated here, but passed on to the handler when an event is fired.

  • handler – The handling routine to be called as an immediate response to an event.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

philander.l6924 module

Driver implementation for the L6924D/U battery chargers.

More information on the functionality of the chip can be found at the ST website under e.g. https://www.st.com/en/power-management/l6942d.html

class L6924[source]

Bases: Charger

L6924 driver implementation.

This implementation was tested using STEVAL-ISA076V1 board (based on L6924D) but also should work for other devices. This implementation does only read information on two gpio pins, and thus cannot communicate with the charger in any way.

classmethod Params_init(paramDict)[source]

Initializes configuration parameters with defaults.

The following settings are supported:

Key name

Value type, meaning and default

All L6924.[St1 | St2].gpio.* settings as documented at GPIO.Params_init().

Also see: Charger.Params_init(), SerialBusDevice.Params_init(), GPIO.Params_init().

close()[source]

Shut down the device after usage.

This method should be called when the device is not used, anymore, e.g. as part of the application exit procedure. The following steps are executed:

  • close GPIO pins for st1 and st1

After return, the device can still be re-used, by calling open() again.

Also see: GPIO.close(), Module.close().

getBatStatus()[source]

Get the battery status to tell about the health and state of the battery.

Returns one of the battery.Status values to indicate battery voltage level or presence or health state. Because of the very limited output, this will only return the states Status.normal (charging, etc.) and Status.problemPhysical (Battery absent, too hot, etc.)

Returns:

The battery state.

Return type:

battery.Status

getBatteryTempStatus()[source]

Retrieves the battery’s temperature status.

This device does not report on the battery’s temperature. The given status is guessed based on the ChgStatus. If the charger status is ok, the battery temperature is assumed to be ok too. If the charger status is indicating any problem, the temperature rating is assumed to be unknown.

Returns:

A rating code to indicate the temperature rating of the battery element.

Return type:

TemperatureRating

getChargerTempStatus()[source]

Retrieves the charger’s temperature state.

This device does not report it’s temperature.

Returns:

A rating code to indicate the temperature rating of the charger chip.

Return type:

TemperatureRating

getChgStatus()[source]

Retrieves the charging phase or status.

Returns:

A charger status code to indicate the current charger status.

Return type:

charger.Status

getDCStatus()[source]

Retrieves the DC supply status.

This device does not indicate it’s status. The given status is guessed based on the ChgStatus.

Returns:

A status code to indicate the DC supply status.

Return type:

DCStatus

getError()[source]

Determines the error state for the charger chip, if one.

Because this device only has one error status, ChargerError.bat indicates any kind of error e.g. thermal problems, battery absent or charge timer expired.

Returns:

A charger error code to further describe reason for the error.

Return type:

ChargerError

getInfo()[source]

Retrieves an information block from the charging device.

This device does not report any static information.

Returns:

The information object and an error code indicating either success or the reason of failure.

Return type:

Info, ErrorCode

getNumCells()[source]

Retrieves the number of battery cells configured.

This board only supports one cell.

Returns:

The number of cells.

Return type:

int

getPowerSrc()[source]

Retrieves the power source, that presumably drives the system at the moment that this function is executed.

This device does not report it’s power source. The given status is guessed based on the ChgStatus.

Returns:

A code to indicate the power source.

Return type:

PowerSrc

isBatteryPresent()[source]

Checks, if the battery is present.

Because there is only one error code without any differentiation, if Error.errUnavailable is returned, it could be the case, that there is no battery present. Specifically the following is true: If there is no battery present, this function will return Error.errUnavailable. If the function returns Error.errUnavailable, the reason could also be a high/low temperature, a faulty battery or that the time limit has elapsed. If the chip is not powered, it will always return ErrorCode.errOk, guessing that there is a battery present.

Returns ErrorCode.errOk if a battery is present, ErrorCode.errUnavailable if the battery could possibly not be present. This can not be exactly determined, because there is only one error state, which could indicate that the battery is not present, but which also could indicate another problem.

See also: getChgStatus().

Returns:

An error code.

Return type:

ErrorCode

open(paramDict)[source]

Opens the instance and sets it in a usable state.

Allocate necessary hardware resources and configure user-adjustable parameters to meaningful defaults. In this case the two GPIO-Pins for reading the charger status are initialized. This function must be called prior to any further usage of the instance. Involving it in the system ramp-up procedure could be a good choice. After usage of this instance is finished, the application should call close().

Parameters:

paramDict (paramDict(str, object)) – Configuration parameters as obtained from Params_init(), possibly.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

reset()[source]

Soft resets the device.

As there is nothing to reset, this routine does not execute an actual reset. It is just here to fulfill the interface.

The device is in some default state, afterwards and must be re-configured according to the application’s needs. :return: An error code indicating either success or the reason of failure. :rtype: ErrorCode

restartCharging()[source]

Tries to restart the charging phase.

This device does not support manual control of the charging process.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

philander.led module

Module to provide access to and control over LEDs.

class LED[source]

Bases: Module

Generic LED driver class.

CURVE_HARTBEAT = [1, 0, 1, 0.7, 0.4, 0.2, 0, 0, 0, 0]
CYCLEN_FAST = 0.4
CYCLEN_NORMAL = 1
CYCLEN_SLOW = 2
LABEL_DEFAULT = 'LED'
classmethod Params_init(paramDict)[source]

Initializes configuration parameters with defaults.

The following settings are supported:

Key name

Value type, meaning and default

LED.label

str; A descriptive string label; LABEL_DEFAULT.

All LED.gpio.* settings as documented at GPIO.Params_init().

Also see: Module.Params_init(), GPIO.Params_init().

close()[source]

Close this instance and release associated hardware resources.

This is the counterpart of open(). Upon return, further usage of this instance is prohibited and may lead to unexpected results. The instance can be re-activated by calling open(), again.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

off()[source]
on()[source]
open(paramDict)[source]

Open the instance and set it in a usable state.

Allocate necessary hardware resources and configure user-adjustable parameters to meaningful defaults. This function must be called prior to any further usage of the instance. Involving it in the system ramp-up procedure could be a good choice. After usage of this instance is finished, the application should call close().

Parameters:

paramDict (dict(str, object)) – Configuration parameters as obtained from module.Module.Params_init(), possibly.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

set(brightness)[source]
stop_blinking()[source]

philander.max77960 module

Support module for the MAX77960 USB battery charger.

class MAX77960[source]

Bases: MAX77960_Reg, SerialBusDevice, Charger, Configurable, Interruptable, Watchdog

Driver implementation for the MAX77960 USB battery charger.

More information on the functionality of the chip can be found at the Analog site: https://www.analog.com/en/products/max77960.html

ADDRESSES_ALLOWED = [105]
CFG_B2SOVRC = 'Charger.Current.Batt2Sys'
CFG_CHGCC = 'Charger.Current.FastCharge'
CFG_CHGIN_ILIM = 'Charger.Current.Input'
CFG_CHG_CV_PRM = 'Charger.Voltage.ChargeTermination'
CFG_CHG_RSTRT = 'Charger.Restart'
CFG_COMM_MODE = 'Charger.Comm.Mode'
CFG_DISIBS = 'Charger.DisIBS'
CFG_FCHGTIME = 'Charger.Timer.FastCharge'
CFG_ICHGCC_COOL = 'Charger.Current.Jeita.FastCharge'
CFG_ITRICKLE = 'Charger.Current.Trickle'
CFG_JEITA_EN = 'Charger.Jeita'
CFG_MINVSYS = 'Charger.Voltage.MinVSys'
CFG_MODE = 'Charger.Mode'
CFG_OTG_ILIM = 'Charger.Current.OTG'
CFG_PQEN = 'Charger.Prequal'
CFG_REGTEMP = 'Charger.Temp.Reg'
CFG_STAT_EN = 'Charger.Stat'
CFG_TO_ITH = 'Charger.Current.Topoff'
CFG_TO_TIME = 'Charger.Timer.Topoff'
CFG_VCHGCV_COOL = 'Charger.Voltage.Jeita.Term'
CFG_VCHGIN_REG = 'Charger.Voltage.ChargeIn'
classmethod Params_init(paramDict)[source]

Initializes configuration parameters with defaults.

The following settings are supported:

Key name

Value type, meaning and default

SerialBusDevice.address

int I2C serial device address; default is ADDRESSES_ALLOWED [0].

Charger.Comm.Mode

int Communication mode; default is MAX77960_Reg.COMM_MODE_DEFAULT.

Charger.DisIBS

int ; default is MAX77960_Reg.DISIBS_DEFAULT.

Charger.Mode

int ; default is MAX77960_Reg.MODE_DEFAULT.

Charger.Prequal

int ; default is MAX77960_Reg.PQEN_DEFAULT.

Charger.Restart

int ; default is MAX77960_Reg.CHG_RSTRT_DEFAULT.

Charger.Stat

int ; default is MAX77960_Reg.STAT_EN_DEFAULT.

Charger.Timer.FastCharge

int ; default is MAX77960_Reg.FCHGTIME_DEFAULT.

Charger.Current.FastCharge

int ; default is MAX77960_Reg.CHGCC_DEFAULT.

Charger.Timer.Topoff

int ; default is MAX77960_Reg.TO_TIME_DEFAULT.

Charger.Current.Topoff

int ; default is MAX77960_Reg.TO_ITH_DEFAULT.

Charger.Voltage.ChargeTermination

int ; default is MAX77960_Reg.CHG_CV_PRM_DEFAULT.

Charger.Current.Trickle

int ; default is MAX77960_Reg.ITRICKLE_DEFAULT.

Charger.Current.Batt2Sys

int ; default is MAX77960_Reg.B2SOVRC_DEFAULT.

Charger.Jeita

int ; default is MAX77960_Reg.JEITA_EN_DEFAULT.

Charger.Temp.Reg

int ; default is MAX77960_Reg.REGTEMP_DEFAULT.

Charger.Voltage.Jeita.Term

int ; default is MAX77960_Reg.VCHGCV_COOL_DEFAULT.

Charger.Current.Jeita.FastCharge

int ; default is MAX77960_Reg.ICHGCC_COOL_DEFAULT.

Charger.Current.Input

int ; default is MAX77960_Reg.CHGIN_ILIM_DEFAULT.

Charger.Current.OTG

int ; default is MAX77960_Reg.OTG_ILIM_DEFAULT.

Charger.Voltage.MinVSys

int ; default is MAX77960_Reg.MINVSYS_DEFAULT.

Charger.Voltage.ChargeIn

int ; default is MAX77960_Reg.VCHGIN_REG_DEFAULT.

All Charger.int.gpio.* settings as documented at GPIO.Params_init().

Also see: Charger.Params_init(), SerialBusDevice.Params_init(), GPIO.Params_init().

REVISION_MAJOR_5 = 5
REVISION_MAJOR_6 = 6
REVISION_MAJOR_MAX = 6
REVISION_MAJOR_MAX7796x = 5
REVISION_MAJOR_MAX7796xB = 6
REVISION_MAJOR_MIN = 5
REVISION_MINOR_MAX = 31
REVISION_MINOR_MIN = 0
WATCHDOG_INTERVAL_MS = 80000
checkID()[source]

Reads the chip ID and verifies it against the expected value.

clearWatchdog()[source]

Clear the watch dog.

This is the implementation of the acknowledge mechanism. Calling this function is necessary for an application to prevent the watch dog from elapsing. Note that this method does not start the watch dog, when it is disabled.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

clearWatchdogElapsed()[source]

Clear the elapsed flag.

The application should call this function after it observed that the watch dog interval time expired.

Also see: isWatchdogElapsed().

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

close()[source]

Shut down this instance and release associated hardware resources.

If this instance is attached to some bus, it gets detached, before the method returns.

Also see: module.Module.close().

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

configure(configData)[source]

Configures the device as described by the given configuration data.

Note that the type of the provided data and its interpretation will depend on the actual implementation.

Also see: Configuration.

Parameters:

configData (.Configuration) – Specific configuration information.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

disableInterrupt()[source]

Disables the interrupt(s) of the implementing device.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

disableWatchdog()[source]

Disable the watch dog and stop it from running, immediately.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

enableInterrupt()[source]

Enables the interrupt(s) of the implementing device.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

enableWatchdog()[source]

Enable and restart the watch dog.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

getAllRegistersStr()[source]
getBatStatus()[source]

Get the battery status to tell about the health and state of the battery.

Returns one of the battery.Status values to indicate battery voltage level or presence or health state.

Returns:

The battery state.

Return type:

battery.Status

getBatteryTempStatus()[source]

Retrieves the battery’s temperature status.

Returns:

A rating code to indicate the temperature rating of the battery element.

Return type:

TemperatureRating

getChargerTempStatus()[source]

Retrieves the charger’s temperature state.

Returns:

A rating code to indicate the temperature rating of the charger chip.

Return type:

TemperatureRating

getChgStatus()[source]

Retrieves the charging phase or status.

Returns:

A charger status code to indicate the current charger status.

Return type:

charger.Status

getDCStatus()[source]

Retrieves the DC supply status.

Returns:

A status code to indicate the DC supply status.

Return type:

DCStatus

getError()[source]

Determines the error state for the charger chip, if one.

Returns:

A charger error code to further describe reason for the error.

Return type:

ChargerError

getEventContext(event, context)[source]

Retrieve more detailed information on an event.

The event parameter should be interruptable.Event.evtInt1, as there is only this one interrupt line. On return, the context parameter carries the resulting information. It must be an instance of charger.EventContext, which is semantically multiplexed by its charger.EventContext.source attribute.

Also see: Interruptable.getEventContext().

Parameters:
  • event (int) – The original event occurred.

  • context (.charger.EventContext) – Context information.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

getInfo()[source]

Retrieves an information block from the charging device.

Typically, this kind of information is rather static in that, it does not change over time. Usually, this information is somewhat unique for the charger origin, manufacturing date, hardware/firmware revision, product/model ID, chip series and alike. For that reason, this function can be used to see, if communication works reliably.

Returns:

The information object and an error code indicating either success or the reason of failure.

Return type:

Info, ErrorCode

getNumCells()[source]

Retrieves the number of battery cells configured.

Returns the number of battery cells or a negative number if this information could not be retrieved.

Returns:

The number of cells.

Return type:

int

getPowerSrc()[source]

Retrieves the power source, that presumably drives the system at the moment that this function is executed.

Returns:

A code to indicate the power source.

Return type:

PowerSrc

getRegContentStr(regDescr, content)[source]
getRegisterMap()[source]
isBatteryPresent()[source]

Checks, if the battery is present.

This does not tell anything about whether the battery is charged or not.

Returns ErrorCode.errOk if a battery is present, ErrorCode.errUnavailable if the battery is not present and any other value to indicate the reason, why this information could not be retrieved.

See also: getChgStatus().

Returns:

An error code.

Return type:

ErrorCode

isWatchdogElapsed()[source]

Check, whether the configured time interval has expired, or not.

By calling this function, an application may observe the expiration without using the interrupt mechanism. Note, that this flag is not cleared automatically. The caller would have to use clearWatchdogElapsed() for this purpose.

Returns ErrorCode.errOk, if the watch dog has elapsed, ErrorCode.errUnavailable, if it is not elapsed, yet, and any other value to indicate the reason, why this information could not be retrieved.

Returns:

An error code indicating the result.

Return type:

ErrorCode

isWatchdogRunning()[source]

Check, whether the watchdog is currently running or not.

Returns ErrorCode.errOk, if the watch dog is running, ErrorCode.errUnavailable, if it is not running and any other value to indicate the reason, why this information could not be retrieved.

Returns:

An error code indicating the result.

Return type:

ErrorCode

open(paramDict)[source]

Opens this serial device and puts it into a usable state.

If this device has been attached to some bus, already, this method returns an error code. Otherwise, it tries to do this attachment as follows:

  • If the paramDict configuration parameters contain the SerialBusDevice.bus key, the associated value object is checked to be an instance of SerialBus. If successful, this device is attached to that bus. Otherwise, an error code is returned.

  • If no bus instance is passed in, one is created and opened using the same paramDict dictionary of options. If successful, this device gets attached to that new bus. Upon return, the caller might retrieve a reference to the new bus from the parameter dictionary entry with key SerialBusDevice.bus, or by reading the SerialBusDevice.serialBus attribute.

Also see: module.Module.open().

Parameters:

paramDict (dict(str, object)) – Configuration parameters as obtained from Params_init(), possibly.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

registerInterruptHandler(onEvent=None, callerFeedBack=None, handler=None)[source]

Registers a handling routine for interrupt notification.

The caller feedback will be directly passed to the handling routine. In case that multiple different interrupts are handled by the same routine, this parameter may be used to distinguish them and remember the source of interrupt.

The handler should be a method or function that expects at least one argument. That first argument will be the callerFeedBack object given as the above-mentioned parameter. Further parameters may follow, as they were handed in to the _fire() method. The handler’s signature should look like this:

def handlingRoutine( feedback, *args) -> None:

Note that the onEvent parameter is not passed to the handler. It is eaten up by _fire() and just controls the selection of the handling routine called.

Depending on the parameter, this method behaves as follows:

onEvent

handler

semantics and action

Event.evtNone

None

All interrupts are disabled and all registrations cleared.

Event.evtNone

valid

De-register the given handler from all events {Event.evtInt1|2|Any}.

Event.evtInt1|2|*

None

De-register all handlers from the given event.

Event.evtInt1|2|*

valid

Enable interrupt and register this handler for the given event.

Event.evtAny

None

Clear the Event.evtAny registrations, only!

Event.evtAny

valid

Register the handler for any event {Event.evtInt1|2}.

For this method, Event.evtNone is a semantic equivalent to None.

Parameters:
  • onEvent (int) – Exactly one of the event mnemonics defined by the interruptable.Event enumeration.

  • callerFeedBack (object) – Arbitrary object not evaluated here, but passed on to the handler when an event is fired.

  • handler – The handling routine to be called as an immediate response to an event.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

reset()[source]

Soft resets the device.

The device is in some default state, afterwards and must be re-configured according to the application’s needs. :return: An error code indicating either success or the reason of failure. :rtype: ErrorCode

restartCharging()[source]

Tries to restart the charging phase.

This could be necessary, e.g. after recovering from a thermal shutdown.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

setRunLevel(level)[source]

Select the power-saving operation mode.

Switches the instance to one of the power-saving modes or recovers from these modes. Situation-aware deployment of these modes can greatly reduce the system’s total power consumption.

Parameters:

level (RunLevel) – The level to switch to.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

philander.max77960_reg module

Register definition for the MAX77960 USB battery charger.

Definition of registers, content masks and default values for the above mentioined chip. Externalized, just for clarity of the source code.

class MAX77960_Reg[source]

Bases: object

AICL_I = 128
AICL_M = 128
AICL_OK = 128
APP_MODE_DTLS = 8
APP_MODE_DTLS_CHRG = 8
APP_MODE_DTLS_CONV = 0
B2SOVRC = 15
B2SOVRC_10000 = 15
B2SOVRC_3000 = 1
B2SOVRC_3500 = 2
B2SOVRC_4000 = 3
B2SOVRC_4500 = 4
B2SOVRC_5000 = 5
B2SOVRC_5500 = 6
B2SOVRC_6000 = 7
B2SOVRC_6500 = 8
B2SOVRC_7000 = 9
B2SOVRC_7500 = 10
B2SOVRC_8000 = 11
B2SOVRC_8500 = 12
B2SOVRC_9000 = 13
B2SOVRC_9500 = 14
B2SOVRC_DEFAULT = 4
B2SOVRC_DISABLED = 0
B2SOVRC_DTC = 64
B2SOVRC_DTC_100_MS = 64
B2SOVRC_DTC_6_MS = 0
B2SOVRC_DTC_DEFAULT = 0
B2SOVRC_DTC_MAX = 64
B2SOVRC_DTC_MIN = 0
B2SOVRC_I = 32
B2SOVRC_M = 32
B2SOVRC_MAX = 15
B2SOVRC_MIN = 1
B2SOVRC_OK = 32
BAT_DTLS = 112
BAT_DTLS_BELOW_PREQ = 16
BAT_DTLS_LOW_VOLT = 64
BAT_DTLS_NO_LEVEL = 112
BAT_DTLS_OK = 48
BAT_DTLS_OVR_CURR = 96
BAT_DTLS_OVR_VOLT = 80
BAT_DTLS_REMOVAL = 0
BAT_DTLS_TIME_OUT = 32
BAT_I = 8
BAT_M = 8
BAT_OK = 8
CHGCC = 63
CHGCC_100 = 0
CHGCC_1000 = 13
CHGCC_1100 = 14
CHGCC_1200 = 15
CHGCC_1300 = 16
CHGCC_1400 = 17
CHGCC_150 = 1
CHGCC_1500 = 18
CHGCC_1600 = 19
CHGCC_1700 = 20
CHGCC_1800 = 21
CHGCC_1900 = 22
CHGCC_200 = 2
CHGCC_2000 = 23
CHGCC_2100 = 24
CHGCC_2200 = 25
CHGCC_2300 = 26
CHGCC_2400 = 27
CHGCC_250 = 3
CHGCC_2500 = 28
CHGCC_2600 = 29
CHGCC_2700 = 30
CHGCC_2800 = 31
CHGCC_2900 = 32
CHGCC_300 = 4
CHGCC_3000 = 33
CHGCC_3100 = 34
CHGCC_3200 = 35
CHGCC_3300 = 36
CHGCC_3400 = 37
CHGCC_350 = 5
CHGCC_3500 = 38
CHGCC_3600 = 39
CHGCC_3700 = 40
CHGCC_3800 = 41
CHGCC_3900 = 42
CHGCC_400 = 6
CHGCC_4000 = 43
CHGCC_4100 = 44
CHGCC_4200 = 45
CHGCC_4300 = 46
CHGCC_4400 = 47
CHGCC_450 = 7
CHGCC_4500 = 48
CHGCC_4600 = 49
CHGCC_4700 = 50
CHGCC_4800 = 51
CHGCC_4900 = 52
CHGCC_500 = 8
CHGCC_5000 = 53
CHGCC_5100 = 54
CHGCC_5200 = 55
CHGCC_5300 = 56
CHGCC_5400 = 57
CHGCC_5500 = 58
CHGCC_5600 = 59
CHGCC_5700 = 60
CHGCC_5800 = 61
CHGCC_5900 = 62
CHGCC_600 = 9
CHGCC_6000 = 63
CHGCC_700 = 10
CHGCC_800 = 11
CHGCC_900 = 12
CHGCC_DEFAULT = 7
CHGCC_MAX = 63
CHGCC_MIN = 0
CHGINLIM_I = 4
CHGINLIM_M = 4
CHGINLIM_OK = 4
CHGIN_DTLS = 96
CHGIN_DTLS_GOOD = 96
CHGIN_DTLS_RSVD = 32
CHGIN_DTLS_TOO_HIGH = 64
CHGIN_DTLS_TOO_LOW = 0
CHGIN_I = 64
CHGIN_ILIM = 127
CHGIN_ILIM_100 = 0
CHGIN_ILIM_1000 = 21
CHGIN_ILIM_100_1 = 1
CHGIN_ILIM_100_2 = 2
CHGIN_ILIM_100_3 = 3
CHGIN_ILIM_1050 = 22
CHGIN_ILIM_1100 = 23
CHGIN_ILIM_1150 = 24
CHGIN_ILIM_1200 = 25
CHGIN_ILIM_1250 = 26
CHGIN_ILIM_1300 = 27
CHGIN_ILIM_1350 = 28
CHGIN_ILIM_1400 = 29
CHGIN_ILIM_1450 = 30
CHGIN_ILIM_150 = 4
CHGIN_ILIM_1500 = 31
CHGIN_ILIM_1550 = 32
CHGIN_ILIM_1600 = 33
CHGIN_ILIM_1650 = 34
CHGIN_ILIM_1700 = 35
CHGIN_ILIM_1750 = 36
CHGIN_ILIM_1800 = 37
CHGIN_ILIM_1850 = 38
CHGIN_ILIM_1900 = 39
CHGIN_ILIM_1950 = 40
CHGIN_ILIM_200 = 5
CHGIN_ILIM_2000 = 41
CHGIN_ILIM_2050 = 42
CHGIN_ILIM_2100 = 43
CHGIN_ILIM_2150 = 44
CHGIN_ILIM_2200 = 45
CHGIN_ILIM_2250 = 46
CHGIN_ILIM_2300 = 47
CHGIN_ILIM_2350 = 48
CHGIN_ILIM_2400 = 49
CHGIN_ILIM_2450 = 50
CHGIN_ILIM_250 = 6
CHGIN_ILIM_2500 = 51
CHGIN_ILIM_2550 = 52
CHGIN_ILIM_2600 = 53
CHGIN_ILIM_2650 = 54
CHGIN_ILIM_2700 = 55
CHGIN_ILIM_2750 = 56
CHGIN_ILIM_2800 = 57
CHGIN_ILIM_2850 = 58
CHGIN_ILIM_2900 = 59
CHGIN_ILIM_2950 = 60
CHGIN_ILIM_300 = 7
CHGIN_ILIM_3000 = 61
CHGIN_ILIM_3050 = 62
CHGIN_ILIM_3100 = 63
CHGIN_ILIM_3150 = 64
CHGIN_ILIM_3200 = 65
CHGIN_ILIM_3250 = 66
CHGIN_ILIM_3300 = 67
CHGIN_ILIM_3350 = 68
CHGIN_ILIM_3400 = 69
CHGIN_ILIM_3450 = 70
CHGIN_ILIM_350 = 8
CHGIN_ILIM_3500 = 71
CHGIN_ILIM_3550 = 72
CHGIN_ILIM_3600 = 73
CHGIN_ILIM_3650 = 74
CHGIN_ILIM_3700 = 75
CHGIN_ILIM_3750 = 76
CHGIN_ILIM_3800 = 77
CHGIN_ILIM_3850 = 78
CHGIN_ILIM_3900 = 79
CHGIN_ILIM_3950 = 80
CHGIN_ILIM_400 = 9
CHGIN_ILIM_4000 = 81
CHGIN_ILIM_4050 = 82
CHGIN_ILIM_4100 = 83
CHGIN_ILIM_4150 = 84
CHGIN_ILIM_4200 = 85
CHGIN_ILIM_4250 = 86
CHGIN_ILIM_4300 = 87
CHGIN_ILIM_4350 = 88
CHGIN_ILIM_4400 = 89
CHGIN_ILIM_4450 = 90
CHGIN_ILIM_450 = 10
CHGIN_ILIM_4500 = 91
CHGIN_ILIM_4550 = 92
CHGIN_ILIM_4600 = 93
CHGIN_ILIM_4650 = 94
CHGIN_ILIM_4700 = 95
CHGIN_ILIM_4750 = 96
CHGIN_ILIM_4800 = 97
CHGIN_ILIM_4850 = 98
CHGIN_ILIM_4900 = 99
CHGIN_ILIM_4950 = 100
CHGIN_ILIM_500 = 11
CHGIN_ILIM_5000 = 101
CHGIN_ILIM_5050 = 102
CHGIN_ILIM_5100 = 103
CHGIN_ILIM_5150 = 104
CHGIN_ILIM_5200 = 105
CHGIN_ILIM_5250 = 106
CHGIN_ILIM_5300 = 107
CHGIN_ILIM_5350 = 108
CHGIN_ILIM_5400 = 109
CHGIN_ILIM_5450 = 110
CHGIN_ILIM_550 = 12
CHGIN_ILIM_5500 = 111
CHGIN_ILIM_5550 = 112
CHGIN_ILIM_5600 = 113
CHGIN_ILIM_5650 = 114
CHGIN_ILIM_5700 = 115
CHGIN_ILIM_5750 = 116
CHGIN_ILIM_5800 = 117
CHGIN_ILIM_5850 = 118
CHGIN_ILIM_5900 = 119
CHGIN_ILIM_5950 = 120
CHGIN_ILIM_600 = 13
CHGIN_ILIM_6000 = 121
CHGIN_ILIM_6050 = 122
CHGIN_ILIM_6100 = 123
CHGIN_ILIM_6150 = 124
CHGIN_ILIM_6200 = 125
CHGIN_ILIM_6250 = 126
CHGIN_ILIM_6300 = 127
CHGIN_ILIM_650 = 14
CHGIN_ILIM_700 = 15
CHGIN_ILIM_750 = 16
CHGIN_ILIM_800 = 17
CHGIN_ILIM_850 = 18
CHGIN_ILIM_900 = 19
CHGIN_ILIM_950 = 20
CHGIN_ILIM_DEFAULT = 11
CHGIN_ILIM_DEFAULT_VALUE = 500
CHGIN_ILIM_MAX = 127
CHGIN_ILIM_MIN = 0
CHGIN_M = 64
CHGIN_OK = 64
CHGPROT = 12
CHGPROT_DEFAULT = 0
CHGPROT_LOCK = 0
CHGPROT_LOCK_4 = 4
CHGPROT_LOCK_8 = 8
CHGPROT_UNLOCK = 12
CHG_CV_PRM = 63
CHG_CV_PRM_2C_8000 = 0
CHG_CV_PRM_2C_8020 = 1
CHG_CV_PRM_2C_8040 = 2
CHG_CV_PRM_2C_8060 = 3
CHG_CV_PRM_2C_8080 = 4
CHG_CV_PRM_2C_8100 = 5
CHG_CV_PRM_2C_8120 = 6
CHG_CV_PRM_2C_8140 = 7
CHG_CV_PRM_2C_8160 = 8
CHG_CV_PRM_2C_8180 = 9
CHG_CV_PRM_2C_8200 = 10
CHG_CV_PRM_2C_8220 = 11
CHG_CV_PRM_2C_8240 = 12
CHG_CV_PRM_2C_8260 = 13
CHG_CV_PRM_2C_8280 = 14
CHG_CV_PRM_2C_8300 = 15
CHG_CV_PRM_2C_8320 = 16
CHG_CV_PRM_2C_8340 = 17
CHG_CV_PRM_2C_8360 = 18
CHG_CV_PRM_2C_8380 = 19
CHG_CV_PRM_2C_8400 = 20
CHG_CV_PRM_2C_8420 = 21
CHG_CV_PRM_2C_8440 = 22
CHG_CV_PRM_2C_8460 = 23
CHG_CV_PRM_2C_8480 = 24
CHG_CV_PRM_2C_8500 = 25
CHG_CV_PRM_2C_8520 = 26
CHG_CV_PRM_2C_8540 = 27
CHG_CV_PRM_2C_8560 = 28
CHG_CV_PRM_2C_8580 = 29
CHG_CV_PRM_2C_8600 = 30
CHG_CV_PRM_2C_8620 = 31
CHG_CV_PRM_2C_8640 = 32
CHG_CV_PRM_2C_8660 = 33
CHG_CV_PRM_2C_8680 = 34
CHG_CV_PRM_2C_8700 = 35
CHG_CV_PRM_2C_8720 = 36
CHG_CV_PRM_2C_8740 = 37
CHG_CV_PRM_2C_8760 = 38
CHG_CV_PRM_2C_8780 = 39
CHG_CV_PRM_2C_8800 = 40
CHG_CV_PRM_2C_8820 = 41
CHG_CV_PRM_2C_8840 = 42
CHG_CV_PRM_2C_8860 = 43
CHG_CV_PRM_2C_8880 = 44
CHG_CV_PRM_2C_8900 = 45
CHG_CV_PRM_2C_8920 = 46
CHG_CV_PRM_2C_8940 = 47
CHG_CV_PRM_2C_8960 = 48
CHG_CV_PRM_2C_8980 = 49
CHG_CV_PRM_2C_9000 = 50
CHG_CV_PRM_2C_9020 = 51
CHG_CV_PRM_2C_9040 = 52
CHG_CV_PRM_2C_9060 = 53
CHG_CV_PRM_2C_9080 = 54
CHG_CV_PRM_2C_9100 = 55
CHG_CV_PRM_2C_9120 = 56
CHG_CV_PRM_2C_9140 = 57
CHG_CV_PRM_2C_9160 = 58
CHG_CV_PRM_2C_9180 = 59
CHG_CV_PRM_2C_9200 = 60
CHG_CV_PRM_2C_9220 = 61
CHG_CV_PRM_2C_9240 = 62
CHG_CV_PRM_2C_9260 = 63
CHG_CV_PRM_2C_DEFAULT = 0
CHG_CV_PRM_2C_MAX = 63
CHG_CV_PRM_2C_MIN = 0
CHG_CV_PRM_3C_12000 = 0
CHG_CV_PRM_3C_12030 = 1
CHG_CV_PRM_3C_12060 = 2
CHG_CV_PRM_3C_12090 = 3
CHG_CV_PRM_3C_12120 = 4
CHG_CV_PRM_3C_12150 = 5
CHG_CV_PRM_3C_12180 = 6
CHG_CV_PRM_3C_12210 = 7
CHG_CV_PRM_3C_12240 = 8
CHG_CV_PRM_3C_12270 = 9
CHG_CV_PRM_3C_12300 = 10
CHG_CV_PRM_3C_12330 = 11
CHG_CV_PRM_3C_12360 = 12
CHG_CV_PRM_3C_12390 = 13
CHG_CV_PRM_3C_12420 = 14
CHG_CV_PRM_3C_12450 = 15
CHG_CV_PRM_3C_12480 = 16
CHG_CV_PRM_3C_12510 = 17
CHG_CV_PRM_3C_12540 = 18
CHG_CV_PRM_3C_12570 = 19
CHG_CV_PRM_3C_12600 = 20
CHG_CV_PRM_3C_12630 = 21
CHG_CV_PRM_3C_12660 = 22
CHG_CV_PRM_3C_12690 = 23
CHG_CV_PRM_3C_12720 = 24
CHG_CV_PRM_3C_12750 = 25
CHG_CV_PRM_3C_12780 = 26
CHG_CV_PRM_3C_12810 = 27
CHG_CV_PRM_3C_12840 = 28
CHG_CV_PRM_3C_12870 = 29
CHG_CV_PRM_3C_12900 = 30
CHG_CV_PRM_3C_12930 = 31
CHG_CV_PRM_3C_12960 = 32
CHG_CV_PRM_3C_12990 = 33
CHG_CV_PRM_3C_13020 = 34
CHG_CV_PRM_3C_13050 = 35
CHG_CV_PRM_3C_DEFAULT = 0
CHG_CV_PRM_3C_MAX = 35
CHG_CV_PRM_3C_MIN = 0
CHG_CV_PRM_DEFAULT = 0
CHG_DTLS = 15
CHG_DTLS_DONE = 4
CHG_DTLS_E_TIMER = 6
CHG_DTLS_FAST_CURR = 1
CHG_DTLS_FAST_VOLT = 2
CHG_DTLS_OFF_CHGIN = 8
CHG_DTLS_OFF_RESIST = 5
CHG_DTLS_OFF_TEMP = 10
CHG_DTLS_OFF_WDOG = 11
CHG_DTLS_PRECHRG = 0
CHG_DTLS_SUSP_JEITA = 12
CHG_DTLS_SUSP_NOBAT = 13
CHG_DTLS_SUSP_QBAT = 7
CHG_DTLS_TOP_OFF = 3
CHG_I = 16
CHG_INT_MASK_ALL = 255
CHG_INT_MASK_DEFAULT = 255
CHG_INT_MASK_NONE = 0
CHG_M = 16
CHG_OK = 16
CHG_RSTRT = 48
CHG_RSTRT_100 = 0
CHG_RSTRT_150 = 16
CHG_RSTRT_200 = 32
CHG_RSTRT_DEFAULT = 16
CHG_RSTRT_DISABLED = 48
CHG_RSTRT_MAX = 32
CHG_RSTRT_MIN = 0
CID_MAX7796x = 160
CID_MAX7796xB = 192
CID_REVISION = 224
CID_REV_5 = 160
CID_REV_6 = 192
CID_REV_MAX = 192
CID_REV_MIN = 160
CID_VERSION = 31
COMM_MODE = 128
COMM_MODE_AUTO = 0
COMM_MODE_DEFAULT = 0
COMM_MODE_I2C = 128
DISIBS = 64
DISIBS_DEFAULT = 0
DISIBS_FET_OFF = 64
DISIBS_FET_PPSM = 0
DISKIP = 1
DISKIP_AUTO = 0
DISKIP_DEFAULT = 0
DISKIP_DISABLED = 1
DISQBAT_I = 2
DISQBAT_M = 2
DISQBAT_OK = 2
FCHGTIME = 7
FCHGTIME_10H = 7
FCHGTIME_3H = 1
FCHGTIME_4H = 2
FCHGTIME_5H = 3
FCHGTIME_6H = 4
FCHGTIME_7H = 5
FCHGTIME_8H = 6
FCHGTIME_DEFAULT = 1
FCHGTIME_DISABLED = 0
FCHGTIME_MAX = 7
FCHGTIME_MIN = 1
FSHIP_MODE = 1
FSHIP_MODE_DEFAULT = 0
FSHIP_MODE_OFF = 0
FSHIP_MODE_ON = 1
FSW_DTLS = 6
FSW_DTLS_1200K = 2
FSW_DTLS_600K = 0
ICHGCC_COOL = 2
ICHGCC_COOL_DEFAULT = 2
ICHGCC_COOL_NORMAL = 0
ICHGCC_COOL_REDUCED = 2
INLIM_CLK = 192
INLIM_CLK_1024 = 128
INLIM_CLK_256 = 64
INLIM_CLK_4096 = 192
INLIM_CLK_8 = 0
INLIM_CLK_DEFAULT = 128
INLIM_CLK_MAX = 192
INLIM_CLK_MIN = 0
ITRICKLE = 48
ITRICKLE_100 = 0
ITRICKLE_200 = 16
ITRICKLE_300 = 32
ITRICKLE_400 = 48
ITRICKLE_DEFAULT = 0
ITRICKLE_MAX = 48
ITRICKLE_MIN = 0
JEITA_EN = 128
JEITA_EN_DEFAULT = 0
JEITA_EN_OFF = 0
JEITA_EN_ON = 128
LPM = 64
LPM_DEFAULT = 0
LPM_NORMAL = 0
LPM_ON = 64
MINVSYS = 7
MINVSYS_2C_5535 = 0
MINVSYS_2C_5740 = 1
MINVSYS_2C_5945 = 2
MINVSYS_2C_6150 = 3
MINVSYS_2C_6355 = 4
MINVSYS_2C_6560 = 5
MINVSYS_2C_6765 = 6
MINVSYS_2C_6970 = 7
MINVSYS_2C_DEFAULT = 3
MINVSYS_2C_MAX = 7
MINVSYS_2C_MIN = 0
MINVSYS_3C_10148 = 6
MINVSYS_3C_10455 = 7
MINVSYS_3C_8303 = 0
MINVSYS_3C_8610 = 1
MINVSYS_3C_8918 = 2
MINVSYS_3C_9225 = 3
MINVSYS_3C_9533 = 4
MINVSYS_3C_9840 = 5
MINVSYS_3C_DEFAULT = 3
MINVSYS_3C_MAX = 7
MINVSYS_3C_MIN = 0
MINVSYS_DEFAULT = 3
MODE = 15
MODE_ALL_OFF = 0
MODE_ALL_OFF_1 = 1
MODE_ALL_OFF_2 = 2
MODE_ALL_OFF_3 = 3
MODE_CHRG_DCDC = 5
MODE_CHRG_DCDC_6 = 6
MODE_CHRG_DCDC_7 = 7
MODE_DCDC_ONLY = 4
MODE_DEFAULT = 5
MODE_OTG_ONLY = 10
NUM_CELL_DTLS = 1
NUM_CELL_DTLS_2 = 0
NUM_CELL_DTLS_3 = 1
OTG_DTLS = 24
OTG_DTLS_ILIM = 24
OTG_DTLS_OTG_GOOD = 8
OTG_DTLS_OVERVOLT = 16
OTG_DTLS_UNDERVOLT = 0
OTG_ILIM = 56
OTG_ILIM_1200 = 16
OTG_ILIM_1500 = 24
OTG_ILIM_2000 = 32
OTG_ILIM_2250 = 40
OTG_ILIM_2500 = 48
OTG_ILIM_3000 = 56
OTG_ILIM_500 = 0
OTG_ILIM_900 = 8
OTG_ILIM_DEFAULT = 24
OTG_ILIM_MAX = 56
OTG_ILIM_MIN = 0
OTG_PLIM_I = 1
OTG_PLIM_M = 1
OTG_PLIM_OK = 1
PQEN = 128
PQEN_DEFAULT = 128
PQEN_OFF = 0
PQEN_ON = 128
QB_DTLS = 1
QB_DTLS_OFF = 0
QB_DTLS_ON = 1
REGTEMP = 120
REGTEMP_100 = 24
REGTEMP_105 = 32
REGTEMP_110 = 40
REGTEMP_115 = 48
REGTEMP_120 = 56
REGTEMP_125 = 64
REGTEMP_130 = 72
REGTEMP_85 = 0
REGTEMP_90 = 8
REGTEMP_95 = 16
REGTEMP_DEFAULT = 48
REGTEMP_MAX = 72
REGTEMP_MIN = 0
REG_CHG_CNFG_00 = 22
REG_CHG_CNFG_01 = 23
REG_CHG_CNFG_02 = 24
REG_CHG_CNFG_03 = 25
REG_CHG_CNFG_04 = 26
REG_CHG_CNFG_05 = 27
REG_CHG_CNFG_06 = 28
REG_CHG_CNFG_07 = 29
REG_CHG_CNFG_08 = 30
REG_CHG_CNFG_09 = 31
REG_CHG_CNFG_10 = 32
REG_CHG_DETAILS_00 = 19
REG_CHG_DETAILS_01 = 20
REG_CHG_DETAILS_02 = 21
REG_CHG_INT = 16
REG_CHG_INT_MASK = 17
REG_CHG_INT_OK = 18
REG_CID = 0
REG_SWRST = 1
REG_TOP_INT = 2
REG_TOP_INT_MASK = 3
REG_TOP_INT_OK = 4
STAT_EN = 8
STAT_EN_DEFAULT = 8
STAT_EN_OFF = 0
STAT_EN_ON = 8
STBY_EN = 32
STBY_EN_DCDC_DEFAULT = 0
STBY_EN_DCDC_OFF = 32
STBY_EN_DCDC_PPSM = 0
SWRST_DEFAULT = 0
SWRST_NONE = 0
SWRST_TYPE_O = 165
SYSOVLO_I = 2
SYSOVLO_M = 2
SYSOVLO_OK = 2
SYSUVLO_I = 1
SYSUVLO_M = 1
SYSUVLO_OK = 1
SYS_TRACK_DEFAULT = 128
SYS_TRACK_DIS = 128
SYS_TRACK_DISABLED = 128
SYS_TRACK_ENABLED = 0
THM_DTLS = 112
THM_DTLS_BAT_RMVD = 80
THM_DTLS_COLD = 0
THM_DTLS_COOL = 16
THM_DTLS_DISABLED = 96
THM_DTLS_HOT = 64
THM_DTLS_NORMAL = 32
THM_DTLS_WARM = 48
TOP_INT_MASK_ALL = 7
TOP_INT_MASK_DEFAULT = 255
TOP_INT_MASK_NONE = 0
TO_ITH = 7
TO_ITH_100 = 0
TO_ITH_200 = 1
TO_ITH_300 = 2
TO_ITH_400 = 3
TO_ITH_500 = 4
TO_ITH_600 = 5
TO_ITH_600_6 = 6
TO_ITH_600_7 = 7
TO_ITH_DEFAULT = 0
TO_ITH_MAX = 5
TO_ITH_MIN = 0
TO_TIME = 56
TO_TIME_10_MIN = 8
TO_TIME_20_MIN = 16
TO_TIME_30_MIN = 24
TO_TIME_30_SEC = 0
TO_TIME_40_MIN = 32
TO_TIME_50_MIN = 40
TO_TIME_60_MIN = 48
TO_TIME_70_MIN = 56
TO_TIME_DEFAULT = 24
TO_TIME_MAX = 56
TO_TIME_MIN = 0
TREG = 128
TREG_GOOD = 0
TREG_HIGH = 128
TSHDN_I = 4
TSHDN_M = 4
TSHDN_OK = 4
VCHGCV_COOL = 4
VCHGCV_COOL_DEFAULT = 0
VCHGCV_COOL_NORMAL = 0
VCHGCV_COOL_REDUCED = 4
VCHGIN_REG = 62
VCHGIN_REG_10150 = 30
VCHGIN_REG_10675 = 32
VCHGIN_REG_10950 = 34
VCHGIN_REG_11550 = 36
VCHGIN_REG_12150 = 38
VCHGIN_REG_12750 = 40
VCHGIN_REG_13350 = 42
VCHGIN_REG_13950 = 44
VCHGIN_REG_14550 = 46
VCHGIN_REG_15150 = 48
VCHGIN_REG_15750 = 50
VCHGIN_REG_16350 = 52
VCHGIN_REG_16950 = 54
VCHGIN_REG_17550 = 56
VCHGIN_REG_18150 = 58
VCHGIN_REG_18750 = 60
VCHGIN_REG_19050 = 62
VCHGIN_REG_4025 = 0
VCHGIN_REG_4200 = 2
VCHGIN_REG_4375 = 4
VCHGIN_REG_4550 = 6
VCHGIN_REG_4725 = 8
VCHGIN_REG_4900 = 10
VCHGIN_REG_5425 = 12
VCHGIN_REG_5950 = 14
VCHGIN_REG_6475 = 16
VCHGIN_REG_7000 = 18
VCHGIN_REG_7525 = 20
VCHGIN_REG_8050 = 22
VCHGIN_REG_8575 = 24
VCHGIN_REG_9100 = 26
VCHGIN_REG_9625 = 28
VCHGIN_REG_DEFAULT = 8
VCHGIN_REG_MAX = 62
VCHGIN_REG_MIN = 0
WDTCLR = 3
WDTCLR_DEFAULT = 0
WDTCLR_DO_CLEAR = 1
WDTCLR_DO_NOT_TOUCH = 0
WDTCLR_DO_NOT_TOUCH_2 = 2
WDTCLR_DO_NOT_TOUCH_3 = 3
WDTEN = 16
WDTEN_DEFAULT = 0
WDTEN_OFF = 0
WDTEN_ON = 16
registerMap = [[0, 'CID', ([224, 'REV'], [31, 'VER'], [255, 'ID'])], [1, 'SWRST', ()], [2, 'TOP_INT', ([4, 'TSHDN_I'], [2, 'SYSOVLO_I'], [1, 'SYSUVLO_I'])], [3, 'TOP_INT_MASK', ([4, 'TSHDN_M'], [2, 'SYSOVLO_M'], [1, 'SYSUVLO_M'])], [4, 'TOP_INT_OK', ([4, 'TSHDN_OK'], [2, 'SYSOVLO_OK'], [1, 'SYSUVLO_OK'])], [16, 'CHG_INT', ([128, 'AICL_I'], [64, 'CHGIN_I'], [32, 'B2SOVRC_I'], [16, '_CHG_I'], [8, 'BAT_I'], [4, 'CHGINLIM_I'], [2, 'DISQBAT_I'], [1, 'OTG_PLIM_I'])], [17, 'CHG_INT_MASK', ([128, 'AICL_M'], [64, 'CHGIN_M'], [32, 'B2SOVRC_M'], [16, 'CHG_M'], [8, 'BAT_M'], [4, 'CHGINLIM_M'], [2, 'DISQBAT_M'], [1, 'OTG_PLIM_M'])], [18, 'CHG_INT_OK', ([128, 'AICL_OK'], [64, 'CHGIN_OK'], [32, 'B2SOVRC_OK'], [16, 'CHG_OK'], [8, 'BAT_OK'], [4, 'CHGINLIM_OK'], [2, 'DISQBAT_OK'], [1, 'OTG_PLIM_OK'])], [19, 'CHG_DETAILS_00', ([96, 'CHGIN_DTLS'], [24, 'OTG_DTLS'], [1, 'QB_DTLS'])], [20, 'CHG_DETAILS_01', ([128, 'TREG'], [112, 'BAT_DTLS'], [15, 'CHG_DTLS'])], [21, 'CHG_DETAILS_02', ([112, 'THM_DTLS'], [8, 'APP_MODE_DTLS'], [6, 'FSW_DTLS'], [1, 'NUM_CELL_DTLS'])], [22, 'CHG_CNFG_00', ([128, 'COMM_MODE'], [64, 'DISIBS'], [32, 'STBY_EN'], [16, 'WDTEN'], [15, 'MODE'])], [23, 'CHG_CNFG_01', ([128, 'PQEN'], [64, 'LPM'], [48, 'CHG_RSTRT'], [8, 'STAT_EN'], [7, 'FCHGTIME'])], [24, 'CHG_CNFG_02', ([63, 'CHGCC'],)], [25, 'CHG_CNFG_03', ([128, 'SYS_TRACK_DIS'], [64, 'B2SOVRC_DTC'], [56, 'TO_TIME'], [7, 'TO_ITH'])], [26, 'CHG_CNFG_04', ([63, 'CHG_CV_PRM'],)], [27, 'CHG_CNFG_05', ([48, 'ITRICKLE'], [15, 'B2SOVRC'])], [28, 'CHG_CNFG_06', ([12, 'CHGPROT'], [3, 'WDTCLR'])], [29, 'CHG_CNFG_07', ([128, 'JEITA_EN'], [120, 'REGTEMP'], [4, 'VCHGCV_COOL'], [2, 'ICHGCC_COOL'], [1, 'FSHIP_MODE'])], [30, 'CHG_CNFG_08', ([127, 'CHGIN_ILIM'],)], [31, 'CHG_CNFG_09', ([192, 'INLIM_CLK'], [56, 'OTG_ILIM'], [7, 'MINVSYS'])], [32, 'CHG_CNFG_10', ([62, 'VCHGIN_REG'], [1, 'DISKIP'])]]

philander.mcp40 module

Driver implementation for the MCP40 17/18/19 digital potentiometers.

More information on the functionality of the chip can be found at the microchip’s site for the 18 series chip with download for data sheet of all three chips: https://www.microchip.com/en-us/product/MCP4018

class MCP40[source]

Bases: SerialBusDevice, Potentiometer

MCP40 family and MCP40D family driver implementation. This implementation was tested using a MCP40D18T-104E/LT. It should also work for any other specified chip.

The MCP40 and MCP40D family’s chips are digital potentiometers that are controlled via an I2C interface. Their difference lies in their terminal configurations. The all come in different resistances of 5kOhm, 10kOhm, 50kOhm and 100kOhm. Read more under https://www.microship.com/en-us/product/MCP4017

ADDRESSES_ALLOWED = [46, 62, 47]
classmethod Params_init(paramDict)[source]

Initializes configuration parameters with defaults.

The following settings are supported:

Key name

Value type, meaning and default

SerialBusDevice.address

int I2C serial device address; default is ADDRESSES_ALLOWED [0].

Potentiometer.resistance.max int Maximum resistance in Ohm; DEFAULT_RESISTANCE_MAX.

Also see: SerialBusDevice.Params_init(), Potentiometer.Params_init().

close()[source]

Close this instance and release hardware resources.

Also see: Module.close().

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

getDigital()[source]

Get resistance of potentiometer as a digital value in [0…digital.max]

Also see: Potentiometer.get().

Returns:

The resistance value and an error code indicating either success or the reason of failure.

Return type:

Tuple(ErrorCode, data)

open(paramDict)[source]

Initialize an instance and prepare it for use.

Also see: Module.open().

Parameters:

paramDict (dict(str, object)) – Configuration parameters as possibly obtained from Params_init().

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

setDigital(digital)[source]

Set resistance of potentiometer to a digital value.

Also see: Potentiometer.setDigital().

Parameters:

digital (int) – Digital resistance value to be sent directly to the potentiometer without conversion.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

philander.module module

Module to provide the Module base class.

class Module[source]

Bases: object

Generic interface to describe the capabilities of a module.

This is an abstract base class to define methods for ramp-up, shut-down or switch into certain run level, that are common to each class on module-level.

classmethod Params_init(paramDict)[source]

Initialize parameters with their defaults.

The given dictionary should not be None, on entry. Options not present in the dictionary will be added and set to their defaults on return.

Parameters:

paramDict (dict(str, object)) – Dictionary mapping option names to their respective values.

Returns:

none

Return type:

None

close()[source]

Close this instance and release associated hardware resources.

This is the counterpart of open(). Upon return, further usage of this instance is prohibited and may lead to unexpected results. The instance can be re-activated by calling open(), again.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

open(paramDict)[source]

Open the instance and set it in a usable state.

Allocate necessary hardware resources and configure user-adjustable parameters to meaningful defaults. This function must be called prior to any further usage of the instance. Involving it in the system ramp-up procedure could be a good choice. After usage of this instance is finished, the application should call close().

Parameters:

paramDict (dict(str, object)) – Configuration parameters as obtained from module.Module.Params_init(), possibly.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

setRunLevel(level)[source]

Select the power-saving operation mode.

Switches the instance to one of the power-saving modes or recovers from these modes. Situation-aware deployment of these modes can greatly reduce the system’s total power consumption.

Parameters:

level (RunLevel) – The level to switch to.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

philander.penum module

A light-weight replication of the Python 3.4 built-in Enum and Flag classes.

For portability, this is to support the MicroPython environments. While functionality is drastically reduced, this implementation strives for providing the most basic features of enums, flags and dataclasses.

class Enum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: object

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

>>> Color.RED
<Color.RED: 1>
  • value lookup:

>>> Color(1)
<Color.RED: 1>
  • name lookup:

>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

name

The name of the Enum member.

value

The value of the Enum member.

class Flag(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Support for flags

class auto(value=_auto_null)[source]

Bases: object

Instances are replaced with an appropriate value in Enum class suites.

dataclass(cls=None, /, *, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False, weakref_slot=False)[source]

Add dunder methods based on the fields defined in the class.

Examines PEP 526 __annotations__ to determine fields.

If init is true, an __init__() method is added to the class. If repr is true, a __repr__() method is added. If order is true, rich comparison dunder methods are added. If unsafe_hash is true, a __hash__() method is added. If frozen is true, fields may not be assigned to after instance creation. If match_args is true, the __match_args__ tuple is added. If kw_only is true, then by default all fields are keyword-only. If slots is true, a new class with a __slots__ attribute is returned.

idiotypic(cls)[source]
unique(enumeration)[source]

Class decorator for enumerations ensuring unique member values.

philander.potentiometer module

A module to provide a base class for potentiometer driver implementations.

philander.primitives module

A module to reflect fundamental physical units and scales.

class Current[source]

Bases: int

invalid = -1
class Percentage[source]

Bases: int

static checkRange(value)[source]

Check if the given value is a plausible percentage.

If the given value is within the range of [0…100], this method returns ErrorCode.errOk. Otherwise, it gives ErrorCode.errInvalidParameter.

Parameters:

value (int) – Something that compares to integer numbers, interpreted as a percentage.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

invalid = 255
class PreciseTemperature[source]

Bases: int

Temperature [-70…+125]in degree Celsius [°C], given as a Q8.8 fixed-point number with 8-bit decimals.

invalid = -32768
max = 32767
min = -32767
class Temperature[source]

Bases: int

invalid = -128
class Voltage[source]

Bases: int

invalid = 65535

philander.pwm module

Abstraction module for the pulse-width-modulation feature.

Provide a convergence layer API to abstract from several different PWM implementing driver modules provided on the target system.

class PWM[source]

Bases: Module

Pulse-width-modulation abstraction class.

Provide access to and control over the underlying PWM hardware. For that, an implementing driver module is used. As a convergence layer, this class is to hide specifics and to level syntactic requirements of the implementing package.

DEFAULT_DUTY = 50
DEFAULT_FREQUENCY = 100000
OFF = 0
ON = 1
classmethod Params_init(paramDict)[source]

Initialize parameters with their defaults.

The given dictionary should not be None, on entry. Options not present in the dictionary will be added and set to their defaults on return. The following options are supported.

Key

Range

Default

pwm.pinNumbering

GPIO.PINNUMBERING_[BCM | BOARD]

GPIO.PINNUMBERING_BCM

pwm.pinDesignator

pin name or number (e.g. 2 or “2”)

None

pwm.chip

alt. to pin designator: PWM chip id as int.

Impl. specific; maybe None

pwm.channel

alt. to pin designator: PWM channel number

Impl. specific; maybe None

pwm.frequency

pulse frequency in Hz; integer

DEFAULT_FREQUENCY

pwm.duty

duty cycle in percent [%]; integer

DEFAULT_DUTY

Parameters:

paramDict (dict(str, object)) – Configuration parameters as obtained from Params_init(), possibly.

Returns:

none

Return type:

None

close()[source]

Closes this instance and releases associated hardware resources.

This is the counterpart of open(). Upon return, further usage of this instance is prohibited and may lead to unexpected results. The instance can be re-activated by calling open(), again.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

static getPWM(provider=SysProvider.AUTO)[source]

Generates a PWM implementation according to the requested provider.

Parameters:

provider (SysProvider) – The low-level lib to rely on, or AUTO for automatic detection.

Returns:

A PWM implementation object, or None in case of an error.

Return type:

PWM

getState()[source]

Retrieve the state of this PWM instance.

Gives PWM.ON if this instance is up and running (started) or PWM.OFF otherwise.

Returns:

A status value [PWM.ON | PWM.OFF] and an error code indicating either success or the reason of failure.

Return type:

int, ErrorCode

open(paramDict)[source]

Opens the instance and sets it in a usable state.

Allocate necessary hardware resources and configure user-adjustable parameters to meaningful defaults. This function must be called prior to any further usage of the instance. Involving it in the system ramp-up procedure could be a good choice. After usage of this instance is finished, the application should call close().

Parameters:

paramDict (dict(str, object)) – Configuration parameters as obtained from Params_init(), possibly.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

setDuty(duty)[source]

Set the new duty cycle percentage without altering the on/off state.

Just update the duty value. If the PWM is off, it stays off and just stores the new duty cycle. When starting the PWM again, the signal will show this new duty cycle. If the PWM is running while calling this method, the new duty value will immediately affect the output signal.

A duty cycle of 0 or 100 will effectively switch the PWM off. Still, the caller should prefer using start() or stop() for this purpose, instead.

Parameters:

duty (int) – A value [0…100] giving the new duty cycle as a percentage [%].

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

setFrequency(frequency)[source]

Set the new base frequency. Does not alter the on/off state.

Just update the frequency value. If the PWM is off, it stays off and just stores the new frequency. When starting the PWM at a later point, the signal will have this new base frequency. If the PWM is running (on) while calling this method, the new frequency will immediately affect the output signal.

It’s at the discretion of the implementation whether or not special values (e.g. 0) will cause side effects, like switching the PWM off or on. The caller should not rely on this kind of side effects, but use start() or stop(), instead.

Parameters:

frequency (int) – Positive int value giving the new frequency in Hertz [Hz].

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

setRunLevel(level)[source]

Select the power-saving operation mode.

Switches the instance to one of the power-saving modes or recovers from these modes. Situation-aware deployment of these modes can greatly reduce the system’s total power consumption.

Parameters:

level (RunLevel) – The level to switch to.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

start(duty=None)[source]

Switch output of the PWM signal on.

If the status is currently OFF, the output starts immediately and the status turns to ON. If no parameter is given, the configured duty value is used. Alternatively, the new duty percentage can be specified as a parameter. If the PWM is already running (ON), the output signal is just updated. If a new duty value is given, it will apply to the relative pulse width. Otherwise, the output signal will not change.

Note that setting the duty value to zero or 100 will effectively turn the PWM off.

Parameters:

duty (int) – The new relative pulse width as a percentage in [0, 100].

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

stop()[source]

Switch output of the PWM signal off.

Immediately stops the output of the PWM signal. The configured duty value is not modified. Operation can be re-started by calling start().

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

philander.sensor module

Abstract sensor interface.

Provide an API to abstract from any type of sensors. Only a very basic set of common types and functions is provided.

class Calibration(scheme: CalibrationType = CalibrationType.default, data: CalibrationData = None)[source]

Bases: object

Container to wrap calibration scheme and data at the top level.

This structure is to be passed in calls to Sensor.calibrate(). The interpretation of the data particles depends on the scheme of the calibration as follows.

CalibrationType

CalibrationData particle

default

none

zero

none

one

none

hundred

none

trueValue

trueValue

expose1

trueValue

expose2

trueValue

expose3

trueValue

offset

offset, iOffset

shiftOffset

offset, iOffset

linear

linear, iLinear

linearRel

linear, iLinear

param

param

paramRel

param

trueMeasurement

trueMeasurement

trueMeasurement2

trueMeasurement2

knownMeasurement

knownMeasurement

knownMeasurement1

knownMeasurement

knonwMeasurement2

knownMeasurement

knonwMeasurement3

knownMeasurement

temperature

temp

data: CalibrationData = None
scheme: CalibrationType = 1
class CalibrationData(trueValue: object = None, offset: object = None, iOffset: int = 0, linear: _CalibrationData_linear = None, iLinear: _CalibrationData_iLinear = None, param: object = None, trueMeasurement: _CalibrationData_trueMeasurement = None, trueMeasurement2: _CalibrationData_trueMeasurement = None, knownMeasurement: object = None, temp: _CalibrationData_iLinear = None)[source]

Bases: object

Container type to encapsulate a calibrations pure data structure.

iLinear: _CalibrationData_iLinear = None

Either new linear calibration parameters to replace the current ones, or corrective numbers to adjust the calibration parameters in effect, both given in abstract integer units. To be used with CalibrationType.linear and CalibrationType.linearRel.

iOffset: int = 0

Either a new absolute offset, or the shift to correct the current offset, given in analogue, digitised or abstract integer units. To be used with CalibrationType.offset and CalibrationType.shiftOffset.

knownMeasurement: object = None

Up to 3 pairs of raw measure and true value to support a multi-point-calibration. The source (x)- values measure are meant as ADC ticks or milli Volts. Up to 3 inputs are supported (x,y,z or real/imaginary etc.). The target (y)- values trueValue are given in measurement units. To be used with CalibrationType.knownMeasurement, CalibrationType.knownMeasurement1, CalibrationType.calibKnownMeasurement2, CalibrationType.calibKnownMeasuremen3.

linear: _CalibrationData_linear = None

Either new linear calibration parameters to replace the current ones, or corrective numbers to adjust the calibration parameters in effect, both given in measurement units. To be used with CalibrationType.linear and CalibrationType.linearRel.

offset: object = None

Either a new absolute offset, or the shift to correct the current offset, given in measurement units. To be used with CalibrationType.offset and CalibrationType.shiftOffset.

param: object = None

Generic set of parameters, stored separately. To be used with CalibrationType.param and CalibrationType.paramRel.

temp: _CalibrationData_iLinear = None

Temperature calibration data. To be used with CalibrationType.temperature.

trueMeasurement: _CalibrationData_trueMeasurement = None

Pair of measured and true value to support a one-point-calibration. Both values are given in measurement units. Note that the values do not relate to the current exposure. To be used with CalibrationType.trueMeasurement.

trueMeasurement2: _CalibrationData_trueMeasurement = None

Two pairs of measured and true value to support a two-point- calibration. All values are given in measurement units. To be used with CalibrationType.trueMeasurement2.

trueValue: object = None

True measurement value related to the current exposure. Should be used with CalibrationType.trueValue, CalibrationType.expose1, CalibrationType.expose2 and CalibrationType.expose3.

class CalibrationType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Mnemonic type to identify a specific calibration procedure.

This is part of the information to be passed to a sensor when calling its Sensor.calibrate() method.

default = 1

Default calibration procedure. This may be a special procedure of the sensor hardware, or simply the use of hard-coded default calibration parameters. Depends on the sensor hardware and/or driver implementation.

expose1 = 6

The first point in a two- or three point calibration, depending on what the sensor implementation actually supports. The true measurement value at this point is either given implicitly or explicitly by further data of the calibration data structure. The calibration procedure cannot be finished at this time. Instead, the driver’s calibration routine should expect to be called again with one of the other calibExpose calibration types.

expose2 = 7

The second point in a two- or three point calibration, depending on what the sensor implementation actually supports. The true measurement value at this point is either given implicitly or explicitly by further data of the calibration data structure. A two-point calibration finishes at this point, while a 3-point calibration should expect to be called once more.

expose3 = 8

The last point in a three point calibration. The true measurement value at this point is either given implicitly or explicitly by further data of the calibration data structure.

hundred = 4

Single fix point hundred calibration. No further calibration data is needed. The current sensory exposure should map to exactly hundred (100) measurement units. For qualitative sensors, may also be interpreted as everything detected or 100%.

knonwMeasurement2 = 19

The same as knownMeasurement. Two data points are used.

knonwMeasurement3 = 20

The same as knownMeasurement. Three data points are used.

knownMeasurement = 17

In contrast to trueMeasurement, calibration uses one or more points (r,v) on the transfer function, where r is the analogue or digitized raw value or voltage equivalent and v is the true, resulting data. This is similar to expose3 etc. except, the primary measure is not given implicitly by the current exposure, but is provided explicitly, instead. All this data must be part of the calibration data structure. This is a generic mnemonics. The actual number of points is given implicitly / at the discretion of the implementation.

knownMeasurement1 = 18

The same as knownMeasurement. One data point is used.

linear = 11

Provides a new pair of total offset and sensitivity/skew for translating raw (analogue) values into measurement units. These parameters must be given as part of the calibration data structure.

linearRel = 12

Gives a pair of relative correctives to the current offset and skew/sensitivity. This data must be part of the calibration data structure. Note that the offset corrective must be given in either analogue, digitised or measurement units and will be added to the current offset. The sensitivity corrective is interpreted as a signed percentage. It will be added to 100% and then applied to (multiplied with) the current sensitivity. This is to allow the current sensitivity being, e.g. increased by 3% or 5% and alike.

offset = 9

Provides the new, total offset, given in either analogue, digitized or measurement units as part of the calibration data structure.

one = 3

Single fix point one calibration. No further calibration data needed. The current sensory exposure should map to exactly one (1) measurement unit. For binary sensors, may also be interpreted as something detected.

param = 13

Generic calibration type to allow for a transfer of calibration parameters. With this, the current parameters are no longer in effect, but will be replaced by the data provided in the calibration data structure.

paramRel = 14

Shift or skew the current calibration parameters by the correctives provided in the calibration data structure.

shiftOffset = 10

The current offset is corrected by the shift given in analogue, digitised or measurement units as part of the calibration data structure. The shift adds to the current offset.

temperature = 21

Re-calibrate the temperature measurement, e.g. for sensors involving temperature compensation.

trueMeasurement = 15

Provide a pair of (m,v) measured and true value to calculate necessary corrections. This is a calibration with one fix point similar to trueValue. The difference is, that the measured value is not implicitly given by the current exposure, but can be provided explicitly as part of the calibration data structure.

trueMeasurement2 = 16

Provides two pairs of (m,v) measured and true values to calculate necessary corrections. This is a two-point calibration and both points are given in the calibration data structure.

trueValue = 5

Single point calibration. The true measurement value of the current exposure must be given as part of the calibration data structure. The current sensory exposure should map to exactly the value given in the calibration data and meant as measurement units.

zero = 2

Single fix point zero calibration. No further calibration data is needed. The current sensory exposure should map to exactly zero (0) measurement units. May also be interpreted as nothing detected or 0%.

class SelfTest(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Flag

Bit mask type to designate the different types of self tests.

CONNECTION = 1

Test physical connection, possibly by reading the chip ID

FUNCTIONAL = 2

Functional test, subject to the implementation.

SELFTEST_ALL = 65535

All possible self tests.

class Sensor[source]

Bases: Module, Configurable

This class is meant to be sub-classed to define interfaces for more-specific categories of sensors.

classmethod Params_init(paramDict)[source]

Initializes parameters to their default values. Supported key names and their meanings / expected keys are:

  • Sensor.dataRange: Upper/lower limit of expected measurements. Defaults to 1.

  • Sensor.dataRate: Measurement frequency, given in Hz. Default is 1.

Also see module.Module.Params_init().

Parameters:

paramDict (dict(str, object)) – Dictionary mapping option names to their respective values.

Returns:

none

Return type:

None

calibrate(calib)[source]

Calibrates the sensor device according to the given calibration data.

Calibration may, for example, provide static offsets to adjust the measurement’s zero point or some sort of corrective coefficients to account for the sensor’s temperature drift. The exact type of calibration along with additional data that is possibly necessary, is passed in via the calib parameter. Also see: Calibration.

Parameters:

calib (Calibration) – The calibration data for that sensor.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

configure(configData)[source]

Configures the sensor device as described by the given configuration data.

Note that the type of the provided data and its interpretation will depend on the sensor implementation. Also see: Configuration.

Parameters:

configData (.sensor.Configuration) – Specific configuration information.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

getInfo()[source]

Retrieves an information block from the sensor device.

Typically, this kind of information is rather static in that, it does not change (much) over time. Usually, it further describes the sensor origin, manufacturing date, hardware/firmware revision, product/model ID, self-identifying numbers and alike. Also, the general operating mode or working conditions may be part of the info block.

For more dynamic meta-information see getStatus().

The method returns both, an instance of Info, carrying the information block as well as an error code, indicating success or failure. The info block shall be evaluated only, if the method returned successfully. Even then, the caller should still evaluate the validity attribute of the returned info block to find out, which of the information is actually valid.

Returns:

The information object and an error code indicating either success or the reason of failure.

Return type:

Info, ErrorCode

getLatestData()[source]

Retrieves the most recent data available and returns immediately.

This function will never block, but may read data that has been read before, already. More precisely, the data returned was valid / taken at a moment in the past, which is as close as possible to the current point in time, (including right NOW).

For sensors which deliver measurements continuously in time, there is no semantic difference to getNextData().

In contrast, for sensors, which provide measurements discretely at certain time intervals, this function is expected to deliver the last measurement point - without any waiting. Typically, this requires some kind of buffering. at the sensor or driver side.

The method is synchronous in that, it hands out the resulting data to the caller upon return. In fact, this method returns both, the measurement result and an error code signaling success or failure. The measurement data should be considered valid only, if the error code indicates a successful execution of this method.

The type and interpretation of the returned measurement data is specific to the individual sensor and driver implementation. The application may rely on values scaled to reasonable units, such as temperatures in degree Celsius, distances in meters and pressures in Pascal - or multiples and fractions thereof.

Also see: getNextData().

Returns:

The measurement data object and an error code indicating either success or the reason of failure.

Return type:

Object, ErrorCode

getNextData()[source]

Retrieves the next data, possibly waiting for the current measurement interval to expire.

This function may introduce a blocking wait, but always returns with fresh, new data never read before. The measurement is taken / valid either immediately or as early as possible in the future.

For sensors, that deliver data continuously in time, there is no difference to getLatestData().

For sensors that sample data at certain time intervals, this function very likely includes some waiting delay until the next measurement is due.

In either case, this function blocks until the measurement is retrieved and hands out data to the application upon return. In that sense, this is a synchronous function.

The return is twofold: the measurement result and an error code signaling success or failure. The measurement data should be considered valid only, if the error code indicates a successful execution of this method.

The type and interpretation of the returned measurement data is specific to the individual sensor and driver implementation. The application may rely on values scaled to reasonable units or multiples and fractions thereof.

Also see: getLatestData().

Returns:

The measurement data object and an error code indicating either success or the reason of failure.

Return type:

Object, ErrorCode

getStatus(statusID)[source]

Retrieves status data from the sensor device.

Typically, this kind of information is more dynamic in that, it changes (much) over time. Usually, it further describes the sensor’s current shape and condition, such as the availability of new measurement data, the cause of an interrupt or the status of certain hardware functions. Also, secondary measurements such as the die temperature could be subject to status data.

For more static meta-information see getInfo().

The given statusID parameter specifies, exactly which status information should be retrieved. Its type and interpretation depends on the sensor implementation.

The method returns both, resulting status data and an error code indicating success or failure. The status data should be considered valid only, if the error code indicates a successful execution of this method.

The type and interpretation of the status data depends on the specific sensor implementation.

Parameters:

statusID (int) – Identifies the status information to be retrieved.

Returns:

The status object and an error code indicating either success or the reason of failure.

Return type:

Object, ErrorCode

open(paramDict)[source]

Opens an instance and puts it into a usable state.

Configures the sensor by reading the supported parameters or applying default values and calling configure(). Also see: module.Module.open().

Parameters:

paramDict (dict(str, object)) – Configuration parameters as obtained from module.Module.Params_init(), possibly.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

reset()[source]

Soft resets the sensor.

Depending on the actual sensor type, configuration may get lost. So, the device is in some default state, afterwards and must be re-configured according to the application’s needs.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

selfTest(tests)[source]

Carry out a sensor self test.

The aim of such tests is to verify the integrity and well-functioning of the sensor device. The nature of these tests is solely specific to the sensor type and implementation. So, a test may be a built-in hardware test or some stress test or spot-check implemented in software or a combination of both. Depending on the underlying sensor type, a test may or may not be finished when returning from this function.

If the test finishes upon return, the test result is communicated to the application via the return value. In that case, the sensor device is assumed to be in the same or similar operating condition as before entering this method.

If, in the other case, the test is not finished before returning, the sensor is assumed to be put in test mode and further action of the application is necessary to elicit the test result. This action could, for example, include reading sample data or retrieve the information block. How to leave the self-test mode, depends on the sensor implementation. Calling this function with the same or complementing tests parameter or invoking Sensor.reset() or Sensor.configure() are just a few examples.

Parameters:

tests (int) – A bit mask to select the tests to be executed, in case several tests are available. Interpretation of this parameter is up to the specific sensor type and may include starting and stopping a certain test mode.

Returns:

An error code either indicating the test result or that starting/stopping test mode was successful or the reason why it failed.

Return type:

ErrorCode

philander.serialbus module

Serial bus convergence layer for smbus, smbus2, periphery or simulative implementation.

Provide a common API for serial bus communication (I2C / SPI). This interface is to to abstract from details of the implementation.

Basically, there are two main classes: SerialBus and SerialBusDevice. The SerialBus class unifies the implementations like smbus or periphery by providing similar communication functions, such as read/write byte, word and buffer data.

The SerialBusDevice carries specific information for a specific bus participant, such as its address. For that reason, every read or write function of the SerialBus class needs an SerialBusDevice instance as a parameter. For convenience, read and write functions are also available at the SerialBusDevice class, delegating their calls to the matching functions in SerialBus along with their self-reference.

For the sake of consistency, each SerialBusDevice must be mated with a certain SerialBus in order to work, properly. This process is called attaching a device to a bus. Several devices may be attached to the same bus. However, a single device may only attached to at most one bus. After attaching, the bus and device are double-linked to each other: The bus has a list of attached devices, while a device has a reference to the bus it is attached to.

class SerialBus[source]

Bases: Module

Convergence layer to abstract from multiple implementations of serial communication (I2C, SPI), such as smbus or periphery.

This class represents the serial bus as such, without any participating device. For communicating with a specific device, a corresponding instance of SerialBusDevice must be provided to the read/write method of interest.

A sub class must overwrite at least the methods for reading and writing a single byte and buffer.

DEFAULT_DESGINATOR = '/dev/i2c-1'
DEFAULT_I2C_SPEED = 400000
DEFAULT_SPEED = 400000
DEFAULT_SPI_BITS_PER_WORD = 8
DEFAULT_SPI_BIT_ORDER = 'MSB'
DEFAULT_SPI_MODE = 3
DEFAULT_SPI_SPEED = 1000000
DEFAULT_TYPE = 10
classmethod Params_init(paramDict)[source]

Initialize parameters with default values.

Supported key names and their meanings are:

Key

Range

Default

SerialBus.type

SerialBusType to indicate the protocol.

SerialBus.DEFAULT_TYPE.

SerialBus.designator

[string | number]: bus port, “/dev/i2c-3” or 1.

“/dev/i2c-1”.

SerialBus.speed

[int|float] maximum bus clock frequency in Hz.

SerialBus.DEFAULT_SPEED.

SerialBus.SPI.mode

SPIMode mode; only for SPI.

SerialBus.DEFAULT_SPI_MODE.

SerialBus.SPI.bitorder

[“msb”|”lsb”] bit transmission order.

SerialBus.DEFAULT_SPI_BIT_ORDER.

SerialBus.SPI.bpw

int; bits per word

SerialBus.DEFAULT_SPI_BITS_PER_WORD.

Parameters:

paramDict (dict(str, object)) – Configuration parameters as obtained from Params_init(), possibly.

Returns:

none

Return type:

None

attach(device)[source]

Attaches a device to this serial bus.

If this bus is not open, yet, then it will get opened, now. If the same device has been attached before, the method will just return successfully.

Param:

SerialBusDevice device: The device to be attached.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

close()[source]

Shut down this bus and release associated hardware resources.

If this bus has some devices attached, they get detached, before the method returns.

Also see: module.Module.close().

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

detach(device)[source]

Detach a device from this serial bus.

If this is the last device on the bus, the bus is closed, automatically.

Param:

SerialBusDevice device: The device to be detached.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

detachAll()[source]

Detaches all devices from this serial bus.

Note that this will not close the bus automatically.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

static getSerialBus(provider=SysProvider.AUTO)[source]

Generates a serial bus implementation according to the requested provider.

Parameters:

provider (SysProvider) – The low-level lib to rely on, or AUTO for automatic detection.

Returns:

A serial bus implementation object, or None in case of an error.

Return type:

SerialBus

isAnyAttached()[source]

Determines, if there is any device attached to this bus implementation.

Returns:

An error code. ErrorCode.errOk, if there is at least one device attached to this bus; ErrorCode.errUnavailable, if no device has been attached before; Any other value to indicate the failure or reason, why this information could not be retrieved.

Return type:

ErrorCode

isAttached(device)[source]

Determines, if the given device is already attached to this bus.

Also see: SerialBusDevice.isAttached().

Returns:

An error code. ErrorCode.errOk, if the device is already attached to some bus; ErrorCode.errUnavailable, if it has not been attached before; Any other value to indicate the failure or reason, why this information could not be retrieved.

Return type:

ErrorCode

isOpen()[source]

Determine, if the given bus is already open.

Returns:

ErrorCode.errOk, if the bus is already open; ErrorCode.errUnavailable, if it has not been opened before; Any other value to indicate the failure or reason, why this information could not be retrieved.

Return type:

ErrorCode

open(paramDict)[source]

Open a new serial bus and apply the given configuration.

If this instance was opened before, already, this method returns an error code. The same is true, when the same physical bus was opened before, possible using another instance.

Also see: Params_init(), module.Module.open().

Parameters:

paramDict (dict(str, object)) – Configuration parameters as obtained from Params_init(), possibly.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

readBuffer(device, length)[source]

Directly reads multiple bytes from the given device.

Also see: SerialBusDevice.readBuffer().

Parameters:
  • device (SerialBusDevice) – The device to communicate with.

  • length (int) – The number of bytes to read from the device. Should be greater than zero.

Returns:

A buffer of the indicated length holding the response and an error code indicating success or the reason of failure.

Return type:

int[], ErrorCode

readBufferRegister(device, reg, length)[source]

Multi-byte read access to a register-type serial bus device.

After sending one byte of command or register address, a number of bytes is read back and returned.

For SPI, the byte received during transmission of the reg byte is discarded. It does not appear in the response buffer. Then, enough dummy traffic is generated to receive length number of bytes.

Also see: SerialBusDevice.readBufferRegister().

Parameters:
  • device (SerialBusDevice) – The device to communicate with.

  • reg (int) – The byte to send. May be a command or register address, depending on the protocol of the addressed device.

  • length (int) – The number of bytes to read from the device. Should be greater than zero.

Returns:

A buffer of the indicated length holding the response and an error code indicating success or the reason of failure.

Return type:

int[], ErrorCode

readByteRegister(device, reg)[source]

This method provides 8 bit register read access to a device.

First, the reg byte is sent to the device. This may address the register to be read out or be some sort of command. Then, one byte is read back from the device. Depending on the device protocol semantics, this may be the register content or the command response.

Also see: SerialBusDevice.readByteRegister().

Parameters:
  • device (SerialBusDevice) – The device to communicate with.

  • reg (int) – The data to write to this device. This may be a register identification or some sort of command.

Returns:

A one-byte integer representing the response of the device and an error code indicating success or the reason of failure.

Return type:

int, ErrorCode

readDWordRegister(device, reg)[source]

Read a 32-bit word from the given register.

After the reg byte is sent, four bytes are read from the device. The 32 bit double-word is always read in little endian order, i.e. the least significant low-byte first, the highes-significant high-byte last.

Also see: SerialBusDevice.readDWordRegister().

Parameters:
  • device (SerialBusDevice) – The device to communicate with.

  • reg (int) – The register identification or command to write to this device.

Returns:

A 32-bit integer representing the response of the device and an error code indicating success or the reason of failure.

Return type:

int, ErrorCode

readWordRegister(device, reg)[source]

Provide register read access for 16 bit data words.

After a byte is sent, two bytes are read from the device. The word is always read in little endian order, i.e. the least significant low-byte first, the highes-significant high-byte second.

Also see: SerialBusDevice.readByteRegister().

Parameters:
  • device (SerialBusDevice) – The device to communicate with.

  • reg (int) – The register identification or command to write to this device.

Returns:

A 16-bit integer representing the response of the device and an error code indicating success or the reason of failure.

Return type:

int, ErrorCode

setRunLevel(level)[source]

Switch the bus into some operating or power-saving mode.

Also see: module.Module.setRunLevel().

Parameters:

level (RunLevel) – The level to switch to.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

writeBuffer(device, buffer)[source]

Writes the given data to the device specified.

The buffer is not interpreted any further but is written as such, no matter of a register information being present, or not.

Also see: SerialBusDevice.writeBuffer().

Parameters:
  • device (SerialBusDevice) – The device to communicate with.

  • buffer (int[]) – The data to store.

Returns:

An error code indicating success or the reason of failure.

Return type:

ErrorCode

writeBufferRegister(device, reg, buffer)[source]

Assuming a register-type access, this function writes a buffer to a register.

The register reg value is written first, followed by the given buffer content.

Also see: SerialBusDevice.writeBufferRegister().

Parameters:
  • device (SerialBusDevice) – The device to communicate with.

  • reg (int) – The register number. This addresses the place where to put the content. Depending on the device, this could also be some kind of command.

  • buffer (int) – The data to store to the given register.

Returns:

An error code indicating success or the reason of failure.

Return type:

ErrorCode

writeByteRegister(device, reg, data8)[source]

Assuming a register-type access, this function writes a byte register.

The register value is written first, followed by the given data parameter.

Also see: SerialBusDevice.writeByteRegister().

Parameters:
  • device (SerialBusDevice) – The device to communicate with.

  • reg (int) – The register number. This addresses the place where to put the content. Depending on the device, this could also be some kind of command.

  • data8 (int) – The data to write to the addressed register.

Returns:

An error code indicating success or the reason of failure.

Return type:

ErrorCode

writeDWordRegister(device, reg, data32)[source]

Write a 32 bit double-word to the given register.

The register reg value is written first, followed by the given data32 parameter in little-endian order.

Also see: SerialBusDevice.writeDWordRegister().

Parameters:
  • device (SerialBusDevice) – The device to communicate with.

  • reg (int) – The register number. This addresses the place where to put the content. Depending on the device, this could also be some kind of command.

  • data32 (int) – The dword to store to the given register.

Returns:

An error code indicating success or the reason of failure.

Return type:

ErrorCode

writeReadBuffer(device, outBuffer, inLength)[source]

Writes and reads a number of bytes simultaneously, if possible.

The output buffer is written. The last inLength number of bytes of the resulting input buffer are returned. E.g. inLength=2 will the method make return the last two bytes (one word) of the buffer retrieved while/after writing the given outBuffer.

If data can be read simultaneously while writing (SPI), that input is considered. Again, inLength is counted from the end of the buffer. If that number is larger the given outBuffer``´s length, dummy bytes are written, accordingly. So, the total traffic caused in this case is ``max( len(outBuffer), inLength ) bytes.

If reading simultaneously is impossible (I2C), the given number of bytes are read by a separate message. The total traffic caused in this case is len(outBuffer) + inLength bytes.

Also see: SerialBusDevice.writeReadBuffer().

Parameters:
  • device (SerialBusDevice) – The device to communicate with.

  • inLength (int) – The number of bytes to read from the device. Should be greater than zero.

  • outBuffer (int[]) – The data to write to the device.

Returns:

A buffer of the indicated length holding the response and an error code indicating success or the reason of failure.

Return type:

int[], ErrorCode

writeWordRegister(device, reg, data16)[source]

Assuming a register-type access, this function writes a word register.

The register reg value is written first, followed by the given data16 parameter in little-endian order.

Also see: SerialBusDevice.writeWordRegister().

Parameters:
  • device (SerialBusDevice) – The device to communicate with.

  • reg (int) – The register number. This addresses the place where to put the content. Depending on the device, this could also be some kind of command.

  • data16 (int) – The word to store to the given register.

Returns:

An error code indicating success or the reason of failure.

Return type:

ErrorCode

class SerialBusDevice[source]

Bases: Module

Reflect a specific device communicating over a serial bus.

As its main information, an instance of SerialBusDevice is to hold specific information of that single device, such as its unique bus address. This class is meant to be sub-classed by implementations for real devices.

Before using a device for communication, it must be attached to a bus by calling SerialBus.attach(). However, a device’s isAttached() function may be used to check, whether it has been attached to a bus, already.

DEFAULT_ADDRESS = 33
classmethod Params_init(paramDict)[source]

Initialize the set of configuration parameters with supported options. Supported configuration key names and their meanings are:

Key

Range, meaning and default

SerialBusDevice.address

int; I2C address of the device; DEFAULT_ADDRESS

SerialBusDevice.CS.gpio.*

SPI chip select pin configuration; See GPIO.Params_init().

Also see module.Module.Params_init().

Parameters:

paramDict (dict(str, object)) – Dictionary mapping option names to their respective values.

Returns:

none

Return type:

None

close()[source]

Shut down this instance and release associated hardware resources.

If this instance is attached to some bus, it gets detached, before the method returns.

Also see: module.Module.close().

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

isAttached()[source]

Determines, if this instance is attached to some bus.

Also see: SerialBus.isAttached().

Returns:

An error code. ErrorCode.errOk, if the device is already attached to some bus; ErrorCode.errUnavailable, if it has not been attached before; Any other value to indicate the failure or reason, why this information could not be retrieved.

Return type:

ErrorCode

open(paramDict)[source]

Opens this serial device and puts it into a usable state.

If this device has been attached to some bus, already, this method returns an error code. Otherwise, it tries to do this attachment as follows:

  • If the paramDict configuration parameters contain the SerialBusDevice.bus key, the associated value object is checked to be an instance of SerialBus. If successful, this device is attached to that bus. Otherwise, an error code is returned.

  • If no bus instance is passed in, one is created and opened using the same paramDict dictionary of options. If successful, this device gets attached to that new bus. Upon return, the caller might retrieve a reference to the new bus from the parameter dictionary entry with key SerialBusDevice.bus, or by reading the SerialBusDevice.serialBus attribute.

Also see: module.Module.open().

Parameters:

paramDict (dict(str, object)) – Configuration parameters as obtained from Params_init(), possibly.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

readBuffer(length)[source]

Directly reads multiple bytes from the given device.

The call is delegated to the corresponding method at the bus that this device is attached to.

Differently from readBufferRegister(), this method does not write any register information beforehand, but just starts reading.

Also see: SerialBus.readBuffer(), readBufferRegister().

Parameters:

length (int) – The number of bytes to read from the device. Should be greater than zero.

Returns:

A buffer of the indicated length holding the response and an error code indicating success or the reason of failure.

Return type:

int[], ErrorCode

readBufferRegister(reg, length)[source]

Multi-byte read access to a register-type serial bus device.

The call is delegated to the corresponding method at the bus that this device is attached to.

After sending one byte of command or register address, a number of bytes is read back and returned.

For SPI, the byte received during transmission of the reg byte is discarded. It does not appear in the response buffer. Then, enough dummy traffic is generated to receive length number of bytes.

Also see: SerialBus.readBufferRegister().

Parameters:
  • reg (int) – The byte to send. May be a command or register address, depending on the protocol of the addressed device.

  • length (int) – The number of bytes to read from the device. Should be greater than zero.

Returns:

A buffer of the indicated length holding the response and an error code indicating success or the reason of failure.

Return type:

int[], ErrorCode

readByteRegister(reg)[source]

This method provides 8 bit register read access to a device.

The call is delegated to the corresponding method at the bus that this device is attached to.

Also see: SerialBus.readByteRegister().

Parameters:

reg (int) – The data to write to this device. This may be a register identification or some sort of command.

Returns:

A one-byte integer representing the response of the device and an error code indicating success or the reason of failure.

Return type:

int, ErrorCode

readDWordRegister(reg)[source]

Provide register read access for 32 bit data words.

The call is delegated to the corresponding method at the bus that this device is attached to. After a byte is sent, four bytes are read from the device in little endian order.

Also see: SerialBus.readDWordRegister().

Parameters:

reg (int) – The register identification or command to write to this device.

Returns:

A 32-bit integer representing the response of the device and an error code indicating success or the reason of failure.

Return type:

int, ErrorCode

readWordRegister(reg)[source]

Provide register read access for 16 bit data words.

The call is delegated to the corresponding method at the bus that this device is attached to. After a byte is sent, two bytes are read from the device in little endian order.

Also see: SerialBus.readWordRegister().

Parameters:

reg (int) – The register identification or command to write to this device.

Returns:

A 16-bit integer representing the response of the device and an error code indicating success or the reason of failure.

Return type:

int, ErrorCode

writeBuffer(buffer)[source]

Writes the given data to the device specified.

The call is delegated to the corresponding method at the bus that this device is attached to. The buffer is not interpreted any further but is written as such, no matter of a register information being present, or not. In SPI mode, the data received during transmission, is discarded.

Also see: SerialBus.writeBuffer(), writeBufferRegister().

Parameters:

buffer (int[]) – The data to store.

Returns:

An error code indicating success or the reason of failure.

Return type:

ErrorCode

writeBufferRegister(reg, buffer)[source]

Assuming a register-type access, this function writes a buffer to a register.

The call is delegated to the corresponding method at the bus that this device is attached to. The register reg value is written first, followed by the given buffer content.

Also see: SerialBus.writeBufferRegister().

Parameters:
  • reg (int) – The register number. This addresses the place where to put the content. Depending on the device, this could also be some kind of command.

  • buffer (int[]) – The data to store to the given register.

Returns:

An error code indicating success or the reason of failure.

Return type:

ErrorCode

writeByteRegister(reg, data8)[source]

Assuming a register-type access, this function writes a byte register.

The call is delegated to the corresponding method at the bus that this device is attached to. The register value is written first, followed by the given data parameter.

Also see: SerialBus.writeByteRegister().

Parameters:
  • reg (int) – The register number. This addresses the place where to put the content. Depending on the device, this could also be some kind of command.

  • data8 (int) – The data to write to the addressed register.

Returns:

An error code indicating success or the reason of failure.

Return type:

ErrorCode

writeDWordRegister(reg, data32)[source]

Assuming a register-type access, this function writes a dword register.

The call is delegated to the corresponding method at the bus that this device is attached to. The register reg value is written first, followed by the given data32 parameter in little-endian order.

Also see: SerialBus.writeDWordRegister().

Parameters:
  • reg (int) – The register number. This addresses the place where to put the content. Depending on the device, this could also be some kind of command.

  • data32 (int) – The double-word to store to the given register.

Returns:

An error code indicating success or the reason of failure.

Return type:

ErrorCode

writeReadBuffer(outBuffer, inLength)[source]

Writes and reads a number of bytes.

The call is delegated to the corresponding method at the bus that this device is attached to.

Also see: SerialBus.writeReadBuffer().

Parameters:
  • outBuffer (int[]) – The data to write to the device.

  • inLength (int) – The number of bytes to read from the device. Should be greater than zero.

Returns:

A buffer of the indicated length holding the response and an error code indicating success or the reason of failure.

Return type:

int[], ErrorCode

writeWordRegister(reg, data16)[source]

Assuming a register-type access, this function writes a word register.

The call is delegated to the corresponding method at the bus that this device is attached to. The register reg value is written first, followed by the given data16 parameter in little-endian order.

Also see: SerialBus.writeWordRegister().

Parameters:
  • reg (int) – The register number. This addresses the place where to put the content. Depending on the device, this could also be some kind of command.

  • data16 (int) – The word to store to the given register.

Returns:

An error code indicating success or the reason of failure.

Return type:

ErrorCode

class SerialBusType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

I2C = 10
SPI = 20
UART = 30

philander.simBMA456 module

Simulation of the BMA456 accelerometer device.

This module provides a pure software implementation of the device to virtualize its serial communication behavior. This is to support cross-platform development and debugging.

class SimDevBMA456[source]

Bases: SimDevMemory

A software simulation of the BMA456. The current implementation is incomplete and imperfect to some extent. The status is as follows.

Working

  • simulation of its bare existence by responding properly in serial communication

  • all registers are present, accessible and constructed with correct reset values.

  • register CHIP_ID

  • STATUS:DRDY_ACC/AUX cleared at each read-access to ACC_X/Y/Z or AUX_X/Y/Z/R

Limitations

  • ACC_X/Y/Z get just incremented after each read access.

  • STATUS:DRDY_ACC/AUX get set after polling (reading) STATUS for 10 times.

  • SENSOR_TIME[0:1:2] incremented after each read-access

  • initialization sequence is satisfied by writing LOAD_CFG_FILE followed by START_INIT to the INIT_CTRL register. This will set INTERNAL_STATUS:MSG to INIT_OK. Otherwise, these bits are set to INIT_ERR.

Missing

  • Simulation of acceleration flow, e.g. as read from an input file

  • Feature simulation (step counter etc.)

  • Simulation of the chip status and behavior, such as ERROR and STATUS

  • power modes

  • interrupts

  • NVM

readBufferRegister(aReg, length)[source]

Read a block of data starting from the given register.

Do not auto-increment destination address when reading from BMA456_REG_FEATURES.

Parameters:
  • aReg (int) – The address of the first register to be read.

  • length (int) – The number of bytes to read.

Returns:

A buffer of the indicated length holding the response and an error code indicating success or the reason of failure.

Return type:

list(int), ErrorCode

writeBufferRegister(aReg, data)[source]

Write a block of byte data into registers.

Do not auto-increment destination address when writing to BMA456_REG_FEATURES.

Parameters:
  • aReg (int) – The address of the first register to receive the block of data.

  • data (list) – List of bytes to be written. The length of the list determines the number of bytes to write. So, all values in the list will be transferred to the device.

Returns:

An error code indicating success or the reason of failure.

Return type:

ErrorCode

philander.simdev module

Serial device simulation module to support debugging and cross-platform development.

This module provides a fake serial device implementation to virtualize serial communication.

class MemoryType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration to reflect the different types of memory.

NVM = 3
RAM = 2
ROM = 1
VOLATILE = 4
class Register(address: int = 0, content: int = 0, type: MemoryType = MemoryType.RAM)[source]

Bases: object

Simulate a memory-based register.

Depending on the type of memory, the register content can or cannot be changed by simply writing to it. Volatile registers are not writable. They may change their content spontaneously or by mechanisms that cannot be controlled by the user.

address: int = 0

The address to identify this register during read/write operations.

content: int = 0

The register content. Can be initialized, independently of the memory type of that register.

type: MemoryType = 2

The type of memory for that register.

class SimDev[source]

Bases: object

Abstract base class to define the functionality of a simulated serial device.

A sub class must overwrite at least the methods for reading and writing a single byte. Implementation should use as least as possible dependencies to other modules. Use of hardware-dependent drivers must be completely avoided!

Objects of this type (and its derivatives) shall be stored as the sim attribute of a matching serialbus.SerialDevice object. Remember that each serialbus.SerialDevice must be registered with a serialbus.SerialBus by calling its serialbus.SerialBus.attach() method. The simulative serial bus implementation uses the serialbus.SerialDevice.address attribute to identify the addressed device and then looks up its SerialBusDevice.sim attribute to retrieve the serial simulation for that device.

For that reason, implementations do not have to care about the address of the device - it’s always the right one.

readBufferRegister(aReg, length)[source]

Read a block of data starting from the given register.

Starting with the given Register address, length bytes are read and returned. As with readWordRegister() and readDWordRegister(), this implementation assumes an auto-increment behavior of the target register. So, the returned data buffer is read as follows:

data[0] -> aReg data[1] -> aReg + 1 …

If this doesn’t match the actual chip behavior, a sub-class should overwrite this method.

Parameters:
  • aReg (int) – The address of the first register to be read.

  • length (int) – The number of bytes to read.

Returns:

A buffer of the indicated length holding the response and an error code indicating success or the reason of failure.

Return type:

list(int), ErrorCode

readByteRegister(aReg)[source]

Read a single byte from a certain register. A sub-class must overwrite this method.

The method is expected to deliver a register’s content to the caller.

Parameters:

aReg (int) – The address of the register to be read.

Returns:

A one-byte integer representing the response of the device and an error code indicating success or the reason of failure.

Return type:

int, ErrorCode

readDWordRegister(aReg)[source]

Read a double word from a certain register.

The dword is formed in little-endian order from the content of the four registers, starting with the given address aReg (low-byte of the low-word) and its successors aReg+1 (high-byte of the low-word), aReg+2 (low-byte of the high-word) and aReg+3 (high-byte of the high-word).

Parameters:

aReg (int) – The address of the first (lowest-byte) register to be read.

Returns:

A 32-bit integer representing the response of the device and an error code indicating success or the reason of failure.

Return type:

int, ErrorCode

readWordRegister(aReg)[source]

Read a word from a certain register.

The word is formed in little-endian order from the content of the given register (low) and the content of the immediate successor aReg+1 of that register (high).

Parameters:

aReg (int) – The address of the low-byte register to be read.

Returns:

A 16-bit integer representing the response of the device and an error code indicating success or the reason of failure.

Return type:

int, ErrorCode

writeBufferRegister(aReg, data)[source]

Write a block of byte data into registers.

As with readBufferRegister() an auto-increment applies for the target register. The first byte - at index zero - is stored at the given register aReg, the next byte - at index 1 - is stored at aReg+1 and so on. More formally:

data[0] -> aReg
data[1] -> aReg + 1
...

The number of bytes written is determined implicitly by the length of the data list. If the auto-increment feature doesn’t match the actual chip, a sub-class should overwrite this method.

Parameters:
  • aReg (int) – The address of the first register to receive the block of data.

  • data (list) – List of bytes to be written. The length of the list determines the number of bytes to write. So, all values in the list will be transferred to the device.

Returns:

An error code indicating success or the reason of failure.

Return type:

ErrorCode

writeByteRegister(aReg, data)[source]

Write a single byte value into a certain register. A sub-class must overwrite this method.

The method is expected to store the given value to a register.

Parameters:
  • aReg (int) – The address of the register to receive the new value.

  • data (int) – The new value to store to that register.

Returns:

An error code indicating success or the reason of failure.

Return type:

ErrorCode

writeDWordRegister(aReg, data32)[source]

Write a double-word (four bytes) value into a certain register.

The method is expected to store the given value to a quadruple of registers in little-endian order. The low-byte of the low word is stored at the given register aReg. The high-byte of the low-word goes to aReg+1. The low-part of the high-word is stored to aReg+2 and the high-part of the high-word is put at aReg+3.

Parameters:
  • aReg (int) – The address of the first (lowest byte) register to receive part of the new value.

  • data32 (int) – The new value to store to that quadruple of registers.

Returns:

An error code indicating success or the reason of failure.

Return type:

ErrorCode

writeWordRegister(aReg, data16)[source]

Write a double-byte (word) value into a certain register.

The method is expected to store the given value to a register or pair of registers in little-endian order. The low-part of the data16 item is stored at the given register, while the high-part is put at aReg+1.

Parameters:
  • aReg (int) – The address of the register to receive the low-part of the new value.

  • data16 (int) – The new value to store to that (pair of) registers.

Returns:

An error code indicating success or the reason of failure.

Return type:

ErrorCode

class SimDevMemory(regs)[source]

Bases: SimDev

Abstract base class for the simulation of memory-based register devices.

Pretend a device that can be accessed through a set of memory-based registers. Implementations must provide the list of registers during instantiation.

readByteRegister(aReg)[source]

Retrieves a register’s content. To also simulate side effects of reading, the following steps are executed in sequence, no matter what the memory type of the given register is:

  1. calling _onPreRead()

  2. reading the register content

  3. calling _onPostRead()

Note that the return value is solely determined by what is read from the register in step #2. It cannot be altered by _onPostRead(), anymore.

Also see simbus.SimDev.readByteRegister().

Parameters:

aReg (int) – The address of the register to be read.

Returns:

A one-byte integer representing the response of the device and an error code indicating success or the reason of failure.

Return type:

int, ErrorCode

writeByteRegister(aReg, data)[source]

Write a single byte value into a certain register.

Write attempts to registers with non-writable memory are ignored. For registers with writable memory, the following sequence is executed in order to give sub-classes the opportunity to simulate side effects:

  1. calling _onPreWrite(), may alter the intended data and returns the actual new content to write.

  2. writing the new register content

  3. calling _onPostWrite()

Parameters:
  • aReg (int) – The address of the register to receive the new value.

  • data (int) – The new value to store to that register.

Returns:

An error code indicating success or the reason of failure.

Return type:

ErrorCode

class SimDevNull(reading=58)[source]

Bases: SimDev

Slim-line serial device simulation. Reading retrieves always the same constant value, while writing is simply ignored.

DEFAULT_READING = 58
readByteRegister(aReg)[source]

Read a single byte.

Independent of the given register, the delivered value will always be the same. That delivered reading can be configured using the SimDevNull.reading option when calling open().

Parameters:

aReg (int) – The address of the register to be read. Actually ignored.

Returns:

A one-byte integer representing the response of the device and an error code indicating success or the reason of failure.

Return type:

int, ErrorCode

writeByteRegister(aReg, data)[source]

Write a single byte.

Actually, does nothing. Also see SimDev.writeByteRegister().

Parameters:
  • aReg (int) – The address of the register. Ignored.

  • data (int) – The new value to store to that register. Ignored.

Returns:

An error code indicating success or the reason of failure.

Return type:

ErrorCode

philander.stadc1283 module

ADC implementation for the ADC1283 A/D converter chip by ST micro.

More information on this chip can be found at https://www.st.com/en/data-converters/adc1283.html

philander.stc3115 module

A module to provide base classes and data types for gas gauge driver implementations.

class STC3115[source]

Bases: STC311x

Driver implementation for the stc3115 gas gauge.

Info about this chip can be found at ST microelectronics https://www.st.com/en/power-management/stc3115.html

MODEL_ID = 3115

philander.stc3115_reg module

Register definitions for the STC311x family battery gas gauges.

Definition of registers and default values for the above-mentioned chips. Externalized, just for clarity of the source code.

class STC3115_Reg[source]

Bases: STC311x_Reg

Definition of the STC3115 exclusive registers and values.

Registers and content interpretation specific to this chip. It complements those definitions inherited from the base class.

CHIP_ID = 20
MODE_CLR_CC_ADJ = 4
MODE_CLR_VM_ADJ = 2
OCV_DEFAULT = 0
REG_ACC_CC_ADJ = 27
REG_ACC_CC_ADJ_H = 28
REG_ACC_CC_ADJ_L = 27
REG_ACC_VM_ADJ = 29
REG_ACC_VM_ADJ_H = 30
REG_ACC_VM_ADJ_L = 29
REG_CC_ADJ_H = 11
REG_CC_ADJ_L = 25
REG_OCVTAB0 = 48
REG_OCVTAB1 = 49
REG_OCVTAB10 = 58
REG_OCVTAB11 = 59
REG_OCVTAB12 = 60
REG_OCVTAB13 = 61
REG_OCVTAB14 = 62
REG_OCVTAB15 = 63
REG_OCVTAB2 = 50
REG_OCVTAB3 = 51
REG_OCVTAB4 = 52
REG_OCVTAB5 = 53
REG_OCVTAB6 = 54
REG_OCVTAB7 = 55
REG_OCVTAB8 = 56
REG_OCVTAB9 = 57
REG_RELAX_COUNT = 22
REG_RELAX_MAX = 23
REG_VM_ADJ_H = 12
REG_VM_ADJ_L = 26
RELAX_MAX_DEFAULT = 120

philander.stc3117 module

A module to provide base classes and data types for gas gauge driver implementations.

class STC3117[source]

Bases: STC311x

Driver implementation for the stc3117 gas gauge.

Info about this chip can be found at ST microelectronics https://www.st.com/en/power-management/stc3117.html

MODEL_ID = 3117
getBatteryCurrentAvg()[source]

Retrieves the average battery current.

The average is taken over some time interval, e.g. 2 seconds. The length of the time window is at the discretion of the implementation and cannot be adjusted by the caller.

See also: getBatteryCurrent()

Returns:

A non-negative integer value [micro A] or Current.invalid to indicate that this information could not be retrieved.

Return type:

Current

getChangeRate()[source]

Retrieves the SOC change rate in milli C.

Remember that 1C = 100% in 1 hour. This information may be used to estimate the remaining stamina or how long the charging process will still take. :return: A SOC change rate (non-negative) or :attr:’SOCChangeRate.invalid` to indicate that this information could not be retrieved. :rtype: SOCChangeRate

philander.stc3117_reg module

Register definitions for the STC311x family battery gas gauges.

Definition of registers and default values for the above-mentioned chips. Externalized, just for clarity of the source code.

class STC3117_Reg[source]

Bases: STC311x_Reg

Definition of the STC3115 exclusive registers and values.

Registers and content interpretation specific to this chip. It complements those definitions inherited from the base class.

CHIP_ID = 22
CMONIT_MAX_DEFAULT = 120
CTRL_UVLOD = 128
MODE_BATD_PU = 2
MODE_DEFAULT = 11
MODE_FORCE_CD = 4
MODE_OFF = 2
OCV0_DEFAULT = 6000
OCV10_DEFAULT = 7024
OCV11_DEFAULT = 7089
OCV12_DEFAULT = 7144
OCV13_DEFAULT = 7256
OCV14_DEFAULT = 7411
OCV15_DEFAULT = 7593
OCV1_DEFAULT = 6438
OCV2_DEFAULT = 6578
OCV3_DEFAULT = 6651
OCV4_DEFAULT = 6718
OCV5_DEFAULT = 6765
OCV6_DEFAULT = 6813
OCV7_DEFAULT = 6838
OCV8_DEFAULT = 6869
OCV9_DEFAULT = 6913
REG_AVG_CURRENT = 11
REG_AVG_CURRENT_H = 12
REG_AVG_CURRENT_L = 11
REG_CC_ADJ = 27
REG_CC_ADJ_H = 28
REG_CC_ADJ_L = 27
REG_CMONIT_COUNT = 22
REG_CMONIT_MAX = 23
REG_OCVTAB0 = 48
REG_OCVTAB0_H = 49
REG_OCVTAB0_L = 48
REG_OCVTAB1 = 50
REG_OCVTAB10 = 68
REG_OCVTAB10_H = 69
REG_OCVTAB10_L = 68
REG_OCVTAB11 = 70
REG_OCVTAB11_H = 71
REG_OCVTAB11_L = 70
REG_OCVTAB12 = 72
REG_OCVTAB12_H = 73
REG_OCVTAB12_L = 72
REG_OCVTAB13 = 74
REG_OCVTAB13_H = 75
REG_OCVTAB13_L = 74
REG_OCVTAB14 = 76
REG_OCVTAB14_H = 77
REG_OCVTAB14_L = 76
REG_OCVTAB15 = 78
REG_OCVTAB15_H = 79
REG_OCVTAB15_L = 78
REG_OCVTAB1_H = 51
REG_OCVTAB1_L = 50
REG_OCVTAB2 = 52
REG_OCVTAB2_H = 53
REG_OCVTAB2_L = 52
REG_OCVTAB3 = 54
REG_OCVTAB3_H = 55
REG_OCVTAB3_L = 54
REG_OCVTAB4 = 56
REG_OCVTAB4_H = 57
REG_OCVTAB4_L = 56
REG_OCVTAB5 = 58
REG_OCVTAB5_H = 59
REG_OCVTAB5_L = 58
REG_OCVTAB6 = 60
REG_OCVTAB6_H = 61
REG_OCVTAB6_L = 60
REG_OCVTAB7 = 62
REG_OCVTAB7_H = 63
REG_OCVTAB7_L = 62
REG_OCVTAB8 = 64
REG_OCVTAB8_H = 65
REG_OCVTAB8_L = 64
REG_OCVTAB9 = 66
REG_OCVTAB9_H = 67
REG_OCVTAB9_L = 66
REG_SOCTAB0 = 80
REG_SOCTAB1 = 81
REG_SOCTAB10 = 90
REG_SOCTAB11 = 91
REG_SOCTAB12 = 92
REG_SOCTAB13 = 93
REG_SOCTAB14 = 94
REG_SOCTAB15 = 95
REG_SOCTAB2 = 82
REG_SOCTAB3 = 83
REG_SOCTAB4 = 84
REG_SOCTAB5 = 85
REG_SOCTAB6 = 86
REG_SOCTAB7 = 87
REG_SOCTAB8 = 88
REG_SOCTAB9 = 89
REG_VM_ADJ = 29
REG_VM_ADJ_H = 30
REG_VM_ADJ_L = 29
SOC0_DEFAULT = 0
SOC10_DEFAULT = 123
SOC11_DEFAULT = 130
SOC12_DEFAULT = 140
SOC13_DEFAULT = 160
SOC14_DEFAULT = 180
SOC15_DEFAULT = 200
SOC1_DEFAULT = 6
SOC2_DEFAULT = 12
SOC3_DEFAULT = 20
SOC4_DEFAULT = 30
SOC5_DEFAULT = 40
SOC6_DEFAULT = 50
SOC7_DEFAULT = 60
SOC8_DEFAULT = 80
SOC9_DEFAULT = 100

philander.stc311x module

A module to provide base classes and data types for ST gas gauge driver implementations.

class OperatingMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

opModeMixed = 4
opModeStandby = 2
opModeUnknown = 1
opModeVoltage = 3
class STC311x[source]

Bases: GasGauge, SerialBusDevice, Interruptable

Base implementation for the stc311x gas gauge chip family.

A gas gauge allows to keep track of the state of charge (SOC), remaining capacity, current voltage etc. of a battery. Info about the specific gas gauge ICs can be found at https://www.st.com/en/power-management/stc3115.html or https://www.st.com/en/power-management/stc3117.html

ADDRESSES_ALLOWED = [112]
ALARM_SOC_DEFAULT = 1
ALARM_VOLTAGE_DEFAULT = 3000
BAT_CAPACITY_DEFAULT = 800
BAT_IMPEDANCE_DEFAULT = 200
MODEL_ID = None
POR_TIMEOUT = 3
classmethod Params_init(paramDict)[source]

Initializes configuration parameters with defaults.

The following settings are supported:

Key name

Value type, meaning and default

SerialBusDevice.address

int I2C serial device address; default is ADDRESSES_ALLOWED [0].

Gasgauge.SenseResistor

int Current sense resistor Rs in mOhm [5…50]; default is RSENSE_DEFAULT

Gasgauge.battery.capacity

int Battery capacity in mAh; default is BAT_CAPACITY_DEFAULT

Gasgauge.battery.impedance

int Battery impedance in mOhm; default is BAT_IMPEDANCE_DEFAULT

Gasgauge.alarm.soc

int SOC alarm threshold [%]; default is ALARM_SOC_DEFAULT

Gasgauge.alarm.voltage

int Voltage alarm threshold [mV]; default is ALARM_VOLTAGE_DEFAULT

Gasgauge.relax.current

int Current monitoring threshold [uA]; default is RELAX_CURRENT_DEFAULT

Gasgauge.relax.timer

int Current monitoring timer count [s]; default is RELAX_TIMER_DEFAULT

Gasgauge.int.gpio.* ALM pin configuration; See GPIO.Params_init().

Also see: Gasgauge.Params_init(), SerialBusDevice.Params_init(), GPIO.Params_init().

RELAX_CURRENT_DEFAULT = 5000
RELAX_TIMER_DEFAULT = 480
RSENSE_DEFAULT = 10
close()[source]

Shut down the device after usage.

This method should be called when the device is not used, anymore, e.g. as part of the application exit procedure. The following steps are executed:

  • close I2C-Bus connection

  • close GPIO pin for interrupts

After return, the device can still be re-used, by calling open() again.

Also see: GPIO.close(), Module.close().

disableInterrupt()[source]

Disables the interrupt(s) of the implementing device.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

enableInterrupt()[source]

Enables the interrupt(s) of the implementing device.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

getBatteryCurrent()[source]

Retrieves the battery current in micro Ampere at the time this function is executed.

See also: getBatteryCurrentAvg()

Returns:

A non-negative integer value [micro A] or Current.invalid to indicate that this information could not be retrieved.

Return type:

Current

getBatteryVoltage()[source]

Retrieves the battery voltage in milli Volt.

Returns:

A on-negative integer value [mV] or Voltage.invalid to indicate that this information could not be retrieved.

Return type:

Voltage

getInfo()[source]

Retrieves an information block from the gas gauge device.

Typically, this kind of information is rather static in that, it does not change over time. Usually, this information is somewhat unique for the charger origin, manufacturing date, hardware/firmware revision, product/model ID, chip series and alike. For that reason, this function can be used to see, if communication works reliably.

For more dynamic meta-information see getStatus().

The method returns both, an instance of Info, carrying the information block as well as an error code, indicating success or failure. The info block shall be evaluated only, if the method returned successfully. Even then, the caller should still evaluate the validity attribute of the returned info block to find out, which of the information is actually valid.

Returns:

The information object and an error code indicating either success or the reason of failure.

Return type:

Info, ErrorCode

getStateOfCharge()[source]

Retrieves the state of charge.

That is the fraction of electric energy from the total capacity, that is still or already stored in the battery. This information is valid for both, the charging as well as the discharging process.

Returns:

A percentage [0…100] value or Percentage.invalid to indicate that this information could not be retrieved.

Return type:

Percentage

getStatus(statusID)[source]

Retrieves status data from the device.

Typically, this kind of information is more dynamic in that, it changes (much) over time. Usually, it further describes the IC’s current shape and condition, such as the availability of new data, the cause of an interrupt or the status of certain hardware functions. Also, secondary measurements such as the die temperature could be subject to status data.

For more static meta-information see getInfo().

The given statusID parameter specifies, exactly which status information should be retrieved. Its type and interpretation depends on the implementation.

The method returns both, resulting status data and an error code indicating success or failure. The status data should be considered valid only, if the error code indicates a successful execution of this method.

The type and interpretation of the status data depends on the specific implementation.

Parameters:

statusID (int) – Identifies the status information to be retrieved.

Returns:

The status object and an error code indicating either success or the reason of failure.

Return type:

Object, ErrorCode

open(paramDict)[source]

Opens the instance and sets it in a usable state.

Allocate necessary hardware resources and configure user-adjustable parameters to meaningful defaults. In this case the registers for the specific chip are defined and optionally the GPIO-Pin for interrupts is initialized. This function must be called prior to any further usage of the instance. Involving it in the system ramp-up procedure could be a good choice. After usage of this instance is finished, the application should call close().

Parameters:

paramDict (paramDict(str, object)) – Configuration parameters as obtained from Params_init(), possibly.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

registerInterruptHandler(onEvent='EventInt1', callerFeedBack=None, handler=None)[source]

Registers a handling routine for interrupt notification.

The caller feedback will be directly passed to the handling routine. In case that multiple different interrupts are handled by the same routine, this parameter may be used to distinguish them and remember the source of interrupt.

The handler should be a method or function that expects at least one argument. That first argument will be the callerFeedBack object given as the above-mentioned parameter. Further parameters may follow, as they were handed in to the _fire() method. The handler’s signature should look like this:

def handlingRoutine( feedback, *args) -> None:

Note that the onEvent parameter is not passed to the handler. It is eaten up by _fire() and just controls the selection of the handling routine called.

Depending on the parameter, this method behaves as follows:

onEvent

handler

semantics and action

Event.evtNone

None

All interrupts are disabled and all registrations cleared.

Event.evtNone

valid

De-register the given handler from all events {Event.evtInt1|2|Any}.

Event.evtInt1|2|*

None

De-register all handlers from the given event.

Event.evtInt1|2|*

valid

Enable interrupt and register this handler for the given event.

Event.evtAny

None

Clear the Event.evtAny registrations, only!

Event.evtAny

valid

Register the handler for any event {Event.evtInt1|2}.

For this method, Event.evtNone is a semantic equivalent to None.

Parameters:
  • onEvent (int) – Exactly one of the event mnemonics defined by the interruptable.Event enumeration.

  • callerFeedBack (object) – Arbitrary object not evaluated here, but passed on to the handler when an event is fired.

  • handler – The handling routine to be called as an immediate response to an event.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

reset()[source]

Soft resets the device.

The device is in some default state, afterwards and must be re-configured according to the application’s needs. :return: An error code indicating either success or the reason of failure. :rtype: ErrorCode

setRunLevel(level)[source]

Select the power-saving operation mode.

Switches the instance to one of the power-saving modes or recovers from these modes. Situation-aware deployment of these modes can greatly reduce the system’s total power consumption.

Parameters:

level (RunLevel) – The level to switch to.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

philander.stc311x_reg module

Register definitions for the STC311x family battery gas gauges.

Definition of registers and default values for the above-mentioned chips. Externalized, just for clarity of the source code.

class STC311x_Reg[source]

Bases: object

Definition of common registers and values.

Base class to define register addresses and content values common to all members of the chip family.

CC_CNF_DEFAULT = 395
CHIP_ID = None
CTRL_ALM_SOC = 32
CTRL_ALM_VOLT = 64
CTRL_BATFAIL = 8
CTRL_DEFAULT = 1
CTRL_GG_RST = 2
CTRL_GG_VM = 4
CTRL_IO0DATA = 1
CTRL_PORDET = 16
IDX_RAM_CC_CNF = 3
IDX_RAM_CC_CNF_H = 4
IDX_RAM_CC_CNF_L = 3
IDX_RAM_CRC = 15
IDX_RAM_SOC = 1
IDX_RAM_SOC_H = 2
IDX_RAM_SOC_L = 1
IDX_RAM_TEST = 0
IDX_RAM_UNUSED_BEGIN = 7
IDX_RAM_UNUSED_END = 14
IDX_RAM_VM_CNF = 5
IDX_RAM_VM_CNF_H = 6
IDX_RAM_VM_CNF_L = 5
MODE_ALM_ENA = 8
MODE_DEFAULT = 9
MODE_FORCE_CC = 32
MODE_FORCE_VM = 64
MODE_GG_RUN = 16
MODE_OFF = 0
MODE_VMODE = 1
RAM_SIZE = 16
RAM_TEST = 178
REG_ALARM_SOC = 19
REG_ALARM_VOLTAGE = 20
REG_CC_CNF = 15
REG_CC_CNF_H = 16
REG_CC_CNF_L = 15
REG_COUNTER = 4
REG_COUNTER_H = 5
REG_COUNTER_L = 4
REG_CTRL = 1
REG_CURRENT = 6
REG_CURRENT_H = 7
REG_CURRENT_L = 6
REG_CURRENT_THRES = 21
REG_ID = 24
REG_MODE = 0
REG_OCV = 13
REG_OCV_H = 14
REG_OCV_L = 13
REG_RAM0 = 32
REG_RAM1 = 33
REG_RAM10 = 42
REG_RAM11 = 43
REG_RAM12 = 44
REG_RAM13 = 45
REG_RAM14 = 46
REG_RAM15 = 47
REG_RAM2 = 34
REG_RAM3 = 35
REG_RAM4 = 36
REG_RAM5 = 37
REG_RAM6 = 38
REG_RAM7 = 39
REG_RAM8 = 40
REG_RAM9 = 41
REG_RAM_FIRST = 32
REG_RAM_LAST = 47
REG_SOC = 2
REG_SOC_H = 3
REG_SOC_L = 2
REG_TEMPERATURE = 10
REG_VM_CNF = 17
REG_VM_CNF_H = 18
REG_VM_CNF_L = 17
REG_VOLTAGE = 8
REG_VOLTAGE_H = 9
REG_VOLTAGE_L = 8
VM_CNF_DEFAULT = 321

philander.sysfactory module

A system convergence layer for smbus, smbus2, periphery or simulative implementation.

The factory class provides implementations for hardware resources like serial bus or GPIO pins. This unifies the APIs provided by packages like smbus, smbus2, periphery or gpiozero etc.

class SysFactory[source]

Bases: object

As a factory, provide implementations for specific hardware resources.

static autoDetectProvider(dependencies, fallback=SysProvider.NONE)[source]

Automatically detect a eligible provider.

Test the given dependencies and for the first available, return the associated provider mnemonic.

The dependencies are given as a list of constellations to check. Each entry of that list is a tuple of (SysProvider Mnemonics, module name, class name) such as in (SysProvider.PERIPHERY, “periphery”, “I2C”).

The fallback parameter is to override SysProvider.NONE in case none of the dependencies is fulfilled.

Parameters:
  • dependencies (list) – List of tuples describing the supported libs.

  • fallback (SysProvider) – Value to be returned, if none of the dependencies is fulfilled.

Returns:

Mnemonic to identify the first dependency fulfilled. SysProvider.NONE or the given fallback, if no matching dependency could be found.

Return type:

SysProvider

static createInstance(provider, implementations)[source]

Instantiate a certain implementation.

Create an instance of an implementation identified by a provider mnemonics.

The given provider parameter is the key argument into the dictionary of the implementations. It could be the result of calling autoDetectProvider().

The implementations are given as a dictionary translating a SysProvider type key into a tuple (pair) -value comprised of module name and class name. For example:

SysProvider.PERIPHERY: (“philander.serialbus_periphery”, “_SerialBus_Periphery”)

Instantiation is done by calling the empty constructor of the identified class.

Parameters:
  • provider (SysProvider) – The provider mnemonics identifying the implementation to be instantiated.

  • implementations (dict) – The dictionary describing where to find the specific class that must be instantiated, for a given provider key.

Returns:

An object, which is an instance of the specific implementation or None in case of an error.

Return type:

object

static getGPIO(provider=SysProvider.AUTO)[source]

Generates a GPIO implementation according to the requested provider.

Parameters:

provider (SysProvider) – The low-level lib to rely on, or AUTO for automatic detection.

Returns:

A GPIO implementation object, or None in case of an error.

Return type:

GPIO

class SysProvider(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Mnemonic designator for a lower-level lib, package or system environment to rely the implementation on.

AUTO = 2

Auto-detect best matching lib/package.

COMPOSITE = 4

Supported by a matching upper-level driver API, such as ADC via SPI.

GPIOZERO = 5

GPIO zero implementation for raspberry pi (https://gpiozero.readthedocs.io/en/latest/).

MICROPYTHON = 6

MicroPython environment (https://docs.micropython.org).

NONE = 1

No low-level API available.

PERIPHERY = 7

Python periphery lib (https://pypi.org/project/python-periphery/).

RPIGPIO = 8

RaspberryPi GPIO lib (https://pypi.org/project/RPi.GPIO/).

SIM = 3

Built-in hardware simulation.

SMBUS2 = 9

System Management Bus v2 (SMBUS2) implementation (https://pypi.org/project/smbus2/).

philander.systypes module

Data types commonly used throughout the system and not associated with any specific module.

class ErrorCode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Data type to indicate either a successful completion or the reason why some function or operation failed.

errBusy = 9
errCancelled = 18
errCorruptData = 13
errExhausted = 8
errFailure = 20
errFewData = 7
errInadequate = 2
errInitFailed = 23
errInternal = 5
errInvalidParameter = 1
errLowLevelFail = 24
errMalfunction = 21
errMoreData = 6
errNotImplemented = 3
errNotInited = 22
errNotSupported = 4
errOk = 0
errOverflow = 14
errPostProc = 17
errPreProc = 16
errResourceConflict = 12
errSpecRange = 11
errStopped = 25
errSuspended = 19
errUnavailable = 10
errUnderrun = 15
isOk()[source]
class Info[source]

Bases: object

Container type to wrap chip information data as retrieved from calls of Sensor.getInfo().

This is rather static information not changing too much over time.

validAnything = 255
validChipID = 1
validManufacID = 16
validModelID = 8
validNothing = 0
validRevMajor = 2
validRevMinor = 4
validSerialNum = 32
class RunLevel(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Operating mode that the CPU may run in.

Includes the normal (active) mode as well as a bunch of power-saving run levels.

active = 0
deepSleep = 6
idle = 1
leastFunctional = 7
leastPowerSave = 1
mostFunctional = 1
mostPowerSave = 7
nap = 4
relax = 2
shutdown = 7
sleep = 5
snooze = 3
standby = 3

philander.thermometer module

Abstract interface for temperature sensors accessible via serial communication.

Provide an API to abstract from temperature measurement devices.

class Data(temperature: PreciseTemperature = 0)[source]

Bases: object

Container type to wrap a thermometer’s primary measurement result.

Measurement data should always be expressed as a signed value in degree Celsius.

temperature: PreciseTemperature = 0

philander.vibrasense module

Support module for the Mikro-e Vibra sense click board.

This board carries a Sencera 801S vibration spring device as its core element.

class VibraSense[source]

Bases: EventEmitter, Sensor, Interruptable

Vibra sense driver implementation.

More information on the Mikroelektronika Vibra sense click (MIKROE-1927) board are available at: https://www.mikroe.com/vibra-sense-click

The functional core element is a Sencera 801S vibration spring. More information on that device can be found at: https://www.tme.eu/de/details/sens-801s/drucksensoren/sencera/801s/

DEBOUNCE_MS = 0
classmethod Params_init(paramDict)[source]

Initializes configuration parameters with defaults.

The following settings are supported:

Key name

Value type, meaning and default

Sensor.dataRate

int Data rate in Hz; default is set by Sensor.Params_init().

VibraSense.int.gpio.*

configuration of the INT pin, as documented at GPIO.Params_init(), overrides VibraSense.slot

VibraSense.enable.gpio.*

configuration of the EN pin, as documented at GPIO.Params_init(), optional.

VibraSense.slot

int=[1|2] the click board’s slot, alternative for int+enable pin configuration; SLOT_DEFAULT.

Also see: Sensor.Params_init(), SerialBusDevice.Params_init().

SLOT1_PIN_ENABLE = 29
SLOT1_PIN_SIGNAL = 31
SLOT2_PIN_ENABLE = 32
SLOT2_PIN_SIGNAL = 37
SLOT_DEFAULT = 1
close()[source]

Close this instance and release associated hardware resources.

This is the counterpart of open(). Upon return, further usage of this instance is prohibited and may lead to unexpected results. The instance can be re-activated by calling open(), again.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

getLatestData()[source]

Retrieves the most recent data available and returns immediately.

This function will never block, but may read data that has been read before, already. More precisely, the data returned was valid / taken at a moment in the past, which is as close as possible to the current point in time, (including right NOW).

For sensors which deliver measurements continuously in time, there is no semantic difference to getNextData().

In contrast, for sensors, which provide measurements discretely at certain time intervals, this function is expected to deliver the last measurement point - without any waiting. Typically, this requires some kind of buffering. at the sensor or driver side.

The method is synchronous in that, it hands out the resulting data to the caller upon return. In fact, this method returns both, the measurement result and an error code signaling success or failure. The measurement data should be considered valid only, if the error code indicates a successful execution of this method.

The type and interpretation of the returned measurement data is specific to the individual sensor and driver implementation. The application may rely on values scaled to reasonable units, such as temperatures in degree Celsius, distances in meters and pressures in Pascal - or multiples and fractions thereof.

Also see: getNextData().

Returns:

The measurement data object and an error code indicating either success or the reason of failure.

Return type:

Object, ErrorCode

getNextData()[source]

Retrieves the next data, possibly waiting for the current measurement interval to expire.

This function may introduce a blocking wait, but always returns with fresh, new data never read before. The measurement is taken / valid either immediately or as early as possible in the future.

For sensors, that deliver data continuously in time, there is no difference to getLatestData().

For sensors that sample data at certain time intervals, this function very likely includes some waiting delay until the next measurement is due.

In either case, this function blocks until the measurement is retrieved and hands out data to the application upon return. In that sense, this is a synchronous function.

The return is twofold: the measurement result and an error code signaling success or failure. The measurement data should be considered valid only, if the error code indicates a successful execution of this method.

The type and interpretation of the returned measurement data is specific to the individual sensor and driver implementation. The application may rely on values scaled to reasonable units or multiples and fractions thereof.

Also see: getLatestData().

Returns:

The measurement data object and an error code indicating either success or the reason of failure.

Return type:

Object, ErrorCode

open(paramDict)[source]

Opens an instance and puts it into a usable state.

Configures the sensor by reading the supported parameters or applying default values and calling configure(). Also see: module.Module.open().

Parameters:

paramDict (dict(str, object)) – Configuration parameters as obtained from module.Module.Params_init(), possibly.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

philander.vibrasense2 module

Support module for the Mikro-e Vibra sense 2 click board.

This board carries a TE LDT0-028K Piezo Film sensor as its core element.

class VibraSense2[source]

Bases: EventEmitter, Sensor, Interruptable, SerialBusDevice

Vibra sense 2 driver implementation.

More information on the Mikroelektronika Vibra sense 2 click (MIKROE-4355) board are available at: https://www.mikroe.com/vibra-sense-2-click

The functional core element is a TE LDT0-028K Piezo Film sensor. More information on that device can be found at: https://www.te.com/deu-de/product-CAT-PFS0006.html

ADDRESSES_ALLOWED = [77]
classmethod Params_init(paramDict)[source]

Initializes configuration parameters with defaults.

The following settings are supported:

Key name

Value type, meaning and default

SerialBusDevice.address

int I2C serial device address, must be ADDRESS; default is ADDRESS.

Also see: Sensor.Params_init(), SerialBusDevice.Params_init().

close()[source]

Close this instance and release associated hardware resources.

Also see: philander.module.Module.close().

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

getLatestData()[source]

Retrieve the latest data available, immediately.

The measurement data is a single 12 bit integer value in the range [0…4095]. It is proportional to the sensor element’s (LDT0) output voltage and can be interpreted as the vibration intensity or bending deflection. Note that a rest condition does not necessarily correspond to a value of zero.

Also see: philander.sensor.Sensor.getLatestData().

Returns:

The measurement data as a 16bit integer and an error code indicating either success or the reason of failure.

Return type:

Object, ErrorCode

getNextData()[source]

Retrieve the next data, possibly with a delay.

Also see: philander.sensor.Sensor.getNextData().

Returns:

The measurement data as a 16bit integer and an error code indicating either success or the reason of failure.

Return type:

Object, ErrorCode

open(paramDict)[source]

Opens an instance and puts it into a usable state.

Also see: philander.module.Module.open().

Parameters:

paramDict (dict(str, object)) – Configuration parameters.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

philander.voltmeter module

Driver implementation for a simple ADC-based voltage monitor and gas-gauge.

class Voltmeter(paramDict)[source]

Bases: Module, GasGauge

Driver for a generic ADC-based voltmeter.

DEFAULT_RANGE_MAX = 3300
DEFAULT_RANGE_MIN = 2500
classmethod Params_init(paramDict)[source]

Initialize parameters with their defaults.

The following settings are supported:

Key name

Value type, meaning and default

Voltmeter.range.max

int Maximum voltage in mV, maps to 100%; default is DEFAULT_RANGE_MAX.

Voltmeter.range.min

int Minimum voltage in mV, mapped to 0%; default is DEFAULT_RANGE_MIN.

Voltmeter.gpio.direction

see GPIO.Params_init(); default is GPIO.DIRECTION_IN.

Voltmeter.gpio.trigger

see GPIO.Params_init(); default is GPIO.TRIGGER_EDGE_FALLING.

Voltmeter.gpio.bounce

see GPIO.Params_init(); default is GPIO.BOUNCE_NONE.

All other Voltmeter.gpio.*

as documented at GPIO.Params_init().

Also see: Module.Params_init().

Parameters:

paramDict (dict(str, object)) – Dictionary of settings.

Returns:

none

Return type:

None

close()[source]

Close this instance and release hardware resources.

Also see: Module.close().

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

open(paramDict)[source]

Initialize an instance and prepare it for use.

Also see: Module.open().

Parameters:

paramDict (dict(str, object)) – Configuration parameters as possibly obtained from Params_init().

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

philander.watchdog module

Module to describe objects that provide wath dog capabilities.

class Watchdog[source]

Bases: object

Interface to define watch dog related methods.

INTERVAL_MS_DEFAULT = 1000
classmethod Params_init(paramDict)[source]

Initialize parameters with their defaults.

If the implementing class supports the Module interface, it can use this method to fill commonly supported options.

The following settings are supported:

Key name

Value type, meaning and default

Watchdog.Interval

int Watch dog interval in milliseconds; default is INTERVAL_MS_DEFAULT.

Also see: Module.Params_init().

Parameters:

paramDict (dict(str, object)) – Dictionary mapping option names to their respective values.

Returns:

none

Return type:

None

clearWatchdog()[source]

Clear the watch dog.

This is the implementation of the acknowledge mechanism. Calling this function is necessary for an application to prevent the watch dog from elapsing. Note that this method does not start the watch dog, when it is disabled.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

clearWatchdogElapsed()[source]

Clear the elapsed flag.

The application should call this function after it observed that the watch dog interval time expired.

Also see: isWatchdogElapsed().

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

disableWatchdog()[source]

Disable the watch dog and stop it from running, immediately.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

enableWatchdog()[source]

Enable and restart the watch dog.

Returns:

An error code indicating either success or the reason of failure.

Return type:

ErrorCode

isWatchdogElapsed()[source]

Check, whether the configured time interval has expired, or not.

By calling this function, an application may observe the expiration without using the interrupt mechanism. Note, that this flag is not cleared automatically. The caller would have to use clearWatchdogElapsed() for this purpose.

Returns ErrorCode.errOk, if the watch dog has elapsed, ErrorCode.errUnavailable, if it is not elapsed, yet, and any other value to indicate the reason, why this information could not be retrieved.

Returns:

An error code indicating the result.

Return type:

ErrorCode

isWatchdogRunning()[source]

Check, whether the watchdog is currently running or not.

Returns ErrorCode.errOk, if the watch dog is running, ErrorCode.errUnavailable, if it is not running and any other value to indicate the reason, why this information could not be retrieved.

Returns:

An error code indicating the result.

Return type:

ErrorCode

Module contents

A driver collection for embedded system components, such as sensors or battery chargers.