From 75b1480cb38e21c9de534808fd4af8a3799eddb4 Mon Sep 17 00:00:00 2001 From: bpds Date: Thu, 28 Dec 2023 14:13:14 +0100 Subject: [PATCH] Sensitivity String returns a human readable value --- adxl345/adxl345.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/adxl345/adxl345.go b/adxl345/adxl345.go index 81f1741..f7542f4 100644 --- a/adxl345/adxl345.go +++ b/adxl345/adxl345.go @@ -85,7 +85,7 @@ type Dev struct { } func (d *Dev) String() string { - return fmt.Sprintf("ADXL345{Sensitivity:%d}", d.sensitivity) + return fmt.Sprintf("ADXL345{Sensitivity:%s}", d.sensitivity) } // New creates a new ADXL345 Dev or returns an error. @@ -213,3 +213,18 @@ type Acceleration struct { func (a Acceleration) String() string { return fmt.Sprintf("X:%d Y:%d Z:%d", a.X, a.Y, a.Z) } + +func (s Sensitivity) String() string { + switch s { + case S2G: + return "+/-2g" + case S4G: + return "+/-4g" + case S8G: + return "+/-8g" + case S16G: + return "+/-16g" + default: + return "unsupported" + } +}