gobot.io/x/gobot/v2@v2.1.0/drivers/aio/grove_drivers.go (about)

     1  package aio
     2  
     3  import (
     4  	"time"
     5  )
     6  
     7  // GroveRotaryDriver represents an analog rotary dial with a Grove connector
     8  type GroveRotaryDriver struct {
     9  	*AnalogSensorDriver
    10  }
    11  
    12  // NewGroveRotaryDriver returns a new GroveRotaryDriver with a polling interval of
    13  // 10 Milliseconds given an AnalogReader and pin.
    14  //
    15  // Optionally accepts:
    16  // 	time.Duration: Interval at which the AnalogSensor is polled for new information
    17  //
    18  // Adds the following API Commands:
    19  // 	"Read" - See AnalogSensor.Read
    20  func NewGroveRotaryDriver(a AnalogReader, pin string, v ...time.Duration) *GroveRotaryDriver {
    21  	return &GroveRotaryDriver{
    22  		AnalogSensorDriver: NewAnalogSensorDriver(a, pin, v...),
    23  	}
    24  }
    25  
    26  // GroveLightSensorDriver represents an analog light sensor
    27  // with a Grove connector
    28  type GroveLightSensorDriver struct {
    29  	*AnalogSensorDriver
    30  }
    31  
    32  // NewGroveLightSensorDriver returns a new GroveLightSensorDriver with a polling interval of
    33  // 10 Milliseconds given an AnalogReader and pin.
    34  //
    35  // Optionally accepts:
    36  // 	time.Duration: Interval at which the AnalogSensor is polled for new information
    37  //
    38  // Adds the following API Commands:
    39  // 	"Read" - See AnalogSensor.Read
    40  func NewGroveLightSensorDriver(a AnalogReader, pin string, v ...time.Duration) *GroveLightSensorDriver {
    41  	return &GroveLightSensorDriver{
    42  		AnalogSensorDriver: NewAnalogSensorDriver(a, pin, v...),
    43  	}
    44  }
    45  
    46  // GrovePiezoVibrationSensorDriver represents an analog vibration sensor
    47  // with a Grove connector
    48  type GrovePiezoVibrationSensorDriver struct {
    49  	*AnalogSensorDriver
    50  }
    51  
    52  // NewGrovePiezoVibrationSensorDriver returns a new GrovePiezoVibrationSensorDriver with a polling interval of
    53  // 10 Milliseconds given an AnalogReader and pin.
    54  //
    55  // Optionally accepts:
    56  // 	time.Duration: Interval at which the AnalogSensor is polled for new information
    57  //
    58  // Adds the following API Commands:
    59  // 	"Read" - See AnalogSensor.Read
    60  func NewGrovePiezoVibrationSensorDriver(a AnalogReader, pin string, v ...time.Duration) *GrovePiezoVibrationSensorDriver {
    61  	sensor := &GrovePiezoVibrationSensorDriver{
    62  		AnalogSensorDriver: NewAnalogSensorDriver(a, pin, v...),
    63  	}
    64  
    65  	sensor.AddEvent(Vibration)
    66  
    67  	sensor.On(sensor.Event(Data), func(data interface{}) {
    68  		if data.(int) > 1000 {
    69  			sensor.Publish(sensor.Event(Vibration), data)
    70  		}
    71  	})
    72  
    73  	return sensor
    74  }
    75  
    76  // GroveSoundSensorDriver represents a analog sound sensor
    77  // with a Grove connector
    78  type GroveSoundSensorDriver struct {
    79  	*AnalogSensorDriver
    80  }
    81  
    82  // NewGroveSoundSensorDriver returns a new GroveSoundSensorDriver with a polling interval of
    83  // 10 Milliseconds given an AnalogReader and pin.
    84  //
    85  // Optionally accepts:
    86  // 	time.Duration: Interval at which the AnalogSensor is polled for new information
    87  //
    88  // Adds the following API Commands:
    89  // 	"Read" - See AnalogSensor.Read
    90  func NewGroveSoundSensorDriver(a AnalogReader, pin string, v ...time.Duration) *GroveSoundSensorDriver {
    91  	return &GroveSoundSensorDriver{
    92  		AnalogSensorDriver: NewAnalogSensorDriver(a, pin, v...),
    93  	}
    94  }