Power Supply

Example Usage

// Basic
auto *power_supply = App.make_power_supply(12);
// Inverted, for ATX
auto *atx = App.make_power_supply(GPIOOutputPin(12, OUTPUT, true));

API Reference

PowerSupplyComponent

class PowerSupplyComponent : public Component

This class represents an power supply.

The power supply will automatically be turned on if a component requests high power and will automatically be turned off again keep_on_time (ms) after the last high-power request is cancelled. Aditionally, an enable_time (ms) can be specified because many power supplies only actually provide high-power output after a few milliseconds.

Use the pin argument of the Application helper to enable inverted mode. For example most ATX power supplies operate in inverted mode, so to turn them on you have to pull the pin LOW.

To request high power mode, a component must use the request_high_power() function to register itself as needing high power mode. Once the high power mode is no longer required the component can use unrequest_high_power() to unregister its high power mode. IMPORTANT: An component should NOT hold multiple requests to the same power supply, as the PowerSupplyComponent only holds an internal counter of how many high power requests have been made.

Usually though, all this should actually be handled by BinaryOutput and FloatOutput, since using this class correctly is not too easy.

Public Functions

PowerSupplyComponent(GPIOPin *pin, uint32_t enable_time = 20, uint32_t keep_on_time = 10000)

Creates the PowerSupplyComponent.

Parameters
  • pin: The pin of the power supply control wire.
  • enable_time: The time in milliseconds the power supply requires for power up. The thread will block in the meantime
  • keep_on_time: The time in milliseconds the power supply should be kept on after the last high-power request.

void set_keep_on_time(uint32_t keep_on_time)

Set the time in milliseconds the power supply should be kept on for after the last high-power request.

void set_enable_time(uint32_t enable_time)

Set the time in milliseconds the power supply needs for power-up.

bool is_enabled() const

Is this power supply currently on?

void request_high_power()

Request high power mode. Use unrequest_high_power() to remove this request.

void unrequest_high_power()

Un-request high power mode.

void setup()

Register callbacks.

void dump_config()
float get_setup_priority() const

Hardware setup priority (+1).

uint32_t get_keep_on_time() const

Get the keep on time.

uint32_t get_enable_time() const

Get the enable time.

Protected Attributes

GPIOPin *pin_
bool enabled_ = {false}
uint32_t enable_time_
uint32_t keep_on_time_
int16_t active_requests_ = {0}