Exemplo n.º 1
0
// 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
}
Exemplo n.º 2
0
// 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)
}
Exemplo n.º 3
0
// 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
}
Exemplo n.º 4
0
// 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
}
Exemplo n.º 5
0
// Waits for the touch sensor to be pressed.
func (self *TouchSensor) Wait() {
	snr := findSensor(self.port, TypeTouch)
	path := fmt.Sprintf("/sys/class/msensor/%s", snr)

	for {
		value := utilities.ReadUInt8Value(path, "value0")

		if value == 1 {
			return
		}

		time.Sleep(time.Millisecond * 50)
	}
}
Exemplo n.º 6
0
// Returns the current system volume in range [0, 100].
func CurrentVolume() uint8 {
	return utilities.ReadUInt8Value("/sys/devices/platform/snd-legoev3", "volume")
}