// Reads the ambient light intensity in range [0, 100]. func (self *ColorSensor) ReadAmbientLightIntensity() uint8 { snr := findSensor(self.port, TypeColor) path := fmt.Sprintf("/sys/class/msensor/%s", snr) utilities.WriteStringValue(path, "mode", "COL-AMBIENT") value := utilities.ReadUInt8Value(path, "value0") return value }
// Reads one of seven color values. func (self *ColorSensor) ReadColor() Color { snr := findSensor(self.port, TypeColor) path := fmt.Sprintf("/sys/class/msensor/%s", snr) utilities.WriteStringValue(path, "mode", "COL-COLOR") value := utilities.ReadUInt8Value(path, "value0") return Color(value) }
// Reads the distance (in centimeters) reported by the ultrasonic sensor. func (self *UltrasonicSensor) ReadDistance() uint16 { snr := findSensor(self.port, TypeUltrasonic) path := fmt.Sprintf("/sys/class/msensor/%s", snr) utilities.WriteStringValue(path, "mode", "US-SI-CM") value := utilities.ReadUInt16Value(path, "value0") return (value / 10) }
// Reads the proximity value (in range 0 - 100) reported by the infrared sensor. A value of 100 corresponds to a range of approximately 70 cm. func (self *InfraredSensor) ReadProximity() uint8 { snr := findSensor(self.port, TypeInfrared) path := fmt.Sprintf("/sys/class/msensor/%s", snr) utilities.WriteStringValue(path, "mode", "IR-PROX") value := utilities.ReadUInt8Value(path, "value0") return value }
// Looks for other nearby ultrasonic sensors and returns true if one is found. func (self *UltrasonicSensor) Listen() bool { snr := findSensor(self.port, TypeUltrasonic) path := fmt.Sprintf("/sys/class/msensor/%s", snr) utilities.WriteStringValue(path, "mode", "US-LISTEN") value := utilities.ReadUInt8Value(path, "value0") if value == 1 { return true } return false }
// Disables brake mode, causing the motor at the given port to coast to stops. Brake mode is off by default. func DisableBrakeMode(port OutPort) { utilities.WriteStringValue(findFilename(port), "brake_mode", "off") }
// Disables regulation mode. Regulation mode is off by default. func DisableRegulationMode(port OutPort) { utilities.WriteStringValue(findFilename(port), "regulation_mode", "off") }