From 81b412a40ad92e2e0f1f070fc588fc56f0970aec Mon Sep 17 00:00:00 2001
From: Kevin Lyda <kevin@ie.suberic.net>
Date: Mon, 30 Jan 2017 09:37:33 +0000
Subject: [PATCH] Implement GetCPS.

---
 devices/geiger/gqgmc.go | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/devices/geiger/gqgmc.go b/devices/geiger/gqgmc.go
index 07b1031..1200de1 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
-- 
GitLab