Module:digipowercontrol
From Digi Developer
Low power mode functionality is provided by the digipowercontrol which is supported on Digi products with the special power control hardware. An exception will be thrown if you attempt to use these routines on a device which does not support power control.
The power control device is not responsible for determining when a device or its peripherals should be powered off. This intelligence is left to the applications running in the device. The following operations are supplied via the embedded Python "digipowercontrol" module so that applications can:
- Turn off the system power
- Turn off the system power until a future time (scheduled wakeup)
- Independently control the power of the cellular modem (default state is on when the device is first connected to power)
- Independently control the power of an Orbcomm satellite modem, if present (default state is off whenever the processor is powered on)
- Determine the current state of the power sources managed by the power control module
- Get a hint, when possible, as to the reason the system was powered on
Descriptions of supported methods and types follow.
Contents |
Methods
cellular_power_get()
- Purpose
Get the state of power to the cellular module.
- Syntax
cellular_power_get() . state
- Description
Get the state of power to the cellular module.
- Return
Return a true value if enabled, a false value if disabled.
cellular_power_set()
- Purpose
Control the state of power to the cellular module.
- Syntax
cellular_power_set(state) . None
- Description
Control the state of power to the cellular module. A state argument with a true value enables power, and a false value disables it (low power mode).
- Return
None
orbcomm_power_get()
- Purpose
Get the state of power to the orbcomm satellite module.
- Syntax
orbcomm_power_get() . state
- Description
Get the state of power to the orbcomm satellite module.
- Return
Return a true value if enabled, a false value if disabled.
orbcomm_power_set()
- Purpose
Control the state of power to the orbcomm satellite module.
- Syntax
orbcomm_power_set(state) . None
- Description
Control the state of power to the orbcomm satellite module. A state argument with a true value enables power, and a false value disables it (low power mode).
- Return
None
system_power_get()
- Purpose
Get the state of system power.
- Syntax
system_power_get() . state
- Description
Get the state of system power. This function exists for future flexibility and completeness, since when system power is off, the value False can never be returned.
- Return
Return a true value if enabled, a false value if disabled.
system_power_set()
- Purpose
Control the state of system power.
- Syntax
system_power_set(state[, duration]) . None
- Description
Control the state of system power. A state argument with a true value enables power, and a false value disables it (low power mode). If the power is being changed to the disabled state, the optional duration argument can be supplied to indicate how many seconds (at most) the device should remain powered off.
- Return
None
wake_on_external_irq_set()
- Purpose
Enable the power control module to wake up and reset on an external IRQ.
- Syntax
wake_on_external_irq_set(gpio_pin, trigger_type) . None
- Description
Enable the power control module to wake up and reset on an external IRQ, call system_power_set() to put the device to sleep after calling this function.
The first argument indicates which GPIO pin is used.
The second argument indicates the trigger type, which can be:
WAKE_ON_IRQ_RISING_EDGE -- trigger on rising edge
WAKE_ON_IRQ_FALLING_EDGE -- trigger on falling edge
WAKE_ON_IRQ_LOGIC_ONE -- trigger on logic one
WAKE_ON_IRQ_LOGIC_ZERO -- trigger on logic zero
- Return
None.
wake_reason()
- Purpose
Enable the power control module to wake up and reset on an external IRQ.
- Syntax
wake_reason() . reasons | None
- Description
Returns a Python "set" object populated with one or more values indicating why the power controller enabled processor power.
A return of None indicates that no reason is available. This might occur on a device initiated reboot, since the power controller did not cycle the power to initiate processor operation.
- Return
- None if device is booting due to normal power up.
- WAKE_REASON_ACCEL = 2
- WAKE_REASON_IGNITION = 0
- WAKE_REASON_POWERLOSS = 7
- WAKE_REASON_RTC = 1
Note that not all products support all reasons.
Power Control Examples
Wake up and reset on an external IRQ trigger
# # Cause the device to enter low power sleep mode and # reset when the wakeup button (GPIO 4) is pressed # on the CC9P3G 9215 developement board # import digipowercontrol import sys # The GPIO described in the Hardware Reference Manual for your board # In this case GPIO4 is connected to the wake up button on the board. wakeup_button_gpio = 0x04 # Wake up when the button is pressed, for the this board # the GPIO4 is pulled low when the button is pressed, so we # wakeup on the falling edge. digipowercontrol.wake_on_external_irq_set(wakeup_button_gpio , digipowercontrol.WAKE_ON_IRQ_FALLING_EDGE) # Go to sleep, reset when a trigger occurs, this routine does not return digipowercontrol.system_power_set(0)
Wake up and reset after a given duration
# # Cause the device to enter low power sleep mode and # wake up after the number of seconds entered # import digipowercontrol import sys duration = 0.0 print("Enter the duration in seconds:") duration = float(raw_input('-->')) # Go to sleep, wake-up and reset after the number of seconds entered # This function will not return digipowercontrol.system_power_set(0, duration)
Availability
Products which support this module
Digi Python-enabled products which do support this feature include:
| Function | ConnectPort X3 | ConnectPort X5 | ConnectCore 3G 9P |
|---|---|---|---|
| cellular_power_get() | No | Yes | No |
| cellular_power_set() | No | Yes | No |
| orbcomm_power_get() | No | Optional HW | No |
| orbcomm_power_set() | No | Optional HW | No |
| system_power_get() | Yes | Yes | Yes |
| system_power_set() | Yes | Yes | Yes |
| wake_on_external_irq_set() | No | No | Yes |
| wake_reason() | Yes | Yes | No |
Products which DO NOT support this module
In general, most Digi Python-enabled products DO NOT support this module because very special hardware design is required.
