Public Access
- New native environment: pio test -e native - test/mocks: fake Arduino core, EEPROM and recording BROSE9323 driver - test/test_nano: 25 tests covering every command, bitmaps, bad input, flip time storage and the periodic full redraw - Board environments ignore tests so they are never uploaded Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
// Minimal Arduino API for running the Nano code on the PC (native test environment)
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <deque>
|
|
#include <string>
|
|
|
|
#define HEX 16
|
|
|
|
class __FlashStringHelper;
|
|
#define F(s) ((const __FlashStringHelper *)(s))
|
|
|
|
// Time is controlled by the tests
|
|
inline uint32_t fake_millis = 0;
|
|
inline uint32_t millis() { return fake_millis; }
|
|
inline void delay(uint32_t ms) { fake_millis += ms; }
|
|
|
|
// Serial port: tests push bytes into `in` and read replies from `out`
|
|
class FakeSerial
|
|
{
|
|
public:
|
|
std::deque<char> in;
|
|
std::string out;
|
|
|
|
void begin(unsigned long) {}
|
|
int available() { return in.size(); }
|
|
int read()
|
|
{
|
|
if (in.empty())
|
|
return -1;
|
|
char c = in.front();
|
|
in.pop_front();
|
|
return (uint8_t)c;
|
|
}
|
|
void flush() {}
|
|
|
|
void print(const __FlashStringHelper *s) { out += (const char *)s; }
|
|
void print(const char *s) { out += s; }
|
|
void print(int v, int base = 10)
|
|
{
|
|
char buf[16];
|
|
snprintf(buf, sizeof(buf), base == HEX ? "%X" : "%d", v);
|
|
out += buf;
|
|
}
|
|
void println(const __FlashStringHelper *s) { print(s); out += "\n"; }
|
|
void println(const char *s) { print(s); out += "\n"; }
|
|
void println(unsigned long v) { out += std::to_string(v) + "\n"; }
|
|
};
|
|
|
|
using Print = FakeSerial;
|
|
|
|
inline FakeSerial Serial;
|