View Source Soleil (soleil v0.1.1)
The official support library for the Soleil power management and sleep control board for Raspberry Pi.
This library provides functions for managing device power, scheduling sleep durations and wake times, as well as reading battery information. It is designed to abstract low-level hardware interactions, providing a clean and intuitive API for developers.
Summary
Functions
Reads battery information from the hardware.
Returns a specification to start this module under a supervisor.
Updates the configuration of the BQ27427 battery fuel gauge chip.
Callback implementation for GenServer.init/1
.
Powers off the device.
Puts the device to sleep for a specified duration.
Puts the device to sleep until a specified datetime.
Starts the Soleil GenServer process.
Reports the reason that the board woke from sleep.
Types
Functions
@spec battery_info() :: {:ok, battery_info()} | {:error, any()}
Reads battery information from the hardware.
This function queries the battery for its state of charge, voltage, average current consumption, and temperature.
Examples
iex> {:ok, info} = Soleil.battery_info()
iex> Map.keys(info)
[:state_of_charge, :voltage, :current, :temperature]
Returns a specification to start this module under a supervisor.
See Supervisor
.
Updates the configuration of the BQ27427 battery fuel gauge chip.
Accepts the same parameters as start_link/1
.
Examples
iex> Soleil.configure_fuel_gauge(battery_capacity: 1000, battery_energy: 3700)
:ok
Callback implementation for GenServer.init/1
.
@spec power_off() :: :ok | {:error, any()}
Powers off the device.
On supported hardware, this will initiate a shutdown sequence. On host environments (e.g., during development), it simulates the power-off behavior.
Examples
iex> :ok = Soleil.power_off()
@spec sleep_for(non_neg_integer(), :day | :hour | :minute | System.time_unit()) :: :ok | {:error, any()}
Puts the device to sleep for a specified duration.
The device will enter a low-power state and wake up after the specified duration.
Parameters
duration
- The duration to sleep.unit
- the unit of duration.
Examples
iex> Soleil.sleep_for(60) # Sleep for 1 minute
:ok
@spec sleep_until(NaiveDateTime.t()) :: :ok | {:error, any()}
Puts the device to sleep until a specified datetime.
The device will enter a low-power state and wake up at the specified time.
Parameters
datetime
- A UTCNaiveDateTime
representing the target wake-up time.
Examples
iex> :ok = Soleil.sleep_until(~N[2024-11-17 08:30:00])
@spec start_link(keyword()) :: GenServer.on_start()
Starts the Soleil GenServer process.
This function initializes the state and prepares the library for use.
Options
:i2c_bus
- The I2C bus to use for hardware communication (default:"i2c-1"
).:battery_capacity
- The rated battery capacity in mAh (default: 2000).:battery_energy
- The rated battery power in mWh (default: 7400).
Examples
iex> {:ok, pid} = Soleil.start_link(battery_capacity: 1000, battery_energy: 3700)
iex> is_pid(pid)
true
@spec wakeup_reason() :: :alarm | :manual
Reports the reason that the board woke from sleep.
Reasons for wakeup include:
:alarm
: when the RTC alarm triggers wakeup, such as aftersleep_for/2
orsleep_until/1
:manual
: when the pushbutton or hall sensor triggers wakeup
Examples
iex> Soleil.wakeup_reason()
:manual