26 #include "Serial/Serial.h"
32 #define INPUT_PULLUP 0x2
36 auto start_ts = std::chrono::high_resolution_clock::now();
37 auto start_ts_ms = std::chrono::high_resolution_clock::now();
42 std::chrono::duration_cast<std::chrono::microseconds>(
43 std::chrono::high_resolution_clock::now() - start_ts
46 if(elapsed_usec >= UINT32_MAX) {
47 start_ts = std::chrono::high_resolution_clock::now();
50 return (uint32_t) elapsed_usec;
57 std::chrono::duration_cast<std::chrono::milliseconds>(
58 std::chrono::high_resolution_clock::now() - start_ts_ms
63 void delayMicroseconds(uint32_t delay_value)
65 auto begin_ts = std::chrono::high_resolution_clock::now();
68 std::chrono::duration_cast<std::chrono::microseconds>(
69 std::chrono::high_resolution_clock::now() - begin_ts
71 if(elapsed_usec >= delay_value) {
74 std::this_thread::sleep_for(std::chrono::microseconds(50));
78 void delay(uint32_t delay_value_ms)
80 std::this_thread::sleep_for(std::chrono::milliseconds(delay_value_ms));
90 #define LED_BUILTIN -1
95 #if !defined(PJON_ANALOG_READ)
96 #define PJON_ANALOG_READ(P) 0
99 #if !defined(PJON_IO_WRITE)
101 #define PJON_IO_WRITE(P, V) (void)0
104 #if !defined(PJON_IO_READ)
105 #define PJON_IO_READ(P) 0
108 #if !defined(PJON_IO_MODE)
110 #define PJON_IO_MODE(P, V) (void)0
113 #if !defined(PJON_IO_PULL_DOWN)
115 #define PJON_IO_PULL_DOWN(P) (void)0
121 #define PJON_RANDOM(randMax) (int)((1.0 + randMax) * rand() / ( RAND_MAX + 1.0 ) )
126 #ifndef PJON_RANDOM_SEED
127 #define PJON_RANDOM_SEED srand
133 #ifndef PJON_SERIAL_TYPE
134 #define PJON_SERIAL_TYPE Serial *
137 #ifndef PJON_SERIAL_AVAILABLE
138 #define PJON_SERIAL_AVAILABLE(S) S->serialDataAvail()
141 #ifndef PJON_SERIAL_WRITE
142 #define PJON_SERIAL_WRITE(S, C) S->writeByte(&C)
145 #ifndef PJON_SERIAL_READ
146 #define PJON_SERIAL_READ(S) S->getByte()
149 #ifndef PJON_SERIAL_FLUSH
150 #define PJON_SERIAL_FLUSH(S) S->flush()
157 #define PJON_DELAY delay
160 #ifndef PJON_DELAY_MICROSECONDS
161 #define PJON_DELAY_MICROSECONDS delayMicroseconds
165 #define PJON_MICROS micros
169 #define PJON_MILLIS millis