Skip to content

Commit

Permalink
[TerkinData] Add separate PlatformIO environment native-radiohead
Browse files Browse the repository at this point in the history
Fixes compilation on Linux.

__unix__ is defined on Linux, while __APPLE__ is defined on macOS [1].
In the default configuration, we don't want to specialize for any of
both.

It is probably a leftover from where we explored simulating RadioHead-
based code.

[1] https://www.airspayce.com/mikem/arduino/RadioHead/RadioHead_8h_source.html
  • Loading branch information
amotl committed Jun 1, 2023
1 parent 888363c commit 4caacb6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
17 changes: 17 additions & 0 deletions libraries/TerkinData/examples/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ build_flags =
# -Wextra


[env:native-radiohead]
# Native build with RadioHead, for simulation purposes.
# http://www.airspayce.com/mikem/arduino/RadioHead/classRH__TCP.html
platform = native
lib_deps =
${env:native.lib_deps}
mikem/RadioHead@^1.120
lib_extra_dirs =
${env:native.lib_extra_dirs}
build_flags =
${env:native.build_flags}
# FIXME: Why is that needed? What overwrites it?
-I ${platformio.libdeps_dir}/${this.__env__}/RadioHead
-D RH_SIMULATOR=true
-D SERIAL_PORT_HARDWARE=


[env:avr328]
platform = atmelavr
board = pro8MHzatmega328
Expand Down
8 changes: 4 additions & 4 deletions libraries/Terrine/Terrine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

#if ARDUINO && !ESP32
#include <MemoryFree.h>
#elif defined(__unix__)
#else
#endif
#if defined(__unix__) || defined(__APPLE__)
#include <iostream>
#endif

Expand Down Expand Up @@ -87,7 +87,7 @@ void Terrine::log(int value) {
#ifdef ARDUINO
SERIAL_PORT_HARDWARE.println(value);
delay(TERRINE_SERIAL_DELAY);
#elif defined(__unix__)
#elif defined(RH_SIMULATOR_DEFUNCT)
SERIAL_PORT_HARDWARE.println(std::to_string(value).c_str());
#else
std::cout << value << std::endl;
Expand All @@ -112,7 +112,7 @@ void Terrine::logmem() {
SERIAL_PORT_HARDWARE.print("free: ");
SERIAL_PORT_HARDWARE.println(memfree());
delay(TERRINE_SERIAL_DELAY);
#elif defined(__unix__)
#elif defined(RH_SIMULATOR_DEFUNCT)
SERIAL_PORT_HARDWARE.println(std::to_string(memfree()).c_str());
#else
log("free: ", false);
Expand Down
6 changes: 3 additions & 3 deletions libraries/Terrine/Terrine.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <Arduino.h>
#elif defined SIMULAVR
#include <simulavr.h>
#elif defined __unix__
#elif defined RH_SIMULATOR
#include <RHutil/simulator.h>
#endif

Expand All @@ -45,7 +45,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

#define TERRINE_SERIAL_DELAY 100

#if defined(__unix__)
#if defined(RH_SIMULATOR_DEFUNCT)
#include <sstream>
namespace std {
std::string to_string(size_t n) {
Expand All @@ -55,7 +55,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
}
}
#endif
#if defined(__unix__)
#if defined(RH_SIMULATOR_DEFUNCT)
extern char *ultoa(unsigned long int __val, char *__s, int __radix) {
snprintf(__s, __radix, "%d", __val);
return __s;
Expand Down

0 comments on commit 4caacb6

Please sign in to comment.