From 91c7e223925397bcef087ae717bbd7ae424ac7bb Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Mon, 12 Apr 2021 15:11:56 +0300 Subject: [PATCH] Basic implementation --- .gitignore | 5 ++++ platformio.ini | 33 ++++++++++++++++++++++ src/main.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 .gitignore create mode 100644 platformio.ini create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..a607526 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,33 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[platformio] +default_envs = + esp32dev + +[env] +framework = arduino +lib_ldf_mode = deep +monitor_speed = 115200 +lib_deps = + /Users/mairas/src/SK/SensESP + Adafruit SSD1306 + +[espressif32_base] +platform = espressif32 +build_unflags = -Werror=reorder +board_build.partitions = min_spiffs.csv +monitor_filters = esp32_exception_decoder + +[env:esp32dev] +extends = espressif32_base +board = esp32dev +build_flags = + -D LED_BUILTIN=2 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..fdc3b4b --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,76 @@ +#include +#include +#include + +#include "sensesp_app.h" +#include "sensesp_app_builder.h" +#include "signalk/signalk_output.h" + +// SDA and SCL pins on SH-ESP32 +#define SDA_PIN 16 +#define SCL_PIN 17 + +// Opto in pin on SH-ESP32 +#define OPTO_IN_PIN 35 + +// OLED display width and height, in pixels +#define SCREEN_WIDTH 128 +#define SCREEN_HEIGHT 64 + +// define temperature display units +#define TEMP_DISPLAY_FUNC KelvinToCelsius +//#define TEMP_DISPLAY_FUNC KelvinToFahrenheit + +TwoWire* i2c; +Adafruit_SSD1306* display; + +/// Clear a text row on an Adafruit graphics display +void ClearRow(int row) { display->fillRect(0, 8 * row, SCREEN_WIDTH, 8, 0); } + +/** + * @brief Send Engine Dynamic Parameter data + * + * Send engine temperature data using the Engine Dynamic Parameter PGN. + * All unused fields that are sent with undefined value except the status + * bit fields are sent as zero. Hopefully we're not resetting anybody's engine + * warnings... + */ + +ReactESP app([]() { +// Some initialization boilerplate when in debug mode... +#ifndef SERIAL_DEBUG_DISABLED + SetupSerialDebug(115200); +#endif + + SensESPAppBuilder builder; + + sensesp_app = builder.set_hostname("nmea1_test") + ->set_standard_sensors(NONE) + ->get_app(); + + // initialize the display + i2c = new TwoWire(0); + i2c->begin(SDA_PIN, SCL_PIN); + display = new Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT, i2c, -1); + if (!display->begin(SSD1306_SWITCHCAPVCC, 0x3C)) { + debugW("SSD1306 allocation failed"); + } + delay(100); + display->setRotation(2); + display->clearDisplay(); + display->setTextSize(1); + display->setTextColor(SSD1306_WHITE); + display->setCursor(0, 0); + display->printf("Host: %s", sensesp_app->get_hostname().c_str()); + display->display(); + + // initialize Serial1 on the opto_in pin + + Serial1.begin(4800, SERIAL_8N1, OPTO_IN_PIN, -1, true); + + app.onAvailable(Serial1, []() { + Serial.write(Serial1.read()); + }); + + sensesp_app->enable(); +});