GY-63_MS5611/libraries/Troolean
2024-04-13 10:35:57 +02:00
..
.github bulk update GitHub actions 2024-04-13 10:35:57 +02:00
examples 0.1.5 Troolean 2021-12-29 13:05:17 +01:00
test 0.1.5 Troolean 2021-12-29 13:05:17 +01:00
.arduino-ci.yml 0.1.6 Troolean 2022-11-26 16:50:57 +01:00
CHANGELOG.md 0.1.8 Troolean 2023-11-23 13:46:31 +01:00
keywords.txt 0.1.5 Troolean 2021-12-29 13:05:17 +01:00
library.json 0.1.8 Troolean 2023-11-23 13:46:31 +01:00
library.properties 0.1.8 Troolean 2023-11-23 13:46:31 +01:00
LICENSE bulk update GitHub actions 2024-04-13 10:35:57 +02:00
README.md 0.1.8 Troolean 2023-11-23 13:46:31 +01:00
Troolean.cpp 0.1.8 Troolean 2023-11-23 13:46:31 +01:00
Troolean.h 0.1.8 Troolean 2023-11-23 13:46:31 +01:00

Arduino CI Arduino-lint JSON check GitHub issues

License: MIT GitHub release PlatformIO Registry

Troolean

Arduino Library for a three state logic data type supporting {True False Unknown}.

Description

Troolean is a data type that implements three state logic with the values {True False Unknown }

Logic operators are similar to boolean and behave the same for the familiar boolean values.

Trooleans can be used e.g. to indicate a value is valid, invalid or unknown to be valid or not. Imagine a monitoring application which has different sensors e.g. temperature. If the sensor is sampled less than 1 minute ago one could say the value is valid. If the last sample is taken more than an hour ago it could have changed (a lot) or not. So one does not know if the temperature has become invalid or not. Boolean logic would make it invalid, but troolean allows to state we just don't know. As long as there is no urgency (need a valid value) one does not need to resample yet.

See also https://en.wikipedia.org/wiki/Three-valued_logic

Interface

#include "Troolean.h"

Constructor

  • Troolean() value is unknown.
  • Troolean(const int8_t) 0 = false, -1 = unknown anything else = true
  • Troolean(const Troolean&) copy constructor.

Equality operators

  • bool operator == equals
  • bool operator != not equal
  • operator bool() convert to boolean.

Logical operators

  • **Troolean operator ! ** negation, not UNKNOWN == UNKNOWN.
  • **Troolean operator && ** AND
  • **Troolean operator || ** OR

Value operators

  • bool isTrue() if not false and if not unknown.
  • bool isFalse() idem.
  • bool isUnknown() idem.

Operation

See examples

Future

Must

  • fix isTrue() to allow internal values to be anything except 0 and -1 (0.2.0)
  • check logical operators.
  • update documentation

Should

  • add unit tests (derive from test troolean.ino?)
  • add examples

Could

  • Troolean operator &&=
  • Troolean operator ||=
  • bool toBool(); // returns random true/false if unknown....

Wont

  • extend with don't care ? ==> four state logic ? Foolean?
    • => new class.

Support

If you appreciate my libraries, you can support the development and maintenance. Improve the quality of the libraries by providing issues and Pull Requests, or donate through PayPal or GitHub sponsors.

Thank you,