Documentation
¶
Index ¶
- Variables
- type CardDetectionState
- type CardState
- func (cs *CardState) CanStartRemovalTimer() bool
- func (cs *CardState) TransitionToDetected(timeout time.Duration, callback func())
- func (cs *CardState) TransitionToIdle()
- func (cs *CardState) TransitionToPostReadGrace(timeout time.Duration, callback func())
- func (cs *CardState) TransitionToReading()
- type Config
- type DeviceActor
- type DeviceCallbacks
- type DeviceMetrics
- type Session
- func (s *Session) Close() error
- func (s *Session) GetDevice() *pn532.Device
- func (s *Session) GetDeviceActor() *DeviceActor
- func (s *Session) GetState() CardState
- func (s *Session) Pause()
- func (s *Session) Resume()
- func (s *Session) Start(ctx context.Context) error
- func (s *Session) WriteToNextTag(sessionCtx context.Context, writeCtx context.Context, timeout time.Duration, ...) error
- func (s *Session) WriteToTag(sessionCtx context.Context, writeCtx context.Context, ...) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
CanStartRemovalTimer returns true if the state allows removal timer to run
func (*CardState) TransitionToDetected ¶
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 ¶
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
// HardwareTimeoutRetries controls how long PN532 waits for card detection
// 0x00 = immediate return, 0x01-0xFE = retry count (~150ms each), 0xFF = infinite
// Higher values reduce LED blinking frequency but increase detection latency
HardwareTimeoutRetries byte
}
Config holds polling configuration options
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns the default polling configuration
type DeviceActor ¶ added in v0.5.0
type DeviceActor struct {
// contains filtered or unexported fields
}
DeviceActor minimal implementation to make the test pass
func NewDeviceActor ¶ added in v0.5.0
func NewDeviceActor(device *pn532.Device, config *Config, callbacks DeviceCallbacks) *DeviceActor
NewDeviceActor creates a new device actor (minimal implementation to pass test)
func (*DeviceActor) GetCurrentPollInterval ¶ added in v0.5.0
func (da *DeviceActor) GetCurrentPollInterval() time.Duration
GetCurrentPollInterval returns the current adaptive polling interval
func (*DeviceActor) GetMetrics ¶ added in v0.5.0
func (da *DeviceActor) GetMetrics() DeviceMetrics
GetMetrics returns current operational metrics
type DeviceCallbacks ¶ added in v0.5.0
type DeviceCallbacks struct {
OnCardDetected func(tag *pn532.DetectedTag) error
OnCardRemoved func()
OnCardChanged func(tag *pn532.DetectedTag) error
}
DeviceCallbacks defines callback functions for device events
type DeviceMetrics ¶ added in v0.5.0
type DeviceMetrics struct {
PollCycles int64 // Total number of polling cycles
PollErrors int64 // Number of polling errors
CardsDetected int64 // Number of cards detected
CallbackErrors int64 // Number of callback errors
LastPollLatency time.Duration // Duration of last polling operation
}
DeviceMetrics tracks operational metrics for DeviceActor
type Session ¶ added in v0.5.0
type Session struct {
OnCardDetected func(tag *pn532.DetectedTag) error
OnCardRemoved func()
OnCardChanged func(tag *pn532.DetectedTag) error
// contains filtered or unexported fields
}
Session handles continuous card monitoring with state machine
func NewActorBasedSession ¶ added in v0.5.0
NewActorBasedSession creates a session using DeviceActor underneath
func NewSession ¶ added in v0.5.0
NewSession creates a new card monitoring session
func (*Session) GetDeviceActor ¶ added in v0.5.0
func (s *Session) GetDeviceActor() *DeviceActor
GetDeviceActor returns the underlying DeviceActor for actor-based sessions
func (*Session) Pause ¶ added in v0.5.0
func (s *Session) Pause()
Pause temporarily stops the polling loop This is used to coordinate with write operations
func (*Session) Resume ¶ added in v0.5.0
func (s *Session) Resume()
Resume restarts the polling loop after a pause
func (*Session) WriteToNextTag ¶ added in v0.5.0
func (s *Session) WriteToNextTag( sessionCtx context.Context, writeCtx context.Context, timeout time.Duration, writeFn func(context.Context, pn532.Tag) error, ) error
WriteToNextTag waits for the next tag detection and performs a write operation This method blocks until a tag is detected or timeout occurs sessionCtx controls session lifetime, writeCtx controls write operation lifetime
func (*Session) WriteToTag ¶ added in v0.5.0
func (s *Session) WriteToTag( sessionCtx context.Context, writeCtx context.Context, detectedTag *pn532.DetectedTag, writeFn func(context.Context, pn532.Tag) error, ) error
WriteToTag performs a thread-safe write operation to a detected tag This method pauses polling during the write to prevent interference sessionCtx controls session lifetime, writeCtx controls write operation lifetime