EX-Display
EX-Display
Loading...
Searching...
No Matches
Arduino.h
Go to the documentation of this file.
1/*
2 * © 2024 Peter Cole
3 *
4 * This is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * It is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this code. If not, see <https://www.gnu.org/licenses/>.
16 */
17
22#ifndef ARDUINO_H
23#define ARDUINO_H
24
25#include "Stream.h"
26#include <cstdarg>
27#include <gmock/gmock.h>
28#include <stdint.h>
29
30// Define states
31#define HIGH 0x1
32#define LOW 0x0
33
34// Define pin modes
35#define INPUT 0x0
36#define OUTPUT 0x1
37#define INPUT_PULLUP 0x2
38
39// Define common Arduino types
40typedef uint8_t byte;
41
42// Declare millis so it can be mocked/returned
43static unsigned long _currentMillis = 0;
44
45// Define a mock class to enable EXPECT_CALL tests against these
47public:
48 MOCK_METHOD(void, mockPinMode, (int pin, int mode), ());
49 MOCK_METHOD(void, mockDigitalWrite, (int pin, int value), ());
50
51 // Set up a singleton instance for this class to work with gmock
53 static MockArduino instance;
54 return instance;
55 }
56};
57
58// Mock Arduino functions
59inline void pinMode(int pin, int mode) { MockArduino::getInstance().mockPinMode(pin, mode); }
60inline void digitalWrite(int pin, int value) { MockArduino::getInstance().mockDigitalWrite(pin, value); }
61inline int digitalRead(int pin) { return 0; }
62inline void delay(unsigned long ms) {}
63inline unsigned long millis() { return _currentMillis; }
64inline void analogWrite(int pin, int value) {}
65inline int analogRead(int pin) { return 0; }
66
67inline void advanceMillis(unsigned long ms) { _currentMillis += ms; }
68
69#endif // ARDUINO_H
int analogRead(int pin)
Definition Arduino.h:65
void delay(unsigned long ms)
Definition Arduino.h:62
unsigned long millis()
Definition Arduino.h:63
void analogWrite(int pin, int value)
Definition Arduino.h:64
uint8_t byte
Definition Arduino.h:40
void pinMode(int pin, int mode)
Definition Arduino.h:59
void advanceMillis(unsigned long ms)
Definition Arduino.h:67
static unsigned long _currentMillis
Definition Arduino.h:43
int digitalRead(int pin)
Definition Arduino.h:61
void digitalWrite(int pin, int value)
Definition Arduino.h:60
Definition Arduino.h:46
MOCK_METHOD(void, mockDigitalWrite,(int pin, int value),())
static MockArduino & getInstance()
Definition Arduino.h:52
MOCK_METHOD(void, mockPinMode,(int pin, int mode),())