summaryrefslogtreecommitdiff
path: root/Layout
diff options
context:
space:
mode:
authorLeon Lindenfelser <llindenfelser@multitech.com>2015-12-15 14:12:23 -0600
committerLeon Lindenfelser <llindenfelser@multitech.com>2015-12-15 14:12:23 -0600
commit4d9b71c83275f36834291c20fc4fddf3dfec89a7 (patch)
tree4876455254179c55371c11f3c6bb3eaa04c921e5 /Layout
parente78d2de28ec86d58a3a0330faadbfa595dcbd571 (diff)
downloadmtdot-box-evb-factory-firmware-4d9b71c83275f36834291c20fc4fddf3dfec89a7.tar.gz
mtdot-box-evb-factory-firmware-4d9b71c83275f36834291c20fc4fddf3dfec89a7.tar.bz2
mtdot-box-evb-factory-firmware-4d9b71c83275f36834291c20fc4fddf3dfec89a7.zip
Display accelerometer data in g force for demo mode.
Diffstat (limited to 'Layout')
-rw-r--r--Layout/LayoutDemoSampling.cpp49
1 files changed, 46 insertions, 3 deletions
diff --git a/Layout/LayoutDemoSampling.cpp b/Layout/LayoutDemoSampling.cpp
index 990e1e4..769d6b7 100644
--- a/Layout/LayoutDemoSampling.cpp
+++ b/Layout/LayoutDemoSampling.cpp
@@ -77,21 +77,64 @@ void LayoutDemoSampling::updateInterval(uint32_t seconds) {
void LayoutDemoSampling::updateAccelerationX(int16_t x) {
char buf[16];
size_t size;
- size = snprintf(buf, sizeof(buf), "%d", x);
+ float fx = (float)x;
+ fx /= 1024;
+ // We can only display 5 characters.
+ // For numbers < -1, we display -#.#g. For example -1.3g
+ if(fx < -1){
+ size = snprintf(buf, sizeof(buf), "%4.1fg", fx);
+ }
+ // For numbers > -1 and < 0, we display -.##g. For example -.13g
+ else if(fx < 0){
+ size = snprintf(buf, sizeof(buf), "%4.2fg", fx);
+ for(uint8_t i = 1; i < 5; i++ ){
+ buf[i] = buf[i+1];
+ }
+ }
+ // For numbers > 0, we display #.##g. For example 0.13g.
+ else{
+ size = snprintf(buf, sizeof(buf), "%4.2fg", fx);
+ }
writeField(_fAccx, buf, size, true);
}
void LayoutDemoSampling::updateAccelerationY(int16_t y) {
char buf[16];
size_t size;
- size = snprintf(buf, sizeof(buf), "%d", y);
+ float fy = (float)y;
+ fy /= 1024;
+ if(fy < -1){
+ size = snprintf(buf, sizeof(buf), "%4.1fg", fy);
+ }
+ else if(fy < 0){
+ size = snprintf(buf, sizeof(buf), "%4.2fg", fy);
+ for(uint8_t i = 1; i < 5; i++ ){
+ buf[i] = buf[i+1];
+ }
+ }
+ else{
+ size = snprintf(buf, sizeof(buf), "%4.2fg", fy);
+ }
writeField(_fAccy, buf, size, true);
}
void LayoutDemoSampling::updateAccelerationZ(int16_t z) {
char buf[16];
size_t size;
- size = snprintf(buf, sizeof(buf), "%d", z);
+ float fz = (float)z;
+ fz /= 1024;
+ if(fz < -1){
+ size = snprintf(buf, sizeof(buf), "%1.1fg", fz);
+ }
+ else if(fz < 0){
+ size = snprintf(buf, sizeof(buf), "%4.2fg", fz);
+ for(uint8_t i = 1; i < 5; i++ ){
+ buf[i] = buf[i+1];
+ }
+ }
+ else{
+ size = snprintf(buf, sizeof(buf), "%1.2fg", fz);
+ }
writeField(_fAccz, buf, size, true);
}