예제 #1
0
func (u *UltraEasy) GetAllReadingsCallback(cb func(u *UltraEasyReading)) error {
	var x C.struct_ultraeasy_record

	numReadings := C.ultraeasy_num_records(u.handler)
	if numReadings == 0 {
		return fmt.Errorf("No records found on device")
	}

	for n := 0; n <= int(numReadings); n++ {
		ret := C.ultraeasy_get_record(u.handler, C.uint(n), &x)
		if ret == 0 {
			cb(&UltraEasyReading{
				time:  time.Unix(int64(x.raw.date), 0),
				value: uint(x.raw.reading),
			})
		}
	}
	return nil
}
예제 #2
0
func (u *UltraEasy) GetAllReadings() ([]UltraEasyReading, error) {
	var x C.struct_ultraeasy_record
	var records []UltraEasyReading

	numReadings := C.ultraeasy_num_records(u.handler)

	if numReadings == 0 {
		return nil, fmt.Errorf("No records found on device")
	}

	for n := 0; n <= int(numReadings); n++ {
		ret := C.ultraeasy_get_record(u.handler, C.uint(n), &x)
		if ret == 0 {
			records = append(records, UltraEasyReading{
				time:  time.Unix(int64(x.raw.date), 0),
				value: uint(x.raw.reading),
			})
		}
	}

	return records, nil
}