3-phase PV router
Loading...
Searching...
No Matches
test_main.cpp
Go to the documentation of this file.
1#include <Arduino.h>
2#include <U8g2lib.h>
3
4#include <unity.h>
5
6#include "utils_pins.h"
7
8void setUp(void)
9{
10 // set stuff up here
11}
12
13void tearDown(void)
14{
15 // clean stuff up here
16}
17
18void test_setPinON(void)
19{
20 setPinON(LED_BUILTIN);
21 delay(100);
22 TEST_ASSERT_EQUAL(HIGH, digitalRead(LED_BUILTIN));
23}
24
26{
27 setPinOFF(LED_BUILTIN);
28 delay(100);
29 TEST_ASSERT_EQUAL(LOW, digitalRead(LED_BUILTIN));
30}
31
33{
34 digitalWrite(LED_BUILTIN, HIGH);
35 delay(100);
36 togglePin(LED_BUILTIN);
37 delay(100);
38 TEST_ASSERT_EQUAL(LOW, digitalRead(LED_BUILTIN));
39
40 togglePin(LED_BUILTIN);
41 delay(100);
42 TEST_ASSERT_EQUAL(HIGH, digitalRead(LED_BUILTIN));
43}
44
46{
47 setPinState(LED_BUILTIN, true);
48 delay(100);
49 TEST_ASSERT_EQUAL(HIGH, digitalRead(LED_BUILTIN));
50 setPinState(LED_BUILTIN, false);
51 delay(100);
52 TEST_ASSERT_EQUAL(LOW, digitalRead(LED_BUILTIN));
53}
54
56{
57 const uint16_t pinsToSet{ 0b11111111111100 };
58
59 setPinsON(pinsToSet);
60 delay(100);
61
62 for (uint8_t pin = 2; pin < 14; ++pin)
63 {
64 TEST_ASSERT_EQUAL(HIGH, digitalRead(pin));
65 }
66}
67
69{
70 const uint16_t pinsToSet{ 0b11111111111100 };
71
72 setPinsOFF(pinsToSet);
73 delay(100);
74
75 for (uint8_t pin = 2; pin < 14; ++pin)
76 {
77 TEST_ASSERT_EQUAL(LOW, digitalRead(pin));
78 }
79}
80
81
82void setup()
83{
84 delay(1000);
85
86 for (uint8_t pin = 2; pin < 14; ++pin)
87 {
88 pinMode(pin, OUTPUT);
89 }
90
91 UNITY_BEGIN(); // IMPORTANT LINE!
92}
93
94uint8_t i = 0;
95uint8_t max_blinks = 2;
96
97void loop()
98{
99 if (i < max_blinks)
100 {
101 RUN_TEST(test_setPinON);
102 delay(100);
103 RUN_TEST(test_setPinOFF);
104 delay(100);
105 RUN_TEST(test_togglePin);
106 delay(100);
107 RUN_TEST(test_setPinState);
108 delay(100);
109 RUN_TEST(test_setPinsON);
110 delay(100);
111 RUN_TEST(test_setPinsOFF);
112 delay(100);
113 ++i;
114 }
115 else if (i == max_blinks)
116 {
117 UNITY_END(); // stop unit testing
118 }
119}
constexpr uint16_t
Definition: config_system.h:32
void test_setPinON(void)
Definition: test_main.cpp:18
void setup()
Definition: test_main.cpp:82
void test_togglePin(void)
Definition: test_main.cpp:32
void test_setPinsON(void)
Definition: test_main.cpp:55
void test_setPinsOFF(void)
Definition: test_main.cpp:68
uint8_t max_blinks
Definition: test_main.cpp:95
void setUp(void)
Definition: test_main.cpp:8
void tearDown(void)
Definition: test_main.cpp:13
void test_setPinState(void)
Definition: test_main.cpp:45
void test_setPinOFF(void)
Definition: test_main.cpp:25
uint8_t i
Definition: test_main.cpp:94
void loop()
Definition: test_main.cpp:97
Some utility functions for pins manipulation.
void setPinsOFF(const uint16_t pins)
Set the Pins state to OFF.
Definition: utils_pins.h:161
constexpr void setPinState(const uint8_t pin, const bool bState)
Set the Pin state for the specified pin.
Definition: utils_pins.h:99
constexpr void togglePin(const uint8_t pin)
Toggle the specified pin.
Definition: utils_pins.h:81
constexpr void setPinON(const uint8_t pin)
Set the Pin state to ON for the specified pin.
Definition: utils_pins.h:116
constexpr void setPinOFF(const uint8_t pin)
Set the Pin state to OFF for the specified pin.
Definition: utils_pins.h:144
void setPinsON(const uint16_t pins)
Set the Pins state to ON.
Definition: utils_pins.h:133