Port the guarded NMEA buffer, validated RMC clock samples and coordinate bounds from meshcore-dev/MeshCore#3624, #3625 and #3626. Adapt clock admission to retain this branch's signed date limits, bounded loop work, tracker acquisitions, sample consumption, diagnostics and periodic settings. Upstream-PR: https://github.com/meshcore-dev/MeshCore/pull/3624 Upstream-Commit: 1ac389bbef0084623a3115c526156ae8f414d3ea Upstream-PR: https://github.com/meshcore-dev/MeshCore/pull/3625 Upstream-Commit: 72ed4dcf08869c6900ef579e7af1b28471a86895 Upstream-PR: https://github.com/meshcore-dev/MeshCore/pull/3626 Upstream-Commit: 499727a71c564a7b5d451b8f480d940e185fe742 Co-authored-by: nullrouten0 <201262769+nullrouten0@users.noreply.github.com>
73 lines
1.5 KiB
C++
73 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <ctype.h>
|
|
#include <cmath>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include "Stream.h"
|
|
|
|
using std::atof;
|
|
using std::atoi;
|
|
using std::atol;
|
|
|
|
inline uint32_t g_mock_millis = 0;
|
|
|
|
constexpr uint8_t LOW = 0;
|
|
constexpr uint8_t HIGH = 1;
|
|
constexpr uint8_t INPUT = 0;
|
|
constexpr uint8_t OUTPUT = 1;
|
|
constexpr uint8_t INPUT_PULLUP = 2;
|
|
constexpr uint8_t INPUT_PULLDOWN = 3;
|
|
|
|
inline uint8_t g_mock_pin_modes[64] = {};
|
|
inline uint8_t g_mock_pin_levels[64] = {};
|
|
inline int g_mock_analog_levels[64] = {};
|
|
|
|
using std::isnan;
|
|
|
|
inline uint32_t millis() {
|
|
return g_mock_millis;
|
|
}
|
|
|
|
inline void delay(uint32_t ms) {
|
|
g_mock_millis += ms;
|
|
}
|
|
|
|
// Suites with busy-waiting production methods supply advancing mock time.
|
|
void yield();
|
|
|
|
inline char* ltoa(long value, char* dest, int base) {
|
|
if (base == 10) {
|
|
std::snprintf(dest, 16, "%ld", value);
|
|
} else {
|
|
dest[0] = '\0';
|
|
}
|
|
return dest;
|
|
}
|
|
|
|
inline void pinMode(uint8_t pin, uint8_t mode) {
|
|
if (pin < 64) g_mock_pin_modes[pin] = mode;
|
|
}
|
|
|
|
inline void digitalWrite(uint8_t pin, uint8_t level) {
|
|
if (pin < 64) g_mock_pin_levels[pin] = level;
|
|
}
|
|
|
|
inline int digitalRead(uint8_t pin) {
|
|
return pin < 64 ? g_mock_pin_levels[pin] : LOW;
|
|
}
|
|
|
|
inline int analogRead(uint8_t pin) {
|
|
return pin < 64 ? g_mock_analog_levels[pin] : 0;
|
|
}
|
|
|
|
inline void resetArduinoMock() {
|
|
g_mock_millis = 0;
|
|
for (uint8_t pin = 0; pin < 64; pin++) {
|
|
g_mock_pin_modes[pin] = INPUT;
|
|
g_mock_pin_levels[pin] = LOW;
|
|
g_mock_analog_levels[pin] = 0;
|
|
}
|
|
}
|