Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
18 changes: 16 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ jobs:
matrix:
pio-env: ['esp12e', 'esp32dev']
example: ['Blink/Blink.cpp', 'Do/Do.cpp', 'FromArray/FromArray.cpp', 'FromProperty/FromProperty.cpp', 'FromSerialPort/FromSerialPort.cpp', 'FromString/FromString.cpp', 'GlobalDefined/GlobalDefined.cpp', 'Reduce/Reduce.cpp']
steps:
- uses: actions/checkout@v4
- name: Set up python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install PlatformIO
run: python -m pip install platformio
- name: Build firmware
run: pio ci --lib="." --board ${{matrix.pio-env}} "examples/${{matrix.example}}"

test:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up python
Expand All @@ -17,5 +31,5 @@ jobs:
architecture: 'x64'
- name: Install PlatformIO
run: python -m pip install platformio
- name: Build firmware
run: pio ci --lib="." --board ${{matrix.pio-env}} "examples/${{matrix.example}}"
- name: Run unit tests
run: pio test -e native
16 changes: 0 additions & 16 deletions keywords.txt

This file was deleted.

37 changes: 37 additions & 0 deletions library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json",
"name": "ReactiveArduino",
"description": "ReactiveArduino implements observable-observer pattern on a processor like Arduino",
"keywords": [
"Reactive",
"Arduino",
"Observer",
"Observable",
"Event"
],
"repository": {
"type": "git",
"url": "https://github.com/rzeldent/Arduino-ReactiveArduino"
},
"frameworks": [
"arduino"
],
"platforms": "*",
"build": {
"srcDir": "src/",
"includeDir": "include/"
},
"version": "2.0.0",
"authors": [
{
"name": "Luis Llamas",
"maintainer": true
},
{
"name": "Rene Zeldenthuis",
"maintainer": true
}

],
"category": "Other"
}
9 changes: 0 additions & 9 deletions library.properties

This file was deleted.

19 changes: 19 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; PlatformIO Unit Testing configuration for the ReactiveArduino library.
;
; Run the tests with:
; pio test -e native
;
; The `native` environment compiles and runs the tests on the host machine.
; Arduino hardware functions (millis, micros, pinMode, digitalWrite, analogWrite,
; analogRead, digitalRead, String, Serial) are stubbed in test/WProgram.h so the
; header-only library can be exercised without a board.

[platformio]
default_envs = native

[env:native]
platform = native
test_framework = unity
build_flags =
-Isrc
-Itest
2 changes: 1 addition & 1 deletion src/Aggregates/AggregateAll.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ AggregateAll<T>::AggregateAll(ReactivePredicate<T> condition)
template <typename T>
void AggregateAll<T>::OnNext(T value)
{
if (_state && _condition(value)) _state = false;
if (!_condition(value)) _state = false;

this->_childObservers.OnNext(_state);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Aggregates/AggregateAverage.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void AggregateAverage<T>::OnNext(T value)
{
_sum += value;
_count++;
this->_childObservers.OnNext(_sum / _count);
this->_childObservers.OnNext(_sum / static_cast<T>(_count));
}

#endif
2 changes: 1 addition & 1 deletion src/Aggregates/AggregateCount.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AggregateCount : public Operator<T, int>
void OnNext(T value) override;

private:
int _count = false;
int _count = 0;
};

template <typename T>
Expand Down
6 changes: 5 additions & 1 deletion src/Aggregates/AggregateCountdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class AggregateCountdown : public Operator<T, int>
void OnNext(T value) override;

private:
int _count = false;
int _count = 0;
bool _completed = false;
};

template <typename T>
Expand All @@ -31,11 +32,14 @@ AggregateCountdown<T>::AggregateCountdown(int count)
template <typename T>
void AggregateCountdown<T>::OnNext(T value)
{
if (_completed) return;

_count--;
this->_childObservers.OnNext(_count);

if (_count <= 0)
{
_completed = true;
this->_childObservers.OnComplete();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Aggregates/AggregateNone.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ AggregateNone<T>::AggregateNone(ReactivePredicate<T> condition)
template <typename T>
void AggregateNone<T>::OnNext(T value)
{
if (!_condition(value)) _state = false;
if (_condition(value)) _state = false;

this->_childObservers.OnNext(_state);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Aggregates/AggregateRMS.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void AggregateRMS<T>::OnNext(T value)
{
_sumSqr += value * value;
_count++;
this->_childObservers.OnNext(sqrt(_sumSqr / _count));
this->_childObservers.OnNext(static_cast<T>(sqrt(static_cast<double>(_sumSqr) / static_cast<double>(_count))));
}

#endif
2 changes: 0 additions & 2 deletions src/Filters/FilterWindowMicros.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ void FilterWindowMicros<T>::OnNext(T value)
}

if (_started && static_cast<unsigned long>(micros() - _lastTrigger) <= _interval)
{
this->_childObservers.OnNext(value);
}
}

#endif
2 changes: 0 additions & 2 deletions src/Filters/FilterWindowMillis.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ void FilterWindowMillis<T>::OnNext(T value)
}

