API for power consumption/metering device drivers
Object filename description:
sensor.type.model.spin
type is one of: power, current
model indicates the manufacturer's model number of the device
These are methods that are common to all power sensor drivers
Method | Description | Param | Returns |
---|---|---|---|
startx() |
Start driver using explicitly defined settings | Notes 1-3 | cog id+1 |
stop() |
Stop the driver | n/a | n/a |
defaults() |
Set sensor factory default settings | n/a | n/a |
Notes:
-
For I2C-connected sensors:
startx(SCL_PIN, SDA_PIN, I2C_FREQ, ADDR_BITS): status
- Not all devices support alternate I2C addresses.
-
startx()
returns the launched cog number+1 of com engine used on success. -
startx()
returnsFALSE
(0) if the driver fails to start, for these possible reasons:- No more cogs available
- One or more specified I/O pins are outside allowed range
- Bus frequency is outside allowed range
- If supported by the device,
dev_id()
didn't return the expected value
-
defaults()
may simply callreset()
, if sensible, as opposed to calling several other driver methods, in order to reduce memory usage. -
Drivers may have one or more
preset_()
methods, that establish a set of pre-set settings. -
stop()
performs the following tasks:- Stop any extra cogs that were started (if applicable)
- Clear all global variable space used to 0
Method | Description |
---|---|
adc2amps() |
Convert current ADC word to amperage |
adc2volts() |
Convert bus voltage ADC word to voltage |
adc2watts() |
Convert power ADC word to wattage |
current() |
Current measurement |
current_data() |
Current ADC word |
dev_id() |
Model-specific identification |
opmode() |
Set operating mode |
power() |
Power measurement |
power_data() |
Power ADC word |
reset() |
Reset device |
voltage() |
Bus voltage measurement |
voltage_data() |
Bus voltage ADC word |
Convert current ADC word to amperage
- Parameters:
adc_wd
: adc word
- Returns:
- current in microamperes
Convert bus voltage ADC word to voltage
- Parameters:
adc_wd
: adc word
- Returns:
- voltage in microvolts
Convert power ADC word to wattage
- Parameters:
adc_wd
: adc word
- Returns:
- power in microwatts
Current measurement
- Parameters: none
- Returns: current in microamperes
Current ADC word
- Parameters: none
- Returns: ADC word representing current
Device identification
- Parameters: n/a
- Returns: model-specific identification
Set operating mode
- Parameters:
mode
: new operating mode
- Returns:
- current operating mode
Power measurement
- Parameters: none
- Returns:
- power measurement in microwatts
Power ADC word
- Parameters: none
- Returns: ADC word representing power measurement
Reset device
- Parameters: none
- Returns: none NOTE: Some devices may require an additional I/O pin to perform a reset.
Bus voltage measurement
- Parameters: none
- Returns: voltage in microvolts
Bus voltage ADC word
- Parameters: none
- Returns: ADC word representing voltage
Notes:
- uA = microamperes, uV = microvolts, uW = microwatts
- Some devices may include additional methods (e.g., for interrupt support)
sensor.power.model.spin - driver object
|-- #include: sensor.power.common.spinh - provides standard API
|-- OBJ: HW-specific constants (core.con.model.spin)
|-- OBJ: Low-level communications engine (I2C, SPI, OneWire, etc)