Skip to content

Conversation

@jimsynz
Copy link
Contributor

@jimsynz jimsynz commented Dec 20, 2025

Summary

  • Add BB.Controller, BB.Sensor, and BB.Bridge behaviours with optional options_schema/0 callbacks
  • Extend BB.Actuator with the same pattern
  • Each behaviour's __using__/1 macro now includes use GenServer, simplifying implementations
  • Add ValidateChildSpecs verifier for compile-time validation of child spec options against module schemas
  • Merge BB.Parameter.Protocol into BB.Bridge for a cleaner API
  • Move disarm/1 callback from BB.Safety to BB.Actuator and BB.Controller behaviours

Usage

defmodule MyActuator do
  use BB.Actuator,
    options_schema: [
      pin: [type: :pos_integer, required: true],
      frequency: [type: :pos_integer, default: 50]
    ]

  @impl BB.Actuator
  def disarm(opts), do: :ok

  @impl GenServer
  def init(opts), do: {:ok, opts}
end

For modules with complex schemas, define the callback explicitly:

defmodule MyController do
  use BB.Controller

  @impl BB.Controller
  def options_schema do
    Spark.Options.new!([...])
  end
end

Test plan

  • All 488 tests pass
  • Dialyzer passes
  • Credo passes
  • Updated servo driver packages compile against new API

Add `BB.Controller`, `BB.Sensor`, and `BB.Bridge` behaviours (and extend
`BB.Actuator`) with optional `options_schema/0` callbacks for compile-time
validation of GenServer configuration.

Key changes:

- Each behaviour's `__using__/1` macro now includes `use GenServer`
- Pass `options_schema: [...]` to auto-define the callback
- Callbacks are overridable with `defoverridable`
- Add `ValidateChildSpecs` verifier for compile-time option validation
- Merge `BB.Parameter.Protocol` into `BB.Bridge` (single behaviour)
- Move `disarm/1` callback from `BB.Safety` to `BB.Actuator`/`BB.Controller`

Usage example:

    defmodule MyActuator do
      use BB.Actuator,
        options_schema: [
          pin: [type: :pos_integer, required: true],
          frequency: [type: :pos_integer, default: 50]
        ]

      @impl BB.Actuator
      def disarm(opts), do: :ok

      @impl GenServer
      def init(opts), do: {:ok, opts}
    end
jimsynz added a commit to beam-bots/bb_servo_pigpio that referenced this pull request Dec 20, 2025
Remove explicit `use GenServer` as `use BB.Actuator` now provides it.

Requires bb >= 0.6.0 (beam-bots/bb#15)
jimsynz added a commit to beam-bots/bb_servo_pca9685 that referenced this pull request Dec 20, 2025
Remove explicit `use GenServer` as `use BB.Actuator` and `use BB.Controller`
now provide it.

Requires bb >= 0.6.0 (beam-bots/bb#15)
@jimsynz jimsynz merged commit 67b2c0c into main Dec 20, 2025
14 checks passed
@jimsynz jimsynz deleted the feature/genserver-behaviours branch December 20, 2025 01:40
jimsynz added a commit to beam-bots/bb_servo_pca9685 that referenced this pull request Dec 20, 2025
Remove explicit `use GenServer` as `use BB.Actuator` and `use BB.Controller`
now provide it.

Requires bb >= 0.6.0 (beam-bots/bb#15)
jimsynz added a commit to beam-bots/bb_servo_pigpio that referenced this pull request Dec 20, 2025
Remove explicit `use GenServer` as `use BB.Actuator` now provides it.

Requires bb >= 0.6.0 (beam-bots/bb#15)
jimsynz added a commit to beam-bots/bb_servo_pca9685 that referenced this pull request Dec 20, 2025
Remove explicit `use GenServer` as `use BB.Actuator` and `use BB.Controller`
now provide it.

Requires bb >= 0.6.0 (beam-bots/bb#15)
jimsynz added a commit to beam-bots/bb_servo_pigpio that referenced this pull request Dec 20, 2025
Remove explicit `use GenServer` as `use BB.Actuator` now provides it.

Requires bb >= 0.6.0 (beam-bots/bb#15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants