Skip to content
Snippets Groups Projects
Commit 81b412a4 authored by Kevin Lyda's avatar Kevin Lyda :speech_balloon:
Browse files

Implement GetCPS.

parent 71f90a58
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment