2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
[![Arduino CI](https://github.com/RobTillaart/Troolean/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
2021-12-29 07:05:17 -05:00
|
|
|
[![Arduino-lint](https://github.com/RobTillaart/Troolean/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/Troolean/actions/workflows/arduino-lint.yml)
|
|
|
|
[![JSON check](https://github.com/RobTillaart/Troolean/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/Troolean/actions/workflows/jsoncheck.yml)
|
2023-11-23 07:46:31 -05:00
|
|
|
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/Troolean.svg)](https://github.com/RobTillaart/Troolean/issues)
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/Troolean/blob/master/LICENSE)
|
|
|
|
[![GitHub release](https://img.shields.io/github/release/RobTillaart/Troolean.svg?maxAge=3600)](https://github.com/RobTillaart/Troolean/releases)
|
2023-11-23 07:46:31 -05:00
|
|
|
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/Troolean.svg)](https://registry.platformio.org/libraries/robtillaart/Troolean)
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
|
2020-11-27 05:33:55 -05:00
|
|
|
# Troolean
|
|
|
|
|
2021-12-29 07:05:17 -05:00
|
|
|
Arduino Library for a three state logic data type supporting {True False Unknown}.
|
2020-11-27 05:33:55 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
## Description
|
2020-11-27 05:33:55 -05:00
|
|
|
|
2021-12-29 07:05:17 -05:00
|
|
|
Troolean is a data type that implements three state logic with the values
|
2020-11-27 05:33:55 -05:00
|
|
|
{True False Unknown }
|
|
|
|
|
|
|
|
Logic operators are similar to boolean and behave the same for the familiar boolean values.
|
|
|
|
|
2021-12-29 07:05:17 -05:00
|
|
|
Trooleans can be used e.g. to indicate a value is valid, invalid or unknown to be valid or not.
|
2022-11-26 10:50:57 -05:00
|
|
|
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.
|
2020-11-27 05:33:55 -05:00
|
|
|
|
|
|
|
See also https://en.wikipedia.org/wiki/Three-valued_logic
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
## Interface
|
|
|
|
|
2023-11-23 07:46:31 -05:00
|
|
|
```cpp
|
|
|
|
#include "Troolean.h"
|
|
|
|
```
|
2021-12-29 07:05:17 -05:00
|
|
|
|
2022-11-26 10:50:57 -05:00
|
|
|
#### 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
|
2022-12-02 08:12:22 -05:00
|
|
|
- **bool isTrue()** if not false and if not unknown.
|
2022-11-26 10:50:57 -05:00
|
|
|
- **bool isFalse()** idem.
|
|
|
|
- **bool isUnknown()** idem.
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
## Operation
|
2020-11-27 05:33:55 -05:00
|
|
|
|
|
|
|
See examples
|
|
|
|
|
2021-12-29 07:05:17 -05:00
|
|
|
|
|
|
|
## Future
|
|
|
|
|
2023-11-23 07:46:31 -05:00
|
|
|
#### Must
|
|
|
|
|
2022-11-26 10:50:57 -05:00
|
|
|
- fix **isTrue()** to allow internal values to be anything except 0 and -1 (0.2.0)
|
|
|
|
- check logical operators.
|
2021-12-29 07:05:17 -05:00
|
|
|
- update documentation
|
2022-11-26 10:50:57 -05:00
|
|
|
|
2023-11-23 07:46:31 -05:00
|
|
|
#### Should
|
|
|
|
|
2021-12-29 07:05:17 -05:00
|
|
|
- add unit tests (derive from test troolean.ino?)
|
|
|
|
- add examples
|
2022-11-26 10:50:57 -05:00
|
|
|
|
2023-11-23 07:46:31 -05:00
|
|
|
#### Could
|
|
|
|
|
2022-12-02 08:12:22 -05:00
|
|
|
- Troolean operator &&=
|
|
|
|
- Troolean operator ||=
|
|
|
|
- bool toBool(); // returns random true/false if unknown....
|
2022-11-26 10:50:57 -05:00
|
|
|
|
2023-11-23 07:46:31 -05:00
|
|
|
#### Wont
|
|
|
|
|
2022-12-02 08:12:22 -05:00
|
|
|
- extend with don't care ? ==> four state logic ? Foolean?
|
|
|
|
- => new class.
|
2022-11-26 10:50:57 -05:00
|
|
|
|
2021-12-29 07:05:17 -05:00
|
|
|
|
2023-11-23 07:46:31 -05:00
|
|
|
## 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,
|
|
|
|
|
|
|
|
|