gobot.io/x/gobot/v2@v2.1.0/drivers/i2c/mfrc522_driver.go (about) 1 package i2c 2 3 import ( 4 "gobot.io/x/gobot/v2/drivers/common/mfrc522" 5 ) 6 7 const mfrc522DefaultAddress = 0x00 8 9 // MFRC522Driver is a wrapper for i2c bus usage. Please refer to the mfrc522.MFRC522Common package 10 // for implementation details. 11 type MFRC522Driver struct { 12 *Driver 13 *mfrc522.MFRC522Common 14 } 15 16 // NewMFRC522Driver creates a new Gobot Driver for MFRC522 RFID with i2c connection 17 // 18 // Params: 19 // 20 // c Connector - the Adaptor to use with this Driver 21 // 22 // Optional params: 23 // 24 // i2c.WithBus(int): bus to use with this driver 25 // i2c.WithAddress(int): address to use with this driver 26 func NewMFRC522Driver(c Connector, options ...func(Config)) *MFRC522Driver { 27 d := &MFRC522Driver{ 28 Driver: NewDriver(c, "MFRC522", mfrc522DefaultAddress), 29 } 30 d.MFRC522Common = mfrc522.NewMFRC522Common() 31 d.afterStart = d.initialize 32 for _, option := range options { 33 option(d) 34 } 35 return d 36 } 37 38 func (d *MFRC522Driver) initialize() error { 39 return d.MFRC522Common.Initialize(d.connection) 40 }