diff options
Diffstat (limited to 'Mussel/Mussel.cpp')
-rw-r--r-- | Mussel/Mussel.cpp | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/Mussel/Mussel.cpp b/Mussel/Mussel.cpp index 1d5c2b0..a05f329 100644 --- a/Mussel/Mussel.cpp +++ b/Mussel/Mussel.cpp @@ -130,9 +130,9 @@ String Mussel::desc() { /// * Values 100-254 are reserved for future use /// * Value 255 is an internal error /// -/// @return relative gape size as value 0-255 encoded as byte -byte Mussel::read() { - byte _byte; +/// @return relative gape size as value 0-255 encoded as int +int Mussel::read() { + int _read; switch(_attitude) { case 1: @@ -140,7 +140,7 @@ byte Mussel::read() { // TODO: account for rollover or (millis() - _time) > MUSSEL_NORMAL_PACE * 1000 ) { - _byte = 2; + _read = 2; _boolState = HIGH; // reset timer @@ -148,7 +148,7 @@ byte Mussel::read() { } else if (_boolState == HIGH and (millis() - _time) > MUSSEL_STRESS_PACE * 1000 ) { - _byte = 42; + _read = 42; _boolState = LOW; // reset timer @@ -157,26 +157,23 @@ byte Mussel::read() { break; case 2: // 42 if current second modulo 12 is below 9, else 2 - _byte = static_cast<byte>( - (static_cast<unsigned long>(millis() / 1000) % 12) < 9 + _read = (static_cast<unsigned long>(millis() / 1000) % 12) < 9 ? 42 - : 2); + : 2; break; case 3: #ifdef DHT_H // temperature in Celsius - _byte = static_cast<byte>( - mussel_dht.readTemperature()); + _read = mussel_dht.readTemperature(); #else - _byte = 255; + _read = 255; #endif break; case 4: // 2 if button is pressed, else 42 - _byte = static_cast<byte>( - digitalRead(_pin) == HIGH + _read = digitalRead(_pin) == HIGH ? 2 - : 42); + : 42; break; case 5: { bool _reading = digitalRead(_pin); // Read button state @@ -195,10 +192,10 @@ byte Mussel::read() { _count = 0; // Reset cycle after 3 clicks } switch (_count) { - case 1: _byte = 2; break; // State: Angry - case 2: _byte = 42; break; // State: Happy - case 3: _byte = 15; break; // State: Unsure - case 0: _byte = 99; break; // State: Off + case 1: _read = 2; break; // State: Angry + case 2: _read = 42; break; // State: Happy + case 3: _read = 15; break; // State: Unsure + case 0: _read = 99; break; // State: Off } } } @@ -218,16 +215,16 @@ byte Mussel::read() { _boolState = LOW; } } - _byte = _boolState == HIGH + _read = _boolState == HIGH ? 42 : 2; break; default: - _byte = 255; + _read = 255; break; } - return _byte; + return _read; } /// Function to push data onto the stack |