diff options
author | Jonas Smedegaard <dr@jones.dk> | 2025-04-08 22:04:59 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2025-04-08 22:04:59 +0200 |
commit | 8a1e160ba0dc6f8153f6ee4aa8566c2622cbe331 (patch) | |
tree | 72ff20b2eea80606977aa4398b987fbaf6a2e918 /Mussel | |
parent | f1812174d8d3d2feae7639d2c00273c2bb705e48 (diff) |
read as type int (not byte)
Diffstat (limited to 'Mussel')
-rw-r--r-- | Mussel/Mussel.cpp | 39 | ||||
-rw-r--r-- | Mussel/Mussel.h | 2 |
2 files changed, 19 insertions, 22 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 diff --git a/Mussel/Mussel.h b/Mussel/Mussel.h index bdc2be8..ba063c2 100644 --- a/Mussel/Mussel.h +++ b/Mussel/Mussel.h @@ -50,7 +50,7 @@ class Mussel { void begin(); String desc(); - byte read(); + int read(); String debug(); bool push(String id, unsigned long timestamp, int measure); void printStack(); |