farmbot v6.0.1-alpha Farmbot.Firmware.StubHandler View Source

Stubs out firmware functionality when you don’t have an arduino.

Link to this section Summary

Functions

Calibrate an axis

Lock the firmware

Unlock the firmware

Find home on an axis

Invoked on :producer stages

Invoked when the server is started

Move to a position

Read a paramater

Start a firmware handler

Manually set an axis’s current position to zero

Link to this section Functions

Link to this function calibrate(handler, axis) View Source

Calibrate an axis.

Callback implementation for Farmbot.Firmware.Handler.calibrate/2.

Lock the firmware.

Callback implementation for Farmbot.Firmware.Handler.emergency_lock/1.

Link to this function emergency_unlock(handler) View Source

Unlock the firmware.

Callback implementation for Farmbot.Firmware.Handler.emergency_unlock/1.

Link to this function find_home(handler, axis) View Source

Find home on an axis.

Callback implementation for Farmbot.Firmware.Handler.find_home/2.

Link to this function handle_demand(amnt, state) View Source

Invoked on :producer stages.

This callback is invoked on :producer stages with the demand from consumers/dispatcher. The producer that implements this callback must either store the demand, or return the amount of requested events.

Must always be explicitly implemented by :producer stages.

Examples

def handle_demand(demand, state) do
  # We check if we're able to satisfy the demand and fetch
  # events if we aren't.
  events =
    if length(state.events) >= demand do
      state.events
    else
      # fetch_events()
    end

  # We dispatch only the requested number of events.
  {to_dispatch, remaining} = Enum.split(events, demand)

  {:noreply, to_dispatch, %{state | events: remaining}}
end

Callback implementation for GenStage.handle_demand/2.

Invoked when the server is started.

start_link/3 (or start/3) will block until this callback returns. args is the argument term (second argument) passed to start_link/3 (or start/3).

In case of successful start, this callback must return a tuple where the first element is the stage type, which is one of:

  • :producer
  • :consumer
  • :producer_consumer (if the stage is acting as both)

For example:

def init(args) do
  {:producer, some_state}
end

The returned tuple may also contain 3 or 4 elements. The third element may be the :hibernate atom or a set of options defined below.

Returning :ignore will cause start_link/3 to return :ignore and the process will exit normally without entering the loop or calling terminate/2.

Returning {:stop, reason} will cause start_link/3 to return {:error, reason} and the process to exit with reason reason without entering the loop or calling terminate/2.

Options

This callback may return options. Some options are specific to the chosen stage type while others are shared across all types.

:producer options

  • :demand - when :forward, the demand is always forwarded to the c:handle_demand/2 callback. When :accumulate, demand is accumulated until its mode is set to :forward via demand/2. This is useful as a synchronization mechanism, where the demand is accumulated until all consumers are subscribed. Defaults to :forward.

:producer and :producer_consumer options

  • :buffer_size - the size of the buffer to store events without demand. Can be :infinity to signal no limit on the buffer size. Check the “Buffer events” section of the module documentation. Defaults to 10_000 for :producer, :infinity for :producer_consumer.

  • :buffer_keep - returns whether the :first or :last entries should be kept on the buffer in case the buffer size is exceeded. Defaults to :last.

  • :dispatcher - the dispatcher responsible for handling demands. Defaults to GenStage.DemandDispatch. May be either an atom representing a dispatcher module or a two-element tuple with the dispatcher module and the dispatcher options.

:consumer and :producer_consumer options

  • :subscribe_to - a list of producers to subscribe to. Each element represents either the producer module or a tuple with the producer module and the subscription options (as defined in sync_subscribe/2).

Callback implementation for GenStage.init/1.

Link to this function move_absolute(handler, pos) View Source

Move to a position.

Callback implementation for Farmbot.Firmware.Handler.move_absolute/2.

Link to this function read_param(handler, param) View Source

Read a paramater.

Callback implementation for Farmbot.Firmware.Handler.read_param/2.

Link to this function read_pin(handler, pin, pin_mode) View Source

Read a pin.

Callback implementation for Farmbot.Firmware.Handler.read_pin/3.

Start a firmware handler.

Callback implementation for Farmbot.Firmware.Handler.start_link/0.

Link to this function update_param(handler, param, val) View Source

Update a paramater.

Callback implementation for Farmbot.Firmware.Handler.update_param/3.

Link to this function write_pin(handler, pin, pin_mode, value) View Source

Write a pin.

Callback implementation for Farmbot.Firmware.Handler.write_pin/4.

Manually set an axis’s current position to zero.

Callback implementation for Farmbot.Firmware.Handler.zero/2.