pulseacceptor

package module
v0.0.0-...-50c8257 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

README

pulseacceptor

This component is for coin acceptors and bill acceptors that use the pulse interface.

pulseacceptor.go contains a small library for counting pulses from a GPIO pin. The input is denoised and debounced.
cmd/pulse-watcher contains a program for checking the pulse and pause widths sent by the device.
cmd/pulseacceptord is a daemon that counts pulses, translates them into monetary values and sends this information to the MQTT broker.

Debugging and finding config parameters using pulse-watcher

pulse-watcher is an useful program that prints widths of each pulse and pause. Upon exiting it also prints averages for both. You can use it to figure out values for debounce and denoise parameters for pulseacceptord.

Example usage:

# Listen on GPIO pin 17 for pulses, if no pulses follow after 101 milliseconds
# ignore this pause because pulses for this bill/coin has ended.
pulse-watcher -pin 17 -timeout 101ms

Handling coins/cash with pulseacceptord

pulseacceptord denoises and debounces the pulses to prevent noise. After it is done counting pulses for a single bill/coin, it sends the event in JSON format to MQTT for queueing.

Change the values inside config.yaml before running.

denoise: Should be set to the pulse width. Although you might want to add or deduct a very little amount from this value to allow for some error. Pulse widths smaller than this value will be ignored.

debounce: Should be set to the pause width. Again, tune this value for possible errors like you should do for the denoise parameter. After a valid pulse (with width longer than the denoise parameter) has been received, more pulses will be ignored for the debounce amount. Meaning repeated pulses within debounce duration are ignored.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PinNotFound = errors.New("Pin not found")

Functions

This section is empty.

Types

type PulseAcceptorConfig

type PulseAcceptorConfig struct {
	// The pulse pin.
	PulsePin string `yaml:"pulse_pin"`

	// The duration of pause width. You might want to add up an error margin on top of this value.
	Debounce time.Duration

	// The duration of pulse width. You might want to add up an error margin on top of this value.
	Denoise time.Duration

	// After how long of a pause, consider counting for this coin/bill done.
	Timeout time.Duration

	// Edge poll frequency
	Freq int `yaml:"poll_frequency"`

	// Print pulse and pause width/count logs
	Debug bool
}

type PulseAcceptorDevice

type PulseAcceptorDevice struct {
	gpio.PinIO

	// Marks end of coin or bill insertion.
	Timeout time.Duration
	// contains filtered or unexported fields
}

func Init

Returns a new device with a denoised and debounced input pin.

func (*PulseAcceptorDevice) Count

func (d *PulseAcceptorDevice) Count() (pulses int64)

Count pulses and return whenever the current wave of pulses ends. The debounce duration is used as the timeout value.

func (*PulseAcceptorDevice) CountWithHandler

func (d *PulseAcceptorDevice) CountWithHandler(ch chan<- int64)

Count pulses and shove them down a channel when activity occurs.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL