From 2a9fb81a3feb58eef54314d6645d70f22fb6ca03 Mon Sep 17 00:00:00 2001 From: Johannes Hubertz Date: Fri, 2 Aug 2019 22:55:27 +0200 Subject: [PATCH] Ensure arduino-mk can handle the i2cEncoderLibV2 Circumvent some errors and warnings when using arduino-mk on Debian GNU/Linux --- src/i2cEncoderLibV2.cpp | 15 ++++++++++++--- src/i2cEncoderLibV2.h | 10 +++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/i2cEncoderLibV2.cpp b/src/i2cEncoderLibV2.cpp index 73a7096..3a88f00 100644 --- a/src/i2cEncoderLibV2.cpp +++ b/src/i2cEncoderLibV2.cpp @@ -19,13 +19,22 @@ /** Class costructor **/ i2cEncoderLibV2::i2cEncoderLibV2(uint8_t add) { _add = add; + // ensure defined values + _stat = 0x00; + _stat2 = 0x00; + _gconf = 0x00; } /** Used for initialize the encoder **/ void i2cEncoderLibV2::begin(uint16_t conf) { + uint8_t temp; + + temp = (uint8_t) conf & 0xff; + writeEncoder(REG_GCONF, temp); + + temp = (uint8_t) (conf >> 8) & 0xff; + writeEncoder(REG_GCONF, temp); - writeEncoder(REG_GCONF, (uint8_t) conf & 0xFF); - writeEncoder(REG_GCONF2, (uint8_t)(conf >> 8) & 0xFF); _gconf = conf; if ((conf & CLK_STRECH_ENABLE) == 0) _clockstreach = 0; @@ -326,7 +335,7 @@ void i2cEncoderLibV2::writeInterruptConfig(uint8_t interrupt) { /** Check if there is some attached callback and enable the corresponding interrupt **/ void i2cEncoderLibV2::autoconfigInterrupt(void) { - uint8_t reg; + uint8_t reg = 0; if (onButtonRelease != NULL) reg |= PUSHR; diff --git a/src/i2cEncoderLibV2.h b/src/i2cEncoderLibV2.h index a6b875c..0c81d31 100644 --- a/src/i2cEncoderLibV2.h +++ b/src/i2cEncoderLibV2.h @@ -162,7 +162,7 @@ class i2cEncoderLibV2 { uint8_t bval[4]; }; - uint8_t id = 0x00; + uint8_t id; // = 0x00; typedef void (*Callback)(i2cEncoderLibV2*); /* Event */ @@ -294,10 +294,10 @@ class i2cEncoderLibV2 { private: uint8_t _clockstreach; - uint8_t _add = 0x00; - uint8_t _stat = 0x00; - uint8_t _stat2 = 0x00; - uint8_t _gconf = 0x00; + uint8_t _add ; // = 0x00; + uint8_t _stat ; // = 0x00; + uint8_t _stat2 ; // = 0x00; + uint8_t _gconf ; // = 0x00; union Data_v _tem_data; void eventCaller(Callback *event);