diff --git a/devices/geiger/gqgmc.go b/devices/geiger/gqgmc.go
index 07b1031de74d540537012dcbf32a9ff805bd3d5b..1200de166e7c4dfa93931aca2fb94696cdd923aa 100644
--- a/devices/geiger/gqgmc.go
+++ b/devices/geiger/gqgmc.go
@@ -190,27 +190,24 @@ func (gc *GQGMCCounter) SerialNum() (string, error) {
return "", nil
}
-// GetCPM returns CPM
-func (gc *GQGMCCounter) GetCPM() (uint16, error) {
- buf, err := gc.communicate([]byte(cmdGetCPM), 2)
+func (gc *GQGMCCounter) getReading(what string) (uint16, error) {
+ buf, err := gc.communicate([]byte(what), 2)
if err != nil {
return 0, err
}
- cpm := ((uint16(buf[0]) << 8) & 0x3f00)
- cpm |= (uint16(buf[1]) & 0x00ff)
- return cpm, nil
+ reading := ((uint16(buf[0]) << 8) & 0x3f00)
+ reading |= (uint16(buf[1]) & 0x00ff)
+ return reading, nil
+}
+
+// GetCPM returns CPM
+func (gc *GQGMCCounter) GetCPM() (uint16, error) {
+ return gc.getReading(cmdGetCPM)
}
// GetCPS returns CPS
func (gc *GQGMCCounter) GetCPS() (uint16, error) {
- //uint32_t cpssize = 2; // 2 bytes of returned data
- //communicate(get_cps_cmd, cps_char, cpssize);
- // 1st byte is MSB, but note that upper two bits are reserved bits.
- // Note that shifting and bitmasking performed in uP register, so
- // endianess is irrevelant.
- //cps_int |= ((uint16_t(cps_char[0]) << 8) & 0x3f00);
- //cps_int |= (uint16_t(cps_char[1]) & 0x00ff);
- return 0, nil
+ return gc.getReading(cmdGetCPM)
}
// GetVoltage returns current battery voltage