STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
Arduino.h
Go to the documentation of this file.
1/**
2 * Minimal Arduino.h stub for native unit tests.
3 * Provides just enough to compile DAQv2-Comms, SensorHotfireCore,
4 * firmware_hash.h, and hotfire_ota.h off-target.
5 */
6#pragma once
7
8#include <algorithm>
9#include <cstdarg>
10#include <cstddef>
11#include <cstdint>
12#include <cstring>
13#include <vector>
14
15// Standard Arduino types
16typedef uint8_t byte;
17
18// Arduino constants
19#define HIGH 1
20#define LOW 0
21#define INPUT 0
22#define OUTPUT 1
23#define LED_BUILTIN 2
24#define HEX 16
25#define DEC 10
26
27// Stub millis() / micros()
28static unsigned long _stub_millis_value = 0;
29inline unsigned long millis() {
30 return _stub_millis_value;
31}
32inline void stub_set_millis(unsigned long v) {
34}
35
36static unsigned long _stub_micros_value = 0;
37inline unsigned long micros() {
38 return _stub_micros_value;
39}
40
41// Arduino min/max macros
42#define min(a, b) ((a) < (b) ? (a) : (b))
43#define max(a, b) ((a) > (b) ? (a) : (b))
44
45// GPIO stubs
46inline void pinMode(int, int) {
47}
48inline void digitalWrite(int, int) {
49}
50inline int digitalRead(int) {
51 return LOW;
52}
53inline int analogRead(int) {
54 return 0;
55}
56inline void delay(unsigned long) {
57}
58inline void delayMicroseconds(unsigned int) {
59}
60
61// Minimal IPAddress stub (real Arduino gets this from IPAddress.h via
62// Ethernet.h). Declared before SerialStub so Serial.print(ip) can exist.
63class IPAddress {
64public:
65 IPAddress() : _o{0, 0, 0, 0} {
66 }
67 IPAddress(uint8_t a, uint8_t b, uint8_t c, uint8_t d) : _o{a, b, c, d} {
68 }
69 uint8_t operator[](int i) const {
70 return _o[i];
71 }
72 uint8_t& operator[](int i) {
73 return _o[i];
74 }
75 bool operator==(const IPAddress& o) const {
76 return memcmp(_o, o._o, 4) == 0;
77 }
78 bool operator!=(const IPAddress& o) const {
79 return !(*this == o);
80 }
81 operator uint32_t() const {
82 return (uint32_t)_o[0] << 24 | (uint32_t)_o[1] << 16 |
83 (uint32_t)_o[2] << 8 | (uint32_t)_o[3];
84 }
85
86private:
87 uint8_t _o[4];
88};
89
90// Minimal Serial stub with printf support
91#include <cstdio>
92struct SerialStub {
93 void print(const IPAddress&) {
94 }
95 void println(const IPAddress&) {
96 }
97 void begin(unsigned long) {
98 }
99 void print(const char*) {
100 }
101 void print(int) {
102 }
103 void print(unsigned int) {
104 }
105 void print(unsigned long) {
106 }
107 void print(float) {
108 }
109 void print(int, int) {
110 }
111 void print(uint8_t v, int base) {
112 } // For firmware_hash.h
113 void println(const char* s = "") {
114 }
115 void println(int) {
116 }
117 void println(unsigned int) {
118 }
119 void println(unsigned long) {
120 }
121 void println(float) {
122 }
123 void flush() {
124 }
125 void printf(const char* fmt, ...) {
126 } // For hotfire_ota.h
127};
129
130// SPI constants
131#define SPI_MODE1 1
132#define HSPI 2
133
134// ESP class stub (for ESP.restart())
136 void restart() {
137 }
138};
static SerialStub Serial
Definition Arduino.h:128
static unsigned long _stub_micros_value
Definition Arduino.h:36
int digitalRead(int)
Definition Arduino.h:50
static ESPClassStub ESP
Definition Arduino.h:139
static unsigned long _stub_millis_value
Definition Arduino.h:28
void pinMode(int, int)
Definition Arduino.h:46
unsigned long millis()
Definition Arduino.h:29
unsigned long micros()
Definition Arduino.h:37
int analogRead(int)
Definition Arduino.h:53
void delay(unsigned long)
Definition Arduino.h:56
#define LOW
Definition Arduino.h:20
uint8_t byte
Minimal Arduino.h stub for native unit tests.
Definition Arduino.h:16
void delayMicroseconds(unsigned int)
Definition Arduino.h:58
void stub_set_millis(unsigned long v)
Definition Arduino.h:32
void digitalWrite(int, int)
Definition Arduino.h:48
bool operator!=(const IPAddress &o) const
Definition Arduino.h:78
uint8_t & operator[](int i)
Definition Arduino.h:72
IPAddress(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
Definition Arduino.h:67
IPAddress()
Definition Arduino.h:65
uint8_t operator[](int i) const
Definition Arduino.h:69
uint8_t _o[4]
Definition Arduino.h:87
bool operator==(const IPAddress &o) const
Definition Arduino.h:75
*brief create JSON pointer *sa reference_tokens const string_t const string_t & b
Definition json.hpp:13878
*brief create JSON pointer *sa reference_tokens const string_t & a
Definition json.hpp:13877
return o
Definition json.hpp:13897
void restart()
Definition Arduino.h:136
void print(const char *)
Definition Arduino.h:99
void printf(const char *fmt,...)
Definition Arduino.h:125
void println(unsigned int)
Definition Arduino.h:117
void print(int, int)
Definition Arduino.h:109
void print(int)
Definition Arduino.h:101
void println(int)
Definition Arduino.h:115
void print(uint8_t v, int base)
Definition Arduino.h:111
void print(float)
Definition Arduino.h:107
void print(unsigned long)
Definition Arduino.h:105
void print(const IPAddress &)
Definition Arduino.h:93
void println(const IPAddress &)
Definition Arduino.h:95
void print(unsigned int)
Definition Arduino.h:103
void begin(unsigned long)
Definition Arduino.h:97
void flush()
Definition Arduino.h:123
void println(const char *s="")
Definition Arduino.h:113
void println(unsigned long)
Definition Arduino.h:119
void println(float)
Definition Arduino.h:121