Skip to content

Commit

Permalink
Merge pull request #801 from SignalK/pioarduino
Browse files Browse the repository at this point in the history
Pioarduino support
  • Loading branch information
mairas authored Dec 20, 2024
2 parents eba5c3b + 1ff708e commit ac86d17
Show file tree
Hide file tree
Showing 31 changed files with 634 additions and 279 deletions.
37 changes: 20 additions & 17 deletions .github/workflows/test.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,33 @@ jobs:
strategy:
matrix:
example:
- examples/minimal_app.cpp
- examples/analog_input.cpp
- examples/hysteresis.cpp
- examples/lambda_transform.cpp
- examples/manual_networking.cpp
- examples/minimal_app.cpp
- examples/relay_control.cpp
- examples/rpm_counter.cpp
- examples/async_repeat_sensor.cpp
- examples/listener.cpp
- examples/repeat_sensor_analog_input.cpp
- examples/freertos_tasks.cpp
- examples/raw_json.cpp
- examples/constant_sensor.cpp
- examples/time_counter.cpp
target_device:
- esp32dev
- examples/rpm_counter.cpp
device:
- esp32
- esp32c3
platform:
- arduino
- pioarduino
# Can't build with espidf until there's a way to copy the
# sdkconfig.defaults file to the correct location in the
# CI build environment.
#- espidf
exclude:
- platform: arduino
device: esp32c3
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
Expand All @@ -42,4 +44,5 @@ jobs:
run: ci/run-ci.sh
env:
PLATFORMIO_CI_SRC: ${{ matrix.example }}
CI_TARGET_DEVICE: ${{ matrix.target_device }}
CI_DEVICE: ${{ matrix.device }}
CI_PLATFORM: ${{ matrix.platform }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
docs/Gemfile.lock
docs/.bundle
docs/_site
managed_components
23 changes: 0 additions & 23 deletions ci/platformio-esp32dev.ini

This file was deleted.

7 changes: 2 additions & 5 deletions ci/run-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ set -euo pipefail

# assume this command is always run from the project root directory

PROJDIR=$(pwd)

# replace the
sed -e "s|\${PROJDIR}|$PROJDIR|" ci/platformio-${CI_TARGET_DEVICE}.ini > ci/platformio.ini
export PROJDIR=$(pwd)

# the example to build comes from $PLATFORMIO_CI_SRC

pio ci -c ci/platformio.ini
pio ci -e ${CI_PLATFORM}_${CI_DEVICE} --project-conf platformio.ini --lib . --exclude examples --exclude docs --exclude .pio
7 changes: 7 additions & 0 deletions default_8MB.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x330000,
app1, app, ota_1, 0x340000,0x330000,
spiffs, data, spiffs, 0x670000,0x180000,
coredump, data, coredump,0x7F0000,0x10000,
10 changes: 10 additions & 0 deletions examples/freertos_tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include "sensesp/net/discovery.h"
#include "sensesp/net/http_server.h"
#include "sensesp/net/networking.h"
#include "sensesp/net/web/app_command_handler.h"
#include "sensesp/net/web/base_command_handler.h"
#include "sensesp/net/web/config_handler.h"
#include "sensesp/net/web/static_file_handler.h"
#include "sensesp/sensors/digital_input.h"
#include "sensesp/signalk/signalk_delta_queue.h"
#include "sensesp/signalk/signalk_output.h"
Expand Down Expand Up @@ -41,6 +45,12 @@ void setup() {
auto networking = std::make_shared<Networking>("/system/networking", "", "");
auto http_server = std::make_shared<HTTPServer>();

// Add the default HTTP server response handlers
add_static_file_handlers(http_server);
add_base_app_http_command_handlers(http_server);
add_app_http_command_handlers(http_server, networking);
add_config_handlers(http_server);

// create the SK delta object
auto sk_delta_queue_ = std::make_shared<SKDeltaQueue>();

Expand Down
File renamed without changes.
99 changes: 56 additions & 43 deletions examples/minimal_app.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
#include <math.h>

#include "sensesp/net/http_server.h"
#include "sensesp/net/networking.h"
#include "sensesp/net/web/app_command_handler.h"
#include "sensesp/net/web/base_command_handler.h"
#include "sensesp/net/web/config_handler.h"
#include "sensesp/net/web/static_file_handler.h"
#include "sensesp/signalk/signalk_delta_queue.h"
#include "sensesp/signalk/signalk_ws_client.h"
#include "sensesp/system/button.h"
#include "sensesp/sensors/digital_input.h"
#include "sensesp/transforms/lambda_transform.h"
#include "sensesp/transforms/linear.h"
#include "sensesp/transforms/typecast.h"
#include "sensesp_minimal_app_builder.h"

using namespace sensesp;

const unsigned int read_delay = 500;

constexpr int input_pin1 = 15;
constexpr int input_pin2 = 13;
constexpr int output_pin1 = 18;
constexpr int output_pin2 = 21;

// This is a sample program to demonstrate how to instantiate a
// SensESPMinimalApp application and only enable some required components
// explicitly.
Expand All @@ -26,46 +36,49 @@ void setup() {
SensESPMinimalAppBuilder builder;
auto sensesp_app = builder.set_hostname("counter-test")->get_app();

auto button_handler = std::make_shared<ButtonHandler>(0);

// As an example, we'll connect to WiFi manually using the Arduino ESP32 WiFi
// library instead of using the SensESP Networking class.

WiFi.mode(WIFI_STA); // Optional
WiFi.begin("ssid", "password");
Serial.println("\nConnecting");

while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(100);
}

Serial.println("\nConnected to the WiFi network");
Serial.print("Local ESP32 IP: ");
Serial.println(WiFi.localIP());

// Initiate the objects you need for your application here. Have a look
// at sensesp_app.h and pick the necessary items from there.

// create the SK delta queue
auto sk_delta_queue = std::make_shared<SKDeltaQueue>();

// Use this if you want to hardcode the Signal K server address
String sk_server_address = "openplotter.local";
// Use this if you want to hardcode the Signal K server port
uint16_t sk_server_port = 3000;
// Set this to true if you want to use mDNS to discover the Signal K server
bool use_mdns = false;

auto ws_client =
std::make_shared<SKWSClient>("/System/Signal K Settings", sk_delta_queue,
sk_server_address, sk_server_port, use_mdns);

// To avoid garbage collecting all shared pointers
// created in setup(), loop from here.
while (true) {
loop();
}
// manually create Networking and HTTPServer objects to enable
// the HTTP configuration interface

auto networking = std::make_shared<Networking>("/system/networking", "", "");
auto http_server = std::make_shared<HTTPServer>();

// Add the default HTTP server response handlers
add_static_file_handlers(http_server);
add_base_app_http_command_handlers(http_server);
add_app_http_command_handlers(http_server, networking);
add_config_handlers(http_server);

auto digin1 = std::make_shared<DigitalInputCounter>(input_pin1, INPUT, RISING,
read_delay);
auto digin2 = std::make_shared<DigitalInputCounter>(input_pin2, INPUT, CHANGE,
read_delay);

auto scaled1 = std::make_shared<Linear>(2, 1, "/digin1/scale");
auto scaled2 = std::make_shared<Linear>(4, -1, "/digin2/scale");
digin1->connect_to(scaled1);

auto lambda_transform1 =
std::make_shared<LambdaTransform<int, int>>([](int input) {
Serial.printf("millis: %d\n", millis());
Serial.printf("Counter 1: %d\n", input);
return input;
});
scaled1->connect_to(lambda_transform1);
auto lambda_transform2 =
std::make_shared<LambdaTransform<int, int>>([](int input) {
Serial.printf("Counter 2: %d\n", input);
return input;
});

digin2->connect_to(scaled2)->connect_to(lambda_transform2);

pinMode(output_pin1, OUTPUT);
event_loop()->onRepeat(
5, []() { digitalWrite(output_pin1, !digitalRead(output_pin1)); });

pinMode(output_pin2, OUTPUT);
event_loop()->onRepeat(
100, []() { digitalWrite(output_pin2, !digitalRead(output_pin2)); });
}

void loop() { event_loop()->tick(); }
Loading

0 comments on commit ac86d17

Please sign in to comment.