if (_started && static_cast<unsigned long>(millis() - _lastTrigger) <= _interval)
{
this->_childObservers.OnNext(value);
}
}

#endif
5 changes: 3 additions & 2 deletions src/Observables/ObservableIntervalMicros.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class ObservableIntervalMicros : public Observable<unsigned long>

private:
bool _isActive;
bool _isExpired;
unsigned long _startTime;
unsigned long _delay;
unsigned long _offset;
Expand Down Expand Up @@ -121,7 +120,9 @@ unsigned long ObservableIntervalMicros<T>::GetElapsedTime()
template <typename T>
unsigned long ObservableIntervalMicros<T>::GetRemainingTime()
{
return _interval - micros() + _startTime;
unsigned long elapsed = micros() - _startTime;
if (elapsed >= _interval) return 0;
return _interval - elapsed;
}

template <typename T>
Expand Down
5 changes: 3 additions & 2 deletions src/Observables/ObservableIntervalMillis.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class ObservableIntervalMillis : public Observable<unsigned long>

private:
bool _isActive;
bool _isExpired;
unsigned long _startTime;
unsigned long _delay;
unsigned long _offset;
Expand Down Expand Up @@ -121,7 +120,9 @@ unsigned long ObservableIntervalMillis<T>::GetElapsedTime()
template <typename T>
unsigned long ObservableIntervalMillis<T>::GetRemainingTime()
{
return _interval - millis() + _startTime;
unsigned long elapsed = millis() - _startTime;
if (elapsed >= _interval) return 0;
return _interval - elapsed;
}

template <typename T>
Expand Down
12 changes: 10 additions & 2 deletions src/Observables/ObservableRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@ void ObservableRange<T>::UnSubscribe(IObserver<T> &observer)
template<typename T>
void ObservableRange<T>::Run()
{
for (auto i = _start; i <= _end; i += _step)
this->_childObservers.OnNext(i);
if (_step > 0)
{
for (auto i = _start; i <= _end; i += _step)
this->_childObservers.OnNext(i);
}
else if (_step < 0)
{
for (auto i = _start; i >= _end; i += _step)
this->_childObservers.OnNext(i);
}

this->_childObservers.OnComplete();
}
Expand Down
5 changes: 3 additions & 2 deletions src/Observables/ObservableRangeDefer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ void ObservableRangeDefer<T>::UnSubscribe(IObserver<T> &observer)
template <typename T>
void ObservableRangeDefer<T>::Next()
{
if (_value > _end) return;
if (_step > 0 && _value > _end) return;
if (_step < 0 && _value < _end) return;

T value = _value;
this->_childObservers.OnNext(value);
_value += _step;

if (_value > _end)
if ((_step > 0 && _value > _end) || (_step < 0 && _value < _end))
this->_childObservers.OnComplete();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Observables/ObservableSerialByte.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class ObservableSerial<byte> : public Observable<byte>
{
public:
ObservableSerial();
void Subscribe(IObserver<byte> &observer);
void UnSubscribe(IObserver<byte> &observer);
void Subscribe(IObserver<byte> &observer) override;
void UnSubscribe(IObserver<byte> &observer) override;
void Receive();

private:
Expand Down
2 changes: 1 addition & 1 deletion src/Observables/ObservableSerialDouble.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ObservableSerial<double> : public Observable<double>
private:
char _separator;

float _data = 0;
double _data = 0;
int _dataReal = 0;
int _dataDecimal = 0;
int _dataPow = 1;
Expand Down
2 changes: 0 additions & 2 deletions src/Observables/ObservableSerialString.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ inline void ObservableSerial<String>::Receive()
{
const char newChar = Serial.read();
if (newChar != _separator)
{
_buffer.concat(newChar);
}
else
{
_childObservers.OnNext(_buffer);
Expand Down
8 changes: 7 additions & 1 deletion src/Observables/ObservableTimerMicros.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ template <typename T>
ObservableTimerMicros<T>::ObservableTimerMicros(unsigned long interval, unsigned long delay)
{
_isActive = true;
_isExpired = false;
_delay = delay;
_offset = delay;
_interval = interval;
Expand All @@ -68,11 +69,13 @@ template <typename T>
void ObservableTimerMicros<T>::Update()
{
if (_isActive == false) return;
if (_isExpired) return;

auto elapsed = static_cast<unsigned long>(micros() - _startTime);
if (elapsed >= _interval + _offset)
{
this->_childObservers.OnNext(elapsed);
_isExpired = true;
_offset = 0;
}
}
Expand All @@ -81,6 +84,7 @@ template <typename T>
void ObservableTimerMicros<T>::Reset()
{
_isActive = true;
_isExpired = false;
_offset = _delay;
_startTime = micros();
}
Expand Down Expand Up @@ -119,7 +123,9 @@ unsigned long ObservableTimerMicros<T>::GetElapsedTime() const
template <typename T>
unsigned long ObservableTimerMicros<T>::GetRemainingTime() const
{
return _interval - micros() + _startTime;
unsigned long elapsed = micros() - _startTime;
if (elapsed >= _interval) return 0;
return _interval - elapsed;
}

template <typename T>
Expand Down
Loading
Loading