Skip to content

reef-pi/hal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

0bb4bbd · Dec 30, 2024

History

24 Commits
Aug 1, 2021
Dec 6, 2018
Oct 3, 2019
Dec 30, 2024
Jan 29, 2019
Dec 30, 2024
Sep 25, 2022
Jan 29, 2019
Jan 29, 2019
Oct 3, 2019
Feb 26, 2020
Sep 25, 2022
Oct 3, 2019
Sep 25, 2022
Oct 3, 2019

Repository files navigation

reef-pi - Hardware Abstraction Layer

Build Status Go Report Card License GoDoc

Introduction

The hal package provide common types for hardware capabilities in reef-pi. It hides device specific details from the controller logic. reef-pi modules like ATO, and pH, uses hal interfaces to perform hardware based operations. The HAL interfaces cover metdata and methods for digital or analog I/O. Check out reef-pi/drivers for examples.

'hal' is mostly made of interfaces and void of business logic and or dependency package. A No-Op or null driver is included to ease testing.

Usage

import(
  "github.com/reef-pi/hal"
)

func main() {
  var d hal.Driver = hal.NewNoopDriver()
  d.Metadata()
  defer d.Close()

  input, _ := d.(hal.InputDriver)
  pin, _ := input.InputPin("GP4")
  v, _ := pin.Read()
  for _, pin := range input.InputPins() {
    fmt.Println(pin.Name())
  }

  output, _ := d.(hal.OutputDriver)
  pin, _ := output.OutputPin("GP4")
  pin.Write(false)

  var pwm PWMDriver = hal.NewNoopDrive()
  ch, _ := pwm.PWMChannel("foo")
  ch.Set(10.23)
  for _, ch := range pwm.PWMChannels() {
     fmt.Println(ch.Name())
  }
}