Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
81b121b
Tests for rgbw
klew Jan 27, 2021
98a9938
RGBW tests
klew Jan 27, 2021
5625f12
Tests for RGBW storage
klew Jan 27, 2021
a4e8d0b
Added tests for dimmer and rgb base classes
klew Jan 28, 2021
5f3fb18
Added repeated ON_HOLD action for button (configured by
klew Jan 28, 2021
ac90aa8
Added RGBWLeds, RGBLeds, DimmerLeds - to control light via PWM signal
klew Jan 29, 2021
59f0778
Added ESP32 specific "analogWrite" implementation for RGBW, RGB, Dimmer
klew Jan 29, 2021
cf1fa22
Added Button to RGBW example
klew Jan 29, 2021
e76419c
Fixed ITERATE_DIM_ALL for Dimmer
klew Jan 31, 2021
86ecf38
Fix for roller shutters with opening time >32s on Arduino Mega
klew Feb 6, 2021
243ef0b
Modified RGBW classes so they will not use separate colorBrightness pin
klew Feb 8, 2021
1d63885
Changed default fade time for RGBW to 500 ms
klew Feb 8, 2021
c5936d6
Added delay(0) in few places to help software WDT get some air time
klew Feb 10, 2021
66ab551
Extracted HC_SR04 to cpp
klew Feb 10, 2021
7fa8101
RGBW PWM scalling in range to 1023
klew Feb 11, 2021
c293e8f
Added averaging for HC_SR04 sensor
klew Feb 11, 2021
e43c70f
Simple button tests
klew Feb 11, 2021
6feb639
Simple button tests
klew Feb 11, 2021
65842c6
Added configurable EEPROM size for ESP boards.
klew Feb 14, 2021
544324c
ValidityTimeSec support for channels
klew Feb 15, 2021
36eea8c
Adjusted srpc mock to "c" value changed method
klew Feb 16, 2021
1bca499
Tests for SuplaDeviceClass, few mocks added.
klew Feb 18, 2021
6af21ab
Added more tests for SuplaDeviceClass.
klew Feb 19, 2021
4d302aa
Drone: -j32
klew Feb 19, 2021
61e407f
Added cleanup fixtures to remove dependencies between test runs.
klew Feb 19, 2021
845f650
Try some perl script instead of ts for timestamp
klew Feb 19, 2021
770f917
Added slack notifications to drone
klew Feb 22, 2021
5deaa6c
Drone slack integration template adjustment
klew Feb 22, 2021
1e64411
Fixed bug when SuplaDevice stuck when no reply to device registration
klew Feb 22, 2021
3562c37
Failed test - drone check
klew Feb 22, 2021
0be0d09
Removed timestamps from drone
klew Feb 22, 2021
87a5a1b
Enabled slack notifications on build failure
klew Feb 22, 2021
ed3c80d
Fix drone
klew Feb 22, 2021
fca93f9
Removed failing test
klew Feb 22, 2021
102f194
SuplaDevice - successful startup test
klew Feb 23, 2021
4dee3ab
SuplaDevice tests
klew Feb 26, 2021
95b2244
Added drone build duration
klew Feb 26, 2021
3541c2f
Drone: time
klew Feb 26, 2021
58faf67
Merge pull request #40 from klew/develop
klew Mar 2, 2021
7700c7c
Exclude pull request from slack notif
klew Mar 2, 2021
4c53949
Merge pull request #41 from klew/develop
klew Mar 2, 2021
758358c
SuplaDevice statuses cleanup and reorganization
klew Mar 4, 2021
9719cbd
Restored values 10 and 17 for important device status values.
klew Mar 8, 2021
f85ae26
SolarEdge support - first not working draft
klew Mar 13, 2021
4121eec
addAction conditions should ignore invalid values of channels
klew Mar 15, 2021
ae7fb1b
Fixed signed/unsigned declarations for electricity meter and impulse
klew Mar 18, 2021
c2360b7
Fixed compilation for esp32
klew Mar 18, 2021
1db5368
Fixed test compilation
klew Mar 18, 2021
393d78f
Library version increment => 2.3.4.
klew Mar 22, 2021
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
32 changes: 30 additions & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,38 @@ steps:
- mkdir extras/test/build
- cd extras/test/build
- cmake ..
- make
- make -j32

- name: test
image: rikorose/gcc-cmake
commands:
- cd extras/test/build
- ./supladevicetests
- ./supladevicetests --gtest_repeat=50 --gtest_shuffle

- name: slack
image: plugins/slack
settings:
webhook:
from_secret: slack_webhook
channel: github
username: drone

# here's the template :)
# notice that the repo endpoint is hardcoded to `https://github.com/`.
# you may adjust it accordingly.
template: >
{{#if build.pull }}
*{{#success build.status}}✔{{ else }}✘{{/success}} {{ uppercasefirst build.status }}*: <https://github.com/{{ repo.owner }}/{{ repo.name }}/pull/{{ build.pull }}|Pull Request #{{ build.pull }}> in {{since build.created}}
{{else}}
*{{#success build.status}}✔{{ else }}✘{{/success}} {{ uppercasefirst build.status }}: Build #{{ build.number }}* (type: `{{ build.event }}`) in {{since build.created}}
{{/if}}

Commit: <https://github.com/{{ repo.owner }}/{{ repo.name }}/commit/{{ build.commit }}|{{ truncate build.commit 8 }}> at: <https://github.com/{{ repo.owner }}/{{ repo.name }}/commits/{{ build.branch }}|{{repo.owner}}/{{repo.name}}/{{ build.branch }}> by: {{ build.author }}

<{{ build.link }}|Visit build page ↗>
when:
status: [success, failure]
event:
exclude:
- pull_request

59 changes: 17 additions & 42 deletions examples/RGBW/RGBW.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <SuplaDevice.h>
#include <supla/control/rgbw_base.h>
#include <supla/control/rgbw_leds.h>
#include <supla/control/button.h>

// Choose proper network interface for your card:
#ifdef ARDUINO_ARCH_AVR
Expand All @@ -39,45 +40,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Youtube example was done on older version of SuplaDevice library
*/

#define RED_PIN 44
#define GREEN_PIN 45
#define BLUE_PIN 46
#define BRIGHTNESS_PIN 7
#define COLOR_BRIGHTNESS_PIN 8

class RgbwLeds : public Supla::Control::RGBWBase {
public:
RgbwLeds(int redPin,
int greenPin,
int bluePin,
int colorBrightnessPin,
int brightnessPin)
: redPin(redPin),
greenPin(greenPin),
bluePin(bluePin),
colorBrightnessPin(colorBrightnessPin),
brightnessPin(brightnessPin) {
}

void setRGBWValueOnDevice(uint8_t red,
uint8_t green,
uint8_t blue,
uint8_t colorBrightness,
uint8_t brightness) {
analogWrite(brightnessPin, (brightness * 255) / 100);
analogWrite(colorBrightnessPin, (colorBrightness * 255) / 100);
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}

protected:
int redPin;
int greenPin;
int bluePin;
int brightnessPin;
int colorBrightnessPin;
};
#define RED_PIN 4
#define GREEN_PIN 5
#define BLUE_PIN 12
#define BRIGHTNESS_PIN 13
#define BUTTON_PIN 0

void setup() {
Serial.begin(115200);
Expand All @@ -96,8 +63,16 @@ void setup() {
*/

// CHANNEL0 - RGB controller and dimmer (RGBW)
new RgbwLeds(
RED_PIN, GREEN_PIN, BLUE_PIN, COLOR_BRIGHTNESS_PIN, BRIGHTNESS_PIN);
auto rgbw = new Supla::Control::RGBWLeds(
RED_PIN, GREEN_PIN, BLUE_PIN, BRIGHTNESS_PIN);

auto button = new Supla::Control::Button(BUTTON_PIN, true, true);
button->setMulticlickTime(200);
button->setHoldTime(400);
button->repeatOnHoldEvery(200);

button->addAction(Supla::ITERATE_DIM_ALL, rgbw, Supla::ON_HOLD);
button->addAction(Supla::TOGGLE, rgbw, Supla::ON_CLICK_1);

/*
* SuplaDevice Initialization.
Expand Down
194 changes: 194 additions & 0 deletions extras/test/ButtonTests/simple_button_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/*
Copyright (C) AC SOFTWARE SP. Z O.O.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <arduino_mock.h>
#include <supla/control/simple_button.h>

using ::testing::Return;

class ActionHandlerMock : public Supla::ActionHandler {
public:
MOCK_METHOD(void, handleAction, (int, int), (override));
};

class TimeInterfaceStub : public TimeInterface {
public:
virtual unsigned long millis() override {
static unsigned long value = 0;
value += 1000;
return value;
}
};

TEST(SimpleButtonTests, NoPullupInit) {
TimeInterfaceStub time;
DigitalInterfaceMock ioMock;
ActionHandlerMock mock1;

EXPECT_CALL(ioMock, pinMode(5, INPUT));
EXPECT_CALL(ioMock, digitalRead(5)).WillOnce(Return(0));

EXPECT_CALL(mock1, handleAction).Times(0);

Supla::Control::SimpleButton button(5, false, false);
button.onInit();
button.addAction(1, mock1, Supla::ON_PRESS);
button.addAction(2, mock1, Supla::ON_CHANGE);
button.addAction(3, mock1, Supla::ON_RELEASE);
}

TEST(SimpleButtonTests, PullupInitAndPress) {
TimeInterfaceMock time;
DigitalInterfaceMock ioMock;
ActionHandlerMock mock1;

EXPECT_CALL(ioMock, pinMode(5, INPUT_PULLUP));
EXPECT_CALL(ioMock, digitalRead(5))
.WillOnce(Return(1))
.WillOnce(Return(0)) // time 1000 - first read
.WillOnce(Return(0)) // second read, should be ignored
.WillOnce(Return(0)) // third read, should trigger on_press
.WillOnce(Return(0)) // time 1090
.WillOnce(Return(1)) // time 1100
.WillOnce(Return(1)) // time 1110
.WillOnce(Return(1)) // time 1150
;

EXPECT_CALL(time, millis)
.WillOnce(Return(1000)) // first read
.WillOnce(Return(1010)) // should be ignored by filtering time
.WillOnce(Return(1030)) // should trigger on press
.WillOnce(Return(1040)) //
.WillOnce(Return(1050)) //
.WillOnce(Return(1060)) //
.WillOnce(Return(1090)) //
.WillOnce(Return(1100)) //
.WillOnce(Return(1110)) //
.WillOnce(Return(1150)) //
;


EXPECT_CALL(mock1, handleAction(Supla::ON_PRESS, 1)).Times(1);
EXPECT_CALL(mock1, handleAction(Supla::ON_CHANGE, 2)).Times(2);
EXPECT_CALL(mock1, handleAction(Supla::ON_RELEASE, 3)).Times(1);

Supla::Control::SimpleButton button(5, true, true);
button.onInit();
button.addAction(1, mock1, Supla::ON_PRESS);
button.addAction(2, mock1, Supla::ON_CHANGE);
button.addAction(3, mock1, Supla::ON_RELEASE);

button.onTimer();
button.onTimer();
button.onTimer();
button.onTimer();
button.onTimer();
button.onTimer();
button.onTimer();
button.onTimer();
button.onTimer();
button.onTimer();

}

TEST(SimpleButtonTests, PullupInitAndPressWithoutNoiseFilter) {
TimeInterfaceMock time;
DigitalInterfaceMock ioMock;
ActionHandlerMock mock1;

EXPECT_CALL(ioMock, pinMode(5, INPUT_PULLUP));
EXPECT_CALL(ioMock, digitalRead(5))
.WillOnce(Return(1))
.WillOnce(Return(0))
.WillOnce(Return(0))
.WillOnce(Return(0))
.WillOnce(Return(1))
;

EXPECT_CALL(time, millis)
.WillOnce(Return(1000))
.WillOnce(Return(1010))
.WillOnce(Return(1100))
.WillOnce(Return(1200))
.WillOnce(Return(1300))
;


EXPECT_CALL(mock1, handleAction(Supla::ON_PRESS, 1)).Times(1);
EXPECT_CALL(mock1, handleAction(Supla::ON_CHANGE, 2)).Times(2);
EXPECT_CALL(mock1, handleAction(Supla::ON_RELEASE, 3)).Times(1);

Supla::Control::SimpleButton button(5, true, true);
button.setSwNoiseFilterDelay(0);
button.onInit();
button.addAction(1, mock1, Supla::ON_PRESS);
button.addAction(2, mock1, Supla::ON_CHANGE);
button.addAction(3, mock1, Supla::ON_RELEASE);

button.onTimer();
button.onTimer();
button.onTimer();
button.onTimer();
button.onTimer();

}

TEST(SimpleButtonTests, PullupInitAndPressWithoutDebounce) {
TimeInterfaceMock time;
DigitalInterfaceMock ioMock;
ActionHandlerMock mock1;

EXPECT_CALL(ioMock, pinMode(5, INPUT_PULLUP));
EXPECT_CALL(ioMock, digitalRead(5))
.WillOnce(Return(1))

.WillOnce(Return(0))
.WillOnce(Return(0))
.WillOnce(Return(0))
.WillOnce(Return(1))
.WillOnce(Return(1))
;

EXPECT_CALL(time, millis)
.WillOnce(Return(1000))
.WillOnce(Return(1010))
.WillOnce(Return(1100))
.WillOnce(Return(1101))
.WillOnce(Return(1145))
;


EXPECT_CALL(mock1, handleAction(Supla::ON_PRESS, 1)).Times(1);
EXPECT_CALL(mock1, handleAction(Supla::ON_CHANGE, 2)).Times(2);
EXPECT_CALL(mock1, handleAction(Supla::ON_RELEASE, 3)).Times(1);

Supla::Control::SimpleButton button(5, true, true);
button.setDebounceDelay(0);
button.onInit();
button.addAction(1, mock1, Supla::ON_PRESS);
button.addAction(2, mock1, Supla::ON_CHANGE);
button.addAction(3, mock1, Supla::ON_RELEASE);

button.onTimer();
button.onTimer();
button.onTimer();
button.onTimer();
button.onTimer();

}

3 changes: 3 additions & 0 deletions extras/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ file(GLOB TEST_SRC
InternalPinOutputTests/*.cpp
PinStatusLedTests/*.cpp
ConditionTests/*.cpp
RgbwDimmerTests/*.cpp
ButtonTests/*.cpp
SuplaDeviceTests/*.cpp
)

file(GLOB DOUBLE_SRC doubles/*.cpp)
Expand Down
10 changes: 5 additions & 5 deletions extras/test/ChannelTests/channel_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ TEST(ChannelTests, SetNewValue) {
EXPECT_TRUE(channel.isUpdateReady());
channel.clearUpdateReady();

_supla_int64_t value64 = 124346;
unsigned _supla_int64_t value64 = 124346;
ASSERT_EQ(sizeof(value64), 8);
channel.setNewValue(value64);
EXPECT_TRUE(0 == memcmp(Supla::Channel::reg_dev.channels[number].value, &value64, sizeof(value64)));
Expand Down Expand Up @@ -255,7 +255,7 @@ TEST(ChannelTests, ChannelValueGetters) {
channel.setNewValue(valueInt);
EXPECT_EQ(channel.getValueInt32(), valueInt);

_supla_int64_t valueInt64 = 202013012021000;
unsigned _supla_int64_t valueInt64 = 202013012021000;
channel.setNewValue(valueInt64);
EXPECT_EQ(channel.getValueInt64(), valueInt64);

Expand Down Expand Up @@ -283,8 +283,8 @@ TEST(ChannelTests, SendUpdateTest) {
char array[SUPLA_CHANNELVALUE_SIZE] = {};
array[0] = 1;

EXPECT_CALL(srpc, valueChanged(nullptr, 0, ElementsAreArray(emptyArray)));
EXPECT_CALL(srpc, valueChanged(nullptr, 0, ElementsAreArray(array)));
EXPECT_CALL(srpc, valueChanged(nullptr, 0, ElementsAreArray(emptyArray), 0, 0));
EXPECT_CALL(srpc, valueChanged(nullptr, 0, ElementsAreArray(array), 0, 0));

EXPECT_FALSE(channel.isUpdateReady());
channel.sendUpdate(nullptr);
Expand Down Expand Up @@ -380,7 +380,7 @@ TEST(ChannelTests, Int64ChannelWithLocalActions) {

ch1.addAction(action1, mock1, Supla::ON_CHANGE);

_supla_int64_t value = 15;
unsigned _supla_int64_t value = 15;

ch1.setNewValue(value);
ch1.setNewValue(value);
Expand Down
Loading