polling

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2025 License: LGPL-3.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoTagInPoll = errors.New("no tag detected in polling cycle")

ErrNoTagInPoll indicates no tag was detected during polling (not an error condition)

Functions

This section is empty.

Types

type CardDetectionState

type CardDetectionState int

CardDetectionState represents the finite state machine for card detection

const (
	StateIdle CardDetectionState = iota
	StateTagDetected
	StateReading
	StatePostReadGrace
)

type CardState

type CardState struct {
	LastSeenTime   time.Time
	ReadStartTime  time.Time
	RemovalTimer   *time.Timer
	LastUID        string
	LastType       string
	TestedUID      string
	DetectionState CardDetectionState
	Present        bool
}

CardState tracks the state of a card on a reader

func (*CardState) CanStartRemovalTimer

func (cs *CardState) CanStartRemovalTimer() bool

CanStartRemovalTimer returns true if the state allows removal timer to run

func (*CardState) TransitionToDetected

func (cs *CardState) TransitionToDetected(timeout time.Duration, callback func())

TransitionToDetected moves to tag detected state with normal removal timeout

func (*CardState) TransitionToIdle

func (cs *CardState) TransitionToIdle()

TransitionToIdle resets to idle state

func (*CardState) TransitionToPostReadGrace

func (cs *CardState) TransitionToPostReadGrace(timeout time.Duration, callback func())

TransitionToPostReadGrace moves to post-read grace period with short timeout

func (*CardState) TransitionToReading

func (cs *CardState) TransitionToReading()

TransitionToReading moves to reading state and suspends removal timer

type Config

type Config struct {
	PollInterval       time.Duration
	CardRemovalTimeout time.Duration
}

Config holds polling configuration options

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default polling configuration

type Monitor

type Monitor struct {
	OnCardDetected func(tag *pn532.DetectedTag) error
	OnCardRemoved  func()
	OnCardChanged  func(tag *pn532.DetectedTag) error
	// contains filtered or unexported fields
}

Monitor handles continuous card monitoring with state machine

func NewMonitor

func NewMonitor(device *pn532.Device, config *Config) *Monitor

NewMonitor creates a new card monitor

func (*Monitor) Close

func (m *Monitor) Close() error

Close cleans up the monitor resources

func (*Monitor) GetDevice

func (m *Monitor) GetDevice() *pn532.Device

GetDevice returns the underlying PN532 device

func (*Monitor) GetState

func (m *Monitor) GetState() CardState

GetState returns the current card state

func (*Monitor) Start

func (m *Monitor) Start(ctx context.Context) error

Start begins continuous monitoring for cards

Jump to

Keyboard shortcuts

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