/* * Copyright 2019 Simon Arlott * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef ARDUINO_H_ #define ARDUINO_H_ #include #include #include #include #include #include // for count_if #include #include #include #include #include // #define IPAddress std::string #define IPAddress String #define ICACHE_FLASH_ATTR #define ICACHE_RAM_ATTR #define os_event_t void #define byte uint8_t #define ltoa itoa #define boolean bool #define LOW 0 #define HIGH 1 #ifndef NAN #define NAN 0 #endif #define INPUT 0 #define OUTPUT 1 #define INPUT_PULLUP 2 #define snprintf snprintf_P // to keep backwards compatibility void pinMode(uint8_t pin, uint8_t mode); void digitalWrite(uint8_t pin, uint8_t value); int digitalRead(uint8_t pin); uint32_t analogReadMilliVolts(uint8_t pin); typedef enum { ADC_0db, ADC_2_5db, ADC_6db, ADC_11db } adc_attenuation_t; void analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation); void analogSetAttenuation(adc_attenuation_t attenuation); void dacWrite(uint8_t pin, uint8_t value); double ledcSetup(uint8_t chan, double freq, uint8_t bit_num); void ledcAttachPin(uint8_t pin, uint8_t chan); void ledcWrite(uint8_t chan, uint32_t duty); #define PROGMEM #define PGM_P const char * class __FlashStringHelper; #define FPSTR(string_literal) (reinterpret_cast(string_literal)) #define F(string_literal) (FPSTR((string_literal))) int snprintf_P(char * str, size_t size, const char * format, ...); int vsnprintf_P(char * str, size_t size, const char * format, va_list ap); // #define pgm_read_byte(addr) (*reinterpret_cast(addr)) // #define pgm_read_ptr(p) (reinterpret_cast(p)) #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) #define pgm_read_word(addr) (*(const unsigned short *)(addr)) #define pgm_read_dword(addr) (*(const unsigned long *)(addr)) #define pgm_read_float(addr) (*(const float *)(addr)) #define pgm_read_ptr(addr) (*(const void **)(addr)) class Print; class NativeConsole : public Stream { public: void begin(unsigned long baud __attribute__((unused))) { } int available() override { if (peek_ != -1) return 1; struct timeval timeout; fd_set rfds; FD_ZERO(&rfds); FD_SET(STDIN_FILENO, &rfds); timeout.tv_sec = 0; timeout.tv_usec = 1000; return ::select(STDIN_FILENO + 1, &rfds, NULL, NULL, &timeout) > 0 ? 1 : 0; } int read() override { if (peek_ != -1) { uint8_t c = peek_; peek_ = -1; return c; } if (available() > 0) { uint8_t c; int ret = ::read(STDIN_FILENO, &c, 1); if (ret == 0) { /* Ctrl+D */ return '\x04'; } else if (ret == 1) { /* Remap Ctrl+Z to Ctrl-\ */ if (c == '\x1A') c = '\x1C'; return c; } else { exit(1); } } return -1; } int peek() override { if (peek_ == -1) peek_ = read(); return peek_; } size_t write(uint8_t c) override { if (::write(STDOUT_FILENO, &c, 1) == 1) { return 1; } else { exit(1); } } size_t write(const uint8_t * buffer, size_t size) override { if (::write(STDOUT_FILENO, buffer, size) == (ssize_t)size) { return size; } else { exit(1); } } private: int peek_ = -1; }; #include "Network.h" extern NativeConsole Serial; extern ETHClass ETH; extern WiFiClass WiFi; unsigned long millis(); int64_t esp_timer_get_time(); void delay(unsigned long millis); void yield(void); void setup(void); void loop(void); #endif