### Start Soleil GenServer - Elixir Source: https://hexdocs.pm/soleil/Soleil.html Starts the Soleil GenServer process, initializing the library. Options include :i2c_bus, :battery_capacity, and :battery_energy. Returns the PID of the started process. ```elixir iex> {:ok, pid} = Soleil.start_link(battery_capacity: 1000, battery_energy: 3700) iex> is_pid(pid) true ``` -------------------------------- ### Start Soleil in Application Supervisor Source: https://hexdocs.pm/soleil/getting_started.html Add `Soleil` to your `application.ex` supervision tree, ensuring it starts before other processes that might call its functions. Provide `battery_capacity` and `battery_energy` for accurate fuel gauge readings. ```elixir defmodule MyApp.Application do # ... @impl true def start(_type, _args) do children = [ # ... {Soleil, battery_capacity: 2000, battery_energy: 7400}, # ... ] opts = [strategy: :one_for_one, name: SoleilDemo.Supervisor] Supervisor.start_link(children, opts) end # ... end ``` -------------------------------- ### start_link(opts) Source: https://hexdocs.pm/soleil/Soleil.html Starts the Soleil GenServer process. This function initializes the state and prepares the library for use. ```APIDOC ## start_link(opts) ### Description Starts the Soleil GenServer process. ### Method `start_link(opts)` ### Parameters #### Request Body - **i2c_bus** (string) - Optional - The I2C bus to use for hardware communication (default: `"i2c-1"`). - **battery_capacity** (integer) - Optional - The rated battery capacity in mAh (default: 2000). - **battery_energy** (integer) - Optional - The rated battery power in mWh (default: 7400). ### Request Example ```json { "i2c_bus": "i2c-1", "battery_capacity": 1000, "battery_energy": 3700 } ``` ### Response #### Success Response (200) - `GenServer.on_start()` - The PID of the started GenServer process. ``` -------------------------------- ### temperature Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Gets the internal chip temperature in degrees Celsius. ```APIDOC ## temperature(i2c_ref) ### Description Get the internal chip temperature in degrees Celsius. Future versions of hardware may support reading temperature from the battery internal NTC sensor. ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - Reference to the I2C bus. ### Request Example ```elixir {:ok, ref} = Circuits.I2C.open("i2c-1") Soleil.BQ27427.temperature(ref) ``` ### Response #### Success Response ( {:ok, float()} ) - Returns `{:ok, temperature}` where `temperature` is a float representing degrees Celsius. #### Error Response ( {:error, term()} ) - Returns `{:error, reason}` if the operation fails. ``` -------------------------------- ### flags/0 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Gets all status flags as a map. ```APIDOC ## flags(i2c_ref) ### Description Get all status flags as a map. ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - The I2C reference for the device. ### Response #### Success Response (200) - **flags** (map()) - A map containing various status flags. ### Response Example ```json { "over_temp_flag": false, "under_temp_flag": false, "full_charge": false, "charging": true, "ocv_taken": true, "dod_correct": true, "itpor": false, "cfgupmode": false, "bat_det": true, "soc1": false, "socf": false, "discharging": true } ``` ``` -------------------------------- ### Install Soleil Library in mix.exs Source: https://hexdocs.pm/soleil/getting_started.html Add the Soleil Elixir library to your project's dependencies in `mix.exs`. After adding, run `mix deps.get`. ```elixir defmodule MyApp.MixProject do # ... defp deps do [ # ... {:soleil, "~> 0.1.0"}, # ... ] end # ... end ``` -------------------------------- ### state_of_charge Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Gets the state of charge as a percentage (0-100). ```APIDOC ## state_of_charge(i2c_ref) ### Description Get the state of charge as a percentage (0-100). ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - Reference to the I2C bus. ### Request Example ```elixir {:ok, ref} = Circuits.I2C.open("i2c-1") Soleil.BQ27427.state_of_charge(ref) ``` ### Response #### Success Response ( {:ok, integer()} ) - Returns `{:ok, percentage}` where `percentage` is an integer from 0 to 100. #### Error Response ( {:error, term()} ) - Returns `{:error, reason}` if the operation fails. ``` -------------------------------- ### voltage Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Gets the battery voltage in volts. ```APIDOC ## voltage(i2c_ref) ### Description Gets the battery voltage in volts. ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - Reference to the I2C bus. ### Request Example ```elixir {:ok, ref} = Circuits.I2C.open("i2c-1") Soleil.BQ27427.voltage(ref) ``` ### Response #### Success Response ( {:ok, integer()} ) - Returns `{:ok, voltage}` where `voltage` is an integer representing volts (e.g., 3.750). #### Error Response ( {:error, term()} ) - Returns `{:error, reason}` if the operation fails. ``` -------------------------------- ### remaining_capacity/0 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Gets the remaining capacity in mAh. ```APIDOC ## remaining_capacity(i2c_ref) ### Description Get the remaining capacity in mAh. ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - The I2C reference for the device. ### Response #### Success Response (200) - **capacity** (integer()) - The remaining capacity in mAh. ### Response Example ```json { "capacity": 1128 } ``` ``` -------------------------------- ### Get Battery Chemistry ID Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves the chemical ID of the battery profile. Requires an opened I2C reference. Example shows successful retrieval of chemistry B. ```elixir iex> {:ok, ref} = Circuits.I2C.open("i2c-1") iex> Soleil.BQ27427.chemistry_id(ref) {:ok, :chemistry_b} # using chemistry B for SOC algorithmcopy ``` -------------------------------- ### power/0 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Get the average power in watts. Positive values indicate charging, negative values indicate discharging. ```APIDOC ## power(i2c_ref) ### Description Get the average power in watts. Positive values indicate charging, negative values indicate discharging. ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - The I2C reference for the device. ### Response #### Success Response (200) - **power** (integer()) - The average power in watts. ### Response Example ```json { "power": -0.850 } ``` ``` -------------------------------- ### Get State of Charge - BQ27427 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves the state of charge as a percentage (0-100). Requires opening an I2C reference. ```elixir @spec state_of_charge(i2c_bus()) :: {:ok, integer()} | {:error, term()} ``` ```elixir iex> {:ok, ref} = Circuits.I2C.open("i2c-1") iex> Soleil.BQ27427.state_of_charge(ref) {:ok, 37} # battery is at 37%copy ``` -------------------------------- ### full_charge_capacity/0 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Gets the full charge capacity in mAh. ```APIDOC ## full_charge_capacity(i2c_ref) ### Description Get the full charge capacity in mAh. ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - The I2C reference for the device. ### Response #### Success Response (200) - **capacity** (integer()) - The full charge capacity in mAh. ### Response Example ```json { "capacity": 1980 } ``` ``` -------------------------------- ### Get Status Flags Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves all status flags from the BQ27427 as a map. Requires an I2C reference. ```elixir flags(i2c_ref) ``` -------------------------------- ### current/0 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Gets the average current in amps. Positive values indicate charging, negative values indicate discharging. ```APIDOC ## current(i2c_ref) ### Description Gets the average current in amps. Positive values indicate charging, negative values indicate discharging. ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - The I2C reference for the device. ### Response #### Success Response (200) - **current** (integer()) - The average current in amps. ### Response Example ```json { "current": -0.250 } ``` ``` -------------------------------- ### Get State of Charge Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves the state of charge of the battery as a percentage (0-100). Requires an I2C reference. ```elixir state_of_charge(i2c_ref) ``` -------------------------------- ### Get Battery Voltage Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves the battery voltage in volts. Requires an I2C reference. ```elixir voltage(i2c_ref) ``` -------------------------------- ### Get Voltage - BQ27427 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves the battery voltage in volts. Requires opening an I2C reference. ```elixir @spec voltage(i2c_bus()) :: {:ok, integer()} | {:error, term()} ``` ```elixir iex> {:ok, ref} = Circuits.I2C.open("i2c-1") iex> Soleil.BQ27427.voltage(ref) {:ok, 3.750}copy ``` -------------------------------- ### Alarm Management Functions Source: https://hexdocs.pm/soleil/Soleil.MCP7940.html Functions to clear, get, and set alarms on the RTC. ```APIDOC ## clear_alarm(i2c) ### Description Clears the currently set alarm on the RTC. ### Parameters * **i2c** (Circuits.I2C.bus()) - The I2C bus to use for communication. ### Returns * `:ok` - If the alarm was successfully cleared. * `{:error, any()}` - An error tuple if communication fails. ``` ```APIDOC ## get_alarm(i2c) ### Description Retrieves the currently set alarm time from the RTC. ### Parameters * **i2c** (Circuits.I2C.bus()) - The I2C bus to use for communication. ### Returns * `{:ok, NaiveDateTime.t()}` - The set alarm time as a NaiveDateTime struct. * `{:error, any()}` - An error tuple if communication fails. ``` ```APIDOC ## set_alarm(i2c, alarm) ### Description Sets a new alarm time on the RTC. ### Parameters * **i2c** (Circuits.I2C.bus()) - The I2C bus to use for communication. * **alarm** (NaiveDateTime.t()) - The desired alarm time. ### Returns * `:ok` - If the alarm was successfully set. * `{:error, any()}` - An error tuple if communication fails. ``` ```APIDOC ## set_alarm_enabled(i2c, bool) ### Description Enables or disables the alarm functionality on the RTC. ### Parameters * **i2c** (Circuits.I2C.bus()) - The I2C bus to use for communication. * **bool** (boolean()) - `true` to enable the alarm, `false` to disable. ### Returns * `:ok` - If the alarm setting was successful. * `{:error, any()}` - An error tuple if communication fails. ``` -------------------------------- ### Get Full Charge Capacity Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves the full charge capacity of the battery in mAh. Requires an I2C reference. ```elixir full_charge_capacity(i2c_ref) ``` -------------------------------- ### Get Remaining Capacity Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves the remaining capacity of the battery in mAh. Requires an I2C reference. ```elixir remaining_capacity(i2c_ref) ``` -------------------------------- ### get_design_energy/0 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Gets the design capacity of the battery in mWh. The device must be unsealed to use this function. ```APIDOC ## get_design_energy(i2c_ref) ### Description Gets the design capacity of the battery in mWh. The device must be unsealed to use this function. ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - The I2C reference for the device. ### Response #### Success Response (200) - **energy** (integer()) - The design capacity in mWh. ### Response Example ```json { "energy": 3000 } ``` ``` -------------------------------- ### Get Wakeup Reason - Elixir Source: https://hexdocs.pm/soleil/Soleil.html Reports the reason the board woke from sleep. Possible reasons are :alarm (RTC alarm) or :manual (pushbutton/hall sensor). ```elixir iex> Soleil.wakeup_reason() :manual ``` -------------------------------- ### Get Average Power Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves the average battery power in watts. Positive values indicate charging, and negative values indicate discharging. Requires an I2C reference. ```elixir power(i2c_ref) ``` -------------------------------- ### Get Average Current Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves the average battery current in amps. Positive values indicate charging, and negative values indicate discharging. Requires an I2C reference. ```elixir current(i2c_ref) ``` -------------------------------- ### Get Control Status Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves the control status of the BQ27427 fuel gauge as a map. Requires an I2C reference. ```elixir @spec control_status(i2c_bus()) :: {:ok, map()} | {:error, term()} ``` -------------------------------- ### Get Battery Information - Elixir Source: https://hexdocs.pm/soleil/Soleil.html Reads battery information including state of charge, voltage, current, and temperature. Returns an {:ok, info} tuple or an {:error, reason}. ```elixir iex> {:ok, info} = Soleil.battery_info() iex> Map.keys(info) [:state_of_charge, :voltage, :current, :temperature] ``` -------------------------------- ### Get BQ27427 Design Capacity Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves the design capacity of the battery in mAh. Note that the device must be unsealed to use this function. ```elixir iex> Soleil.BQ27427.get_design_capacity(i2c) ``` ```elixir {:ok, 1200} # 1200 mAh batterycopy ``` -------------------------------- ### Get BQ27427 Design Energy Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves the design capacity of the battery in mWh. The device must be unsealed to use this function. ```elixir iex> Soleil.BQ27427.get_design_energy(i2c) ``` ```elixir {:ok, 3000} # 3000 mWh batterycopy ``` -------------------------------- ### Get Temperature - BQ27427 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves the internal chip temperature in degrees Celsius. Future versions may support reading from the battery's NTC sensor. Requires opening an I2C reference. ```elixir @spec temperature(i2c_bus()) :: {:ok, float()} | {:error, term()} ``` ```elixir iex> {:ok, ref} = Circuits.I2C.open("i2c-1") iex> Soleil.BQ27427.temperature(ref) {:ok, 25.7} # chip temperature is 25.7Ccopy ``` -------------------------------- ### Get Design Capacity Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves the design capacity of the battery in mAh. The device must be unsealed to use this function. Requires an I2C reference. ```elixir get_design_capacity(i2c_ref) ``` -------------------------------- ### Get Temperature Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves the internal chip temperature in degrees Celsius. Future hardware versions may support reading temperature from the battery's NTC sensor. Requires an I2C reference. ```elixir temperature(i2c_ref) ``` -------------------------------- ### Get Design Energy Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves the design energy of the battery in mWh. The device must be unsealed to use this function. Requires an I2C reference. ```elixir get_design_energy(i2c_ref) ``` -------------------------------- ### Get RTC Alarm Time Source: https://hexdocs.pm/soleil/Soleil.MCP7940.html Retrieves the currently set alarm time from the MCP7940 RTC. Returns the alarm time as a NaiveDateTime struct or an error tuple. Requires an active I2C bus connection. ```elixir @spec get_alarm(Circuits.I2C.bus()) :: {:ok, NaiveDateTime.t()} | {:error, any()} ``` -------------------------------- ### enter_config_mode/0 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Enters configuration mode. The device must be unsealed before this can be used. ```APIDOC ## enter_config_mode(i2c_ref) ### Description Enter configuration mode. The device must be unsealed before this can be used. ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - The I2C reference for the device. ### Response #### Success Response (200) - **status** (:ok | {:error, term()}) - Indicates success or failure. ### Response Example ```json { "status": "ok" } ``` ``` -------------------------------- ### Enter Configuration Mode Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Enters configuration mode for the BQ27427. The device must be unsealed before this function can be used. Requires an I2C reference. ```elixir enter_config_mode(i2c_ref) ``` -------------------------------- ### Configure NervesTime with Soleil.MCP7940 Source: https://hexdocs.pm/soleil/Soleil.MCP7940.html To use this module with NervesTime, update the `:nerves_time` application environment configuration. Check logs for errors if the RTC does not function correctly. ```elixir config :nerves_time, rtc: Soleil.MCP7940copy ``` -------------------------------- ### Enable Linux Kernel Preempt-RT Patches Source: https://hexdocs.pm/soleil_system_rpi0_2/index.html Add this kernel patch URL to your nerves_defconfig to enable real-time performance. Verify the patch version as it may be out of date. ```bash BR2_LINUX_KERNEL_PATCH="http://cdn.kernel.org/pub/linux/kernel/projects/rt/4.19/patch-4.19.25-rt16.patch.xz" ``` -------------------------------- ### power_off() Source: https://hexdocs.pm/soleil/Soleil.html 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. ```APIDOC ## power_off() ### Description Powers off the device. ### Method `power_off()` ### Response #### Success Response (200) - `:ok` or `{:error, any()}` ``` -------------------------------- ### configure_fuel_gauge(opts) Source: https://hexdocs.pm/soleil/Soleil.html Updates the configuration of the BQ27427 battery fuel gauge chip. Accepts the same parameters as `start_link/1`. ```APIDOC ## configure_fuel_gauge(opts) ### Description Updates the configuration of the BQ27427 battery fuel gauge chip. ### Method `configure_fuel_gauge(opts)` ### Parameters #### Request Body - **battery_capacity** (integer) - Required/Optional - The rated battery capacity in mAh. - **battery_energy** (integer) - Required/Optional - The rated battery power in mWh. ### Request Example ```json { "battery_capacity": 1000, "battery_energy": 3700 } ``` ### Response #### Success Response (200) - `:ok` or `{:error, any()}` ``` -------------------------------- ### Enable PREEMPT_RT_FULL in Linux Configuration Source: https://hexdocs.pm/soleil_system_rpi0_2/index.html Modify the Linux kernel configuration to enable full real-time preemption. This is an alternative to using `make linux-menuconfig`. ```diff -CONFIG_PREEMPT=y +CONFIG_PREEMPT_RT_FULL=y ``` -------------------------------- ### Power Off Device - Elixir Source: https://hexdocs.pm/soleil/Soleil.html Initiates a shutdown sequence for the device. On host environments, it simulates the power-off behavior. Returns :ok or an {:error, reason}. ```elixir iex> :ok = Soleil.power_off() ``` -------------------------------- ### unseal Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Unseals the device to allow configuration changes. ```APIDOC ## unseal(i2c_ref) ### Description Unseal the device to allow configuration changes. ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - Reference to the I2C bus. ### Response #### Success Response ( :ok ) - Returns `:ok` on success. #### Error Response ( {:error, term()} ) - Returns `{:error, reason}` if the operation fails. ``` -------------------------------- ### Add Soleil Nerves System to mix.exs Source: https://hexdocs.pm/soleil/getting_started.html Specify the Soleil Nerves system and target in your project's mix.exs file. Ensure the target is set as an environment variable before running `mix deps.get`. ```elixir defmodule MyApp.MixProject do # ... @all_targets ["...", :soleil_rpi0_2] # ... defp deps do [ # ... {:soleil_system_rpi0_2, "~> 1.28.1", runtime: false, targets: :soleil_rpi0_2}, # ... ] end # ... end ``` ```bash export MIX_TARGET="soleil_rpi0_2" ``` -------------------------------- ### get_design_capacity/0 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Gets the design capacity of the battery in mAh. The device must be unsealed to use this function. ```APIDOC ## get_design_capacity(i2c_ref) ### Description Gets the design capacity of the battery in mAh. The device must be unsealed to use this function. ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - The I2C reference for the device. ### Response #### Success Response (200) - **capacity** (integer()) - The design capacity in mAh. ### Response Example ```json { "capacity": 1200 } ``` ``` -------------------------------- ### seal/0 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Seals the device to prevent configuration changes. ```APIDOC ## seal(i2c_ref) ### Description Seal the device to prevent configuration changes. ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - The I2C reference for the device. ### Response #### Success Response (200) - **status** (:ok | {:error, term()}) - Indicates success or failure. ### Response Example ```json { "status": "ok" } ``` ``` -------------------------------- ### Capture JPEG Image with libcamera Source: https://hexdocs.pm/soleil_system_rpi0_2/index.html Use this command to capture a JPEG image using libcamera. The image will be saved to /data/test.jpeg. This replaces the older MMAL interface, so the Elixir picam library will not work. ```bash cmd("libcamera-jpeg -n -v -o /data/test.jpeg") ``` -------------------------------- ### sleep_until(datetime) Source: https://hexdocs.pm/soleil/Soleil.html Puts the device to sleep until a specified datetime. The device will enter a low-power state and wake up at the specified time. ```APIDOC ## sleep_until(datetime) ### Description Puts the device to sleep until a specified datetime. ### Method `sleep_until(datetime)` ### Parameters #### Path Parameters - **datetime** (NaiveDateTime.t()) - Required - A UTC `NaiveDateTime` representing the target wake-up time. ### Response #### Success Response (200) - `:ok` or `{:error, any()}` ``` -------------------------------- ### wakeup_reason() Source: https://hexdocs.pm/soleil/Soleil.html Reports the reason that the board woke from sleep. Reasons for wakeup include: `:alarm` (when the RTC alarm triggers wakeup) or `:manual` (when the pushbutton or hall sensor triggers wakeup). ```APIDOC ## wakeup_reason() ### Description Reports the reason that the board woke from sleep. ### Method `wakeup_reason()` ### Response #### Success Response (200) - `:alarm` or `:manual` ``` -------------------------------- ### Force Audio Output to HDMI Source: https://hexdocs.pm/soleil_system_rpi0_2/index.html Configure the Raspberry Pi to output audio through the HDMI port. Change the last argument to '1' to use the stereo output jack instead. ```bash cmd("amixer cset numid=3 2") ``` -------------------------------- ### soft_reset Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Performs a soft reset of the device, maintaining configuration but resetting calculations. Used to exit configuration mode. ```APIDOC ## soft_reset(i2c_ref) ### Description Perform a soft reset of the device. This maintains configuration but resets calculations. Used to exit configuration mode (has the side effect of re-sealing the device). ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - Reference to the I2C bus. ### Response #### Success Response ( :ok ) - Returns `:ok` on success. #### Error Response ( {:error, term()} ) - Returns `{:error, reason}` if the operation fails. ``` -------------------------------- ### sleep_for(duration, unit) Source: https://hexdocs.pm/soleil/Soleil.html Puts the device to sleep for a specified duration. The device will enter a low-power state and wake up after the specified duration. ```APIDOC ## sleep_for(duration, unit) ### Description Puts the device to sleep for a specified duration. ### Method `sleep_for(duration, unit)` ### Parameters #### Path Parameters - **duration** (non_neg_integer) - Required - The duration to sleep. - **unit** (:day | :hour | :minute | System.time_unit()) - Required - The unit of duration. ### Response #### Success Response (200) - `:ok` or `{:error, any()}` ``` -------------------------------- ### reset/0 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Performs a hard reset of the device. This will reset all registers to their default values. ```APIDOC ## reset(i2c_ref) ### Description Perform a hard reset of the device. This will reset all registers to their default values. ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - The I2C reference for the device. ### Response #### Success Response (200) - **status** (:ok | {:error, term()}) - Indicates success or failure. ### Response Example ```json { "status": "ok" } ``` ``` -------------------------------- ### control_status/0 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Retrieves the control status flags of the BQ27427 device. ```APIDOC ## control_status(i2c_ref) ### Description Retrieves the control status flags of the BQ27427 device. ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - The I2C reference for the device. ### Response #### Success Response (200) - **control_status** (map()) - A map containing various control status flags. ### Response Example ```json { "sleep": false, "bca": false, "calmode": false, "cca": false, "chemchange": false, "initcomp": true, "ldmd": true, "qmax_up": false, "res_up": false, "rup_dis": true, "sealed": false, "shutdown_enabled": false, "vok": false, "wdreset": false } ``` ``` -------------------------------- ### battery_info() Source: https://hexdocs.pm/soleil/Soleil.html Reads battery information from the hardware. This function queries the battery for its state of charge, voltage, average current consumption, and temperature. ```APIDOC ## battery_info() ### Description Reads battery information from the hardware. ### Method `battery_info()` ### Response #### Success Response (200) - **state_of_charge** (float) - The current state of charge of the battery. - **voltage** (float) - The current voltage of the battery. - **current** (float) - The current average current consumption. - **temperature** (float) - The current temperature of the battery. ### Response Example ```json { "state_of_charge": 0.95, "voltage": 4.1, "current": 0.1, "temperature": 25.5 } ``` ``` -------------------------------- ### Configure Fuel Gauge - Elixir Source: https://hexdocs.pm/soleil/Soleil.html Updates the configuration of the BQ27427 battery fuel gauge chip. Accepts keyword list options similar to start_link/1. Returns :ok or an {:error, reason}. ```elixir iex> Soleil.configure_fuel_gauge(battery_capacity: 1000, battery_energy: 3700) :ok ``` -------------------------------- ### Configure State of Charge Interrupt Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Configures the GPOUT pin to trigger an interrupt based on the State of Charge percentage. Requires an I2C reference, a trigger threshold, and a clear threshold. ```elixir iex> Soleil.BQ27427.configure_soc1_interrupt(i2c, 20, 25) # Trigger at 20%, clear at 25%copy ``` -------------------------------- ### Sleep Until Datetime - Elixir Source: https://hexdocs.pm/soleil/Soleil.html Puts the device to sleep until a specified NaiveDateTime. The device will wake up at the target time. Returns :ok or an {:error, reason}. ```elixir iex> :ok = Soleil.sleep_until(~N[2024-11-17 08:30:00]) ``` -------------------------------- ### set_charge_direction/0 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Sets the bit to configure the sign of the CC_Gain parameter. The default firmware for the BQ27427 for some reason shipped with the wrong value, and isn't documented in the datasheet. ```APIDOC ## set_charge_direction(i2c_ref) ### Description Sets the bit to configure the sign of the CC_Gain parameter. The default firmware for the BQ27427 for some reason shipped with the wrong value, and isn't documented in the datasheet. See the TI support issue for more information: https://e2e.ti.com/support/power-management-group/power-management/f/power-management-forum/1215460/bq27427evm-misbehaving-stateofcharge ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - The I2C reference for the device. ### Response #### Success Response (200) - **status** (:ok | {:error, term()}) - Indicates success or failure. ### Response Example ```json { "status": "ok" } ``` ``` -------------------------------- ### Perform Soft Reset Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Performs a soft reset of the BQ27427 device, maintaining configuration but resetting calculations. This is used to exit configuration mode and has the side effect of re-sealing the device. Requires an I2C reference. ```elixir soft_reset(i2c_ref) ``` -------------------------------- ### Read BQ27427 Current Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Opens an I2C connection and reads the average current in amps. Positive values indicate charging, and negative values indicate discharging. Useful for monitoring battery charge/discharge rates. ```elixir iex> {:ok, ref} = Circuits.I2C.open("i2c-1") iex> Soleil.BQ27427.current(ref) ``` ```elixir {:ok, -0.250} # Discharging at 250mAcopy ``` -------------------------------- ### Unseal Device - BQ27427 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Unseals the device to allow configuration changes. ```elixir @spec unseal(i2c_bus()) :: :ok | {:error, term()} ``` -------------------------------- ### Unseal Device Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Unseals the BQ27427 device to allow configuration changes. Requires an I2C reference. ```elixir unseal(i2c_ref) ``` -------------------------------- ### Soft Reset - BQ27427 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Performs a soft reset of the device. This maintains configuration but resets calculations. Used to exit configuration mode (has the side effect of re-sealing the device). ```elixir @spec soft_reset(i2c_bus()) :: :ok | {:error, term()} ``` -------------------------------- ### Read BQ27427 Remaining Capacity Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Opens an I2C connection and reads the remaining capacity in mAh. This indicates the estimated amount of charge left in the battery. ```elixir iex> {:ok, ref} = Circuits.I2C.open("i2c-1") iex> Soleil.BQ27427.remaining_capacity(ref) ``` ```elixir {:ok, 1128} # battery has an estimated 1128mAh remainingcopy ``` -------------------------------- ### Time Read/Write Functions Source: https://hexdocs.pm/soleil/Soleil.MCP7940.html Functions to read the current time from and write the time to the RTC. ```APIDOC ## read_time(i2c) ### Description Reads the current time from the MCP7940 RTC. ### Parameters * **i2c** (Circuits.I2C.bus()) - The I2C bus to use for communication. ### Returns * `{:ok, NaiveDateTime.t()}` - The current time as a NaiveDateTime struct. * `{:error, any()}` - An error tuple if communication fails. ``` ```APIDOC ## write_time(i2c, datetime) ### Description Writes the specified datetime to the MCP7940 RTC. ### Parameters * **i2c** (Circuits.I2C.bus()) - The I2C bus to use for communication. * **datetime** (NaiveDateTime.t()) - The NaiveDateTime struct to write to the RTC. ### Returns * `:ok` - If the time was successfully written. * `{:error, any()}` - An error tuple if communication fails. ``` -------------------------------- ### Write Time to RTC Source: https://hexdocs.pm/soleil/Soleil.MCP7940.html Writes a specific NaiveDateTime to the MCP7940 RTC. This function requires an active I2C bus connection and the datetime struct to be written. ```elixir @spec write_time(Circuits.I2C.bus(), NaiveDateTime.t()) :: :ok | {:error, any()} ``` -------------------------------- ### Perform Hard Reset Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Performs a hard reset of the BQ27427 device, resetting all registers to their default values. Requires an I2C reference. ```elixir reset(i2c_ref) ``` -------------------------------- ### read_data_memory/4 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Reads data from the device's data memory. ```APIDOC ## read_data_memory(i2c_ref, class, block, offset, length) ### Description Reads data from the device's data memory. ### Parameters #### Path Parameters - **i2c_ref** (i2c_bus()) - Required - The I2C reference for the device. - **class** (integer()) - Required - The memory class to read from. - **block** (integer()) - Required - The memory block to read from. - **offset** (integer()) - Required - The offset within the block to start reading. - **length** (integer()) - Required - The number of bytes to read. ### Response #### Success Response (200) - **data** (binary()) - The data read from memory. ### Response Example ```json { "data": "0xDEADBEEF" } ``` ``` -------------------------------- ### Read BQ27427 Power Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Opens an I2C connection and reads the average power in watts. Positive values indicate charging, and negative values indicate discharging. Useful for monitoring battery power consumption/generation. ```elixir iex> {:ok, ref} = Circuits.I2C.open("i2c-1") iex> Soleil.BQ27427.current(ref) ``` ```elixir {:ok, -0.850} # Discharging at 850mWcopy ``` -------------------------------- ### Set Charge Direction Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Sets the bit to configure the sign of the CC_Gain parameter. This is a workaround for a firmware issue in the default BQ27427 firmware. Requires an I2C reference. ```elixir set_charge_direction(i2c_ref) ``` -------------------------------- ### Set Serial Number on Running Device Source: https://hexdocs.pm/soleil_system_rpi0_2/index.html Use this command to set the `nerves_serial_number` on a live device. A reboot is required for the change to take effect. ```shell iex> cmd("fw_setenv nerves_serial_number 12345678") ``` -------------------------------- ### Read BQ27427 Flags Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Opens an I2C connection and retrieves all status flags from the BQ27427 as a map. This provides a comprehensive overview of the battery's current state. ```elixir iex> {:ok, ref} = Circuits.I2C.open("i2c-1") iex> Soleil.BQ27427.flags(ref) ``` ```elixir %{ over_temp_flag: false, under_temp_flag: false, full_charge: false, charging: true, ocv_taken: true, dod_correct: true, itpor: false, cfgupmode: false, bat_det: true, soc1: false, socf: false, discharging: true } ``` -------------------------------- ### Read BQ27427 Full Charge Capacity Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Opens an I2C connection and reads the full charge capacity in mAh. This value represents the estimated total capacity of the battery when fully charged. ```elixir iex> {:ok, ref} = Circuits.I2C.open("i2c-1") iex> Soleil.BQ27427.full_charge_capacity(ref) ``` ```elixir {:ok, 1980} # battery has an estimated capacity of 1980mAh at full chargecopy ``` -------------------------------- ### Sleep for Duration - Elixir Source: https://hexdocs.pm/soleil/Soleil.html Puts the device to sleep for a specified duration. The unit can be :second, :minute, :hour, or :day. Returns :ok or an {:error, reason}. ```elixir iex> Soleil.sleep_for(60) # Sleep for 1 minute :ok ``` -------------------------------- ### Set RTC Alarm Time Source: https://hexdocs.pm/soleil/Soleil.MCP7940.html Sets a specific alarm time on the MCP7940 RTC. The alarm time should be provided as a NaiveDateTime struct. Requires an active I2C bus connection. ```elixir @spec set_alarm(Circuits.I2C.bus(), NaiveDateTime.t()) :: :ok | {:error, any()} ``` -------------------------------- ### Seal Device Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Seals the BQ27427 device to prevent configuration changes. Requires an I2C reference. ```elixir seal(i2c_ref) ``` -------------------------------- ### Read Data Memory Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Reads data from the BQ27427's data memory. Requires an I2C reference, class, block, offset, and length. ```elixir read_data_memory(i2c_ref, class, block, offset, length) ``` -------------------------------- ### Alarm Status Functions Source: https://hexdocs.pm/soleil/Soleil.MCP7940.html Functions to check if an alarm is enabled and if the alarm flag is set. ```APIDOC ## alarm_enabled?(i2c) ### Description Checks if an alarm is currently enabled on the RTC. ### Parameters * **i2c** (Circuits.I2C.bus()) - The I2C bus to use for communication. ### Returns * `boolean()` - `true` if an alarm is enabled, `false` otherwise. * `{:error, any()}` - An error tuple if communication fails. ``` ```APIDOC ## alarm_flag?(i2c) ### Description Checks if the alarm flag has been set on the RTC. ### Parameters * **i2c** (Circuits.I2C.bus()) - The I2C bus to use for communication. ### Returns * `boolean()` - `true` if the alarm flag is set, `false` otherwise. * `{:error, any()}` - An error tuple if communication fails. ``` -------------------------------- ### Set BQ27427 Charge Direction Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Sets a specific bit to configure the sign of the CC_Gain parameter. This is a workaround for a documented firmware issue in some BQ27427 devices. ```elixir iex> Soleil.BQ27427.set_charge_direction(i2c) ``` ```elixir :okcopy ``` -------------------------------- ### Set Design Capacity Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Sets the design capacity of the battery in mAh. The device must be unsealed to use this function. Requires an I2C reference and the capacity value. ```elixir set_design_capacity(i2c_ref, capacity) ``` -------------------------------- ### Set Serial Number During Firmware Burning Source: https://hexdocs.pm/soleil_system_rpi0_2/index.html Set the `NERVES_SERIAL_NUMBER` environment variable when using `fwup` to burn firmware to a MicroSD card. This provisions the serial number offline. ```shell sudo NERVES_SERIAL_NUMBER=12345678 fwup path_to_firmware.fw ``` -------------------------------- ### Set Design Capacity - BQ27427 Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Sets the design capacity of the battery in mAh. The device must be unsealed to use this function. ```elixir @spec set_design_capacity(i2c_bus(), integer()) :: :ok | {:error, term()} ``` ```elixir iex> Soleil.BQ27427.set_design_capacity(i2c, 1200) # 1200mAh batterycopy ``` -------------------------------- ### Set Chemistry ID Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Sets the chemistry ID of the battery profile. The device must be unsealed to use this function. Requires an I2C reference and the chemistry ID. ```elixir set_chemistry_id(i2c_ref, chem_id) ``` -------------------------------- ### Seal BQ27427 Device Source: https://hexdocs.pm/soleil/Soleil.BQ27427.html Seals the BQ27427 device to prevent further configuration changes. This is typically done after configuration is complete. ```elixir iex> Soleil.BQ27427.seal(i2c_ref) ``` -------------------------------- ### Read Current RTC Time Source: https://hexdocs.pm/soleil/Soleil.MCP7940.html Reads the current time from the MCP7940 RTC. Returns the time as a NaiveDateTime struct or an error tuple. Requires an active I2C bus connection. ```elixir @spec read_time(Circuits.I2C.bus()) :: {:ok, NaiveDateTime.t()} | {:error, any()} ```