Update
This commit is contained in:
BIN
Railuino/examples/01.Controller/.DS_Store
vendored
Normal file
BIN
Railuino/examples/01.Controller/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
Railuino/examples/01.Controller/CV/.DS_Store
vendored
Normal file
BIN
Railuino/examples/01.Controller/CV/.DS_Store
vendored
Normal file
Binary file not shown.
68
Railuino/examples/01.Controller/CV/CV_new.ino
Normal file
68
Railuino/examples/01.Controller/CV/CV_new.ino
Normal file
@@ -0,0 +1,68 @@
|
||||
/*********************************************************************
|
||||
* Railuino - Hacking your Märklin
|
||||
*
|
||||
* Copyright (C) 2012 Joerg Pleumann
|
||||
* Copyright (C) 2024 Christophe Bobille
|
||||
*
|
||||
* This example is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the Creative Commons Zero License,
|
||||
* version 1.0, as published by the Creative Commons Organisation.
|
||||
* This effectively puts the file into the public domain.
|
||||
*
|
||||
* This example 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
|
||||
* LICENSE file for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This exemple is the update of examples/01.Controller/CV/CV_new.ino
|
||||
*/
|
||||
|
||||
#include "Config.h"
|
||||
#include "TrackController.h"
|
||||
|
||||
const uint16_t LOCO = ADDR_MFX + 7; // Change with your own address
|
||||
|
||||
const bool DEBUG = false;
|
||||
const uint64_t TIMEOUT = 500; // ms
|
||||
const uint16_t HASH = 0x00;
|
||||
const bool LOOPBACK = false;
|
||||
|
||||
TrackController ctrl(HASH, DEBUG, TIMEOUT, LOOPBACK); // Instance de la classe TrackController, création de l'objet ctrl.
|
||||
|
||||
void showRegister(uint16_t, String);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial)
|
||||
;
|
||||
|
||||
ctrl.begin();
|
||||
Serial.print("Power on\n\n");
|
||||
ctrl.setPower(true);
|
||||
|
||||
showRegister(1, "Address");
|
||||
showRegister(2, "Min. Voltage");
|
||||
showRegister(3, "Accel. time");
|
||||
showRegister(4, "Decel. time");
|
||||
showRegister(5, "Max. speed");
|
||||
showRegister(6, "Avg. speed");
|
||||
showRegister(7, "Version");
|
||||
showRegister(8, "Manufacturer");
|
||||
|
||||
Serial.println("\n\nSystem stopped. Need to reset.");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}// Nothing to do
|
||||
|
||||
void showRegister(uint16_t i, String label)
|
||||
{
|
||||
uint8_t b = 0;
|
||||
|
||||
if (ctrl.readConfig(LOCO, i, &b))
|
||||
Serial.print("Register "+label+" : "+b+"\n");
|
||||
}
|
||||
BIN
Railuino/examples/01.Controller/Direction/.DS_Store
vendored
Normal file
BIN
Railuino/examples/01.Controller/Direction/.DS_Store
vendored
Normal file
Binary file not shown.
68
Railuino/examples/01.Controller/Direction/Direction_new.ino
Normal file
68
Railuino/examples/01.Controller/Direction/Direction_new.ino
Normal file
@@ -0,0 +1,68 @@
|
||||
/*********************************************************************
|
||||
* Railuino - Hacking your Märklin
|
||||
*
|
||||
* Copyright (C) 2012 Joerg Pleumann
|
||||
* Copyright (C) 2024 Christophe Bobille
|
||||
*
|
||||
* This example is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the Creative Commons Zero License,
|
||||
* version 1.0, as published by the Creative Commons Organisation.
|
||||
* This effectively puts the file into the public domain.
|
||||
*
|
||||
* This example 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
|
||||
* LICENSE file for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This exemple is the update of examples/01.Controller/Direction/Direction.ino
|
||||
*/
|
||||
|
||||
|
||||
#include "Config.h"
|
||||
#include "TrackController.h"
|
||||
|
||||
const uint16_t LOCO = ADDR_MFX + 7; // Change with your own address
|
||||
|
||||
const uint16_t PAUSE = 10UL * 1000UL;
|
||||
|
||||
const bool DEBUG = false;
|
||||
const uint64_t TIMEOUT = 500; // ms
|
||||
const uint16_t HASH = 0x00;
|
||||
const bool LOOPBACK = false;
|
||||
|
||||
TrackController ctrl(HASH, DEBUG, TIMEOUT, LOOPBACK); // Instance de la classe TrackController, création de l'objet ctrl.
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
ctrl.begin();
|
||||
Serial.println("Power on");
|
||||
ctrl.setPower(true);
|
||||
Serial.println("Headlights on");
|
||||
ctrl.setLocoFunction(LOCO, 0, 1);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
byte b;
|
||||
|
||||
ctrl.setLocoDirection(LOCO, DIR_FORWARD);
|
||||
if (ctrl.getLocoDirection(LOCO, &b)) {
|
||||
Serial.print("Direction is ");
|
||||
Serial.println(b == DIR_FORWARD ? "forward" : "reverse");
|
||||
}
|
||||
|
||||
delay(PAUSE);
|
||||
|
||||
ctrl.setLocoDirection(LOCO, DIR_REVERSE);
|
||||
if (ctrl.getLocoDirection(LOCO, &b)) {
|
||||
Serial.print("Direction is ");
|
||||
Serial.println(b == DIR_FORWARD ? "forward" : "reverse");
|
||||
}
|
||||
|
||||
delay(PAUSE);
|
||||
}
|
||||
|
||||
BIN
Railuino/examples/01.Controller/Function/.DS_Store
vendored
Normal file
BIN
Railuino/examples/01.Controller/Function/.DS_Store
vendored
Normal file
Binary file not shown.
82
Railuino/examples/01.Controller/Function/Function_new.ino
Normal file
82
Railuino/examples/01.Controller/Function/Function_new.ino
Normal file
@@ -0,0 +1,82 @@
|
||||
/*********************************************************************
|
||||
* Railuino - Hacking your Märklin
|
||||
*
|
||||
* Copyright (C) 2012 Joerg Pleumann
|
||||
* Copyright (C) 2024 Christophe Bobille
|
||||
*
|
||||
* This example is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the Creative Commons Zero License,
|
||||
* version 1.0, as published by the Creative Commons Organisation.
|
||||
* This effectively puts the file into the public domain.
|
||||
*
|
||||
* This example 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
|
||||
* LICENSE file for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This exemple is the update of examples/01.Controller/Function/Function_new.ino
|
||||
*/
|
||||
|
||||
#include "Config.h"
|
||||
#include "TrackController.h"
|
||||
|
||||
const uint16_t LOCO = ADDR_MFX + 7; // Change with your own address
|
||||
|
||||
const uint16_t PAUSE = 5UL * 1000UL;
|
||||
|
||||
const bool DEBUG = false;
|
||||
const uint64_t TIMEOUT = 500; // ms
|
||||
const uint16_t HASH = 0x00;
|
||||
const bool LOOPBACK = false;
|
||||
|
||||
TrackController ctrl(HASH, DEBUG, TIMEOUT, LOOPBACK); // Instance de la classe TrackController, création de l'objet ctrl.
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial)
|
||||
;
|
||||
|
||||
ctrl.begin();
|
||||
Serial.println("Power on");
|
||||
ctrl.setPower(true);
|
||||
|
||||
byte b;
|
||||
|
||||
for (uint8_t i = 0; i <= 12; i++)
|
||||
{
|
||||
// Serial.print("Function ");
|
||||
// Serial.print(i, DEC);
|
||||
|
||||
ctrl.setLocoFunction(LOCO, i, 1);
|
||||
if (ctrl.getLocoFunction(LOCO, i, &b))
|
||||
{
|
||||
Serial.print("Function ");
|
||||
Serial.print(i, DEC);
|
||||
Serial.println(b ? " is on" : " is off");
|
||||
}
|
||||
|
||||
delay(PAUSE);
|
||||
|
||||
ctrl.setLocoFunction(LOCO, i, 0);
|
||||
if (ctrl.getLocoFunction(LOCO, i, &b))
|
||||
{
|
||||
Serial.print("Function ");
|
||||
Serial.print(i, DEC);
|
||||
Serial.println(b ? " is on" : " is off");
|
||||
}
|
||||
|
||||
delay(PAUSE);
|
||||
}
|
||||
|
||||
Serial.println("Power off");
|
||||
ctrl.setPower(false);
|
||||
|
||||
Serial.println("System stopped. Need to reset.");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
} // Nothing to do
|
||||
65
Railuino/examples/01.Controller/Headlight/Headlight_new.ino
Normal file
65
Railuino/examples/01.Controller/Headlight/Headlight_new.ino
Normal file
@@ -0,0 +1,65 @@
|
||||
/*********************************************************************
|
||||
* Railuino - Hacking your Märklin
|
||||
*
|
||||
* Copyright (C) 2012 Joerg Pleumann
|
||||
* Copyright (C) 2024 Christophe Bobille
|
||||
*
|
||||
* This example is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the Creative Commons Zero License,
|
||||
* version 1.0, as published by the Creative Commons Organisation.
|
||||
* This effectively puts the file into the public domain.
|
||||
*
|
||||
* This example 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
|
||||
* LICENSE file for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This exemple is the update of examples/01.Controller/Headlight/Headlight_new.ino
|
||||
*/
|
||||
|
||||
#include "Config.h"
|
||||
#include "TrackController.h"
|
||||
|
||||
const uint16_t LOCO = ADDR_MFX + 7; // Change with your own address
|
||||
|
||||
const uint16_t PAUSE = 5UL * 1000UL;
|
||||
|
||||
const bool DEBUG = false;
|
||||
const uint64_t TIMEOUT = 500; // ms
|
||||
const uint16_t HASH = 0x00;
|
||||
const bool LOOPBACK = false;
|
||||
|
||||
TrackController ctrl(HASH, DEBUG, TIMEOUT, LOOPBACK); // Instance de la classe TrackController, création de l'objet ctrl.
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
ctrl.begin();
|
||||
Serial.println("Power on");
|
||||
ctrl.setPower(true);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
byte b;
|
||||
|
||||
ctrl.setLocoFunction(LOCO, 0, 1);
|
||||
if (ctrl.getLocoFunction(LOCO, 0, &b)) {
|
||||
Serial.print("Lights are ");
|
||||
Serial.println(b ? "on" : "off");
|
||||
}
|
||||
|
||||
delay(PAUSE);
|
||||
|
||||
ctrl.setLocoFunction(LOCO, 0, 0);
|
||||
if (ctrl.getLocoFunction(LOCO, 0, &b)) {
|
||||
Serial.print("Lights are ");
|
||||
Serial.println(b ? "on" : "off");
|
||||
}
|
||||
|
||||
delay(PAUSE);
|
||||
}
|
||||
|
||||
|
||||
BIN
Railuino/examples/01.Controller/Power/.DS_Store
vendored
Normal file
BIN
Railuino/examples/01.Controller/Power/.DS_Store
vendored
Normal file
Binary file not shown.
48
Railuino/examples/01.Controller/Power/Power_new.ino
Normal file
48
Railuino/examples/01.Controller/Power/Power_new.ino
Normal file
@@ -0,0 +1,48 @@
|
||||
/*********************************************************************
|
||||
* Railuino - Hacking your Märklin
|
||||
*
|
||||
* Copyright (C) 2012 Joerg Pleumann
|
||||
* Copyright (C) 2024 Christophe Bobille
|
||||
*
|
||||
* This example is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the Creative Commons Zero License,
|
||||
* version 1.0, as published by the Creative Commons Organisation.
|
||||
* This effectively puts the file into the public domain.
|
||||
*
|
||||
* This example 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
|
||||
* LICENSE file for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This exemple is the update of examples/01.Controller/Power/Power.ino
|
||||
*/
|
||||
|
||||
#include "Config.h"
|
||||
#include "TrackController.h"
|
||||
|
||||
const uint16_t PAUSE = 5000;
|
||||
const bool DEBUG = true;
|
||||
const uint64_t TIMEOUT = 500; // ms
|
||||
const uint16_t HASH = 0x00;
|
||||
const bool LOOPBACK = false;
|
||||
|
||||
TrackController ctrl(HASH, DEBUG, TIMEOUT, LOOPBACK); // Instance de la classe TrackController, création de l'objet ctrl.
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
ctrl.begin(); // Lancement du contrôleur
|
||||
}
|
||||
|
||||
void loop() {
|
||||
ctrl.setPower(true); // Allumage de la centrale
|
||||
delay(PAUSE);
|
||||
|
||||
ctrl.setPower(false); // Extinction de la centrale
|
||||
delay(PAUSE);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*********************************************************************
|
||||
* Railuino - Hacking your Märklin
|
||||
*
|
||||
* Copyright (C) 2012 Joerg Pleumann
|
||||
* Copyright (C) 2024 Christophe Bobille
|
||||
*
|
||||
* This example is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the Creative Commons Zero License,
|
||||
* version 1.0, as published by the Creative Commons Organisation.
|
||||
* This effectively puts the file into the public domain.
|
||||
*
|
||||
* This example 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
|
||||
* LICENSE file for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This exemple is the update of examples/01.Controller/SerialCommand/SerialCommand.ino
|
||||
*/
|
||||
|
||||
/*
|
||||
* Exemple :
|
||||
power 1
|
||||
speed 16391 100
|
||||
function 16391 0 1
|
||||
*/
|
||||
|
||||
#include "Config.h"
|
||||
#include "TrackController.h"
|
||||
|
||||
const bool DEBUG = false;
|
||||
const uint64_t TIMEOUT = 500; // ms
|
||||
const uint16_t HASH = 0x00;
|
||||
const bool LOOPBACK = false;
|
||||
|
||||
TrackController ctrl(HASH, DEBUG, TIMEOUT, LOOPBACK); // Instance de la classe TrackController, création de l'objet ctrl.
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial)
|
||||
;
|
||||
ctrl.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (Serial.available())
|
||||
{
|
||||
String command = Serial.readStringUntil('\n');
|
||||
Serial.println(command);
|
||||
ctrl.handleUserCommands(command);
|
||||
}
|
||||
}
|
||||
94
Railuino/examples/01.Controller/SerialCommand/TCPCommand.ino
Normal file
94
Railuino/examples/01.Controller/SerialCommand/TCPCommand.ino
Normal file
@@ -0,0 +1,94 @@
|
||||
/*********************************************************************
|
||||
* Railuino - Hacking your Märklin
|
||||
*
|
||||
* Copyright (C) 2012 Joerg Pleumann
|
||||
* Copyright (C) 2024 Christophe Bobille
|
||||
*
|
||||
* This example is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the Creative Commons Zero License,
|
||||
* version 1.0, as published by the Creative Commons Organisation.
|
||||
* This effectively puts the file into the public domain.
|
||||
*
|
||||
* This example 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
|
||||
* LICENSE file for more details.
|
||||
*/
|
||||
|
||||
|
||||
#include "Config.h"
|
||||
#include "TrackController.h"
|
||||
//----------------------------------------------------------------------------------------
|
||||
// Include files
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
#include <ACAN_ESP32.h> // https://github.com/pierremolinaro/acan-esp32.git
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
const uint16_t LOCO = ADDR_MFX + 7; // Change with your own address
|
||||
const bool DEBUG = true;
|
||||
|
||||
byte cBuffer[13]; // CAN buffer
|
||||
byte sBuffer[13]; // Serial buffer
|
||||
|
||||
TrackController ctrl(0xDF24, DEBUG);
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// TCP/WIFI-ETHERNET
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
const char *ssid = "**********";
|
||||
const char *password = "**********";
|
||||
IPAddress ip(192, 168, 1, 103);
|
||||
IPAddress gateway(192, 168, 1, 254);
|
||||
IPAddress subnet(255, 255, 255, 0);
|
||||
const uint port = 15731;
|
||||
WiFiServer server(port);
|
||||
WiFiClient client;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial)
|
||||
;
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected.");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
server.begin();
|
||||
|
||||
ctrl.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
while (!client) // listen for incoming clients
|
||||
client = server.available();
|
||||
if (client.connected())
|
||||
{
|
||||
if (client.available())
|
||||
{
|
||||
String command = client.readStringUntil('\n');
|
||||
|
||||
Serial.println(command);
|
||||
ctrl.handleUserCommands(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (!client.connected())
|
||||
// {
|
||||
// Serial.println("Client disconnected.");
|
||||
// client.stop();
|
||||
// }
|
||||
308
Railuino/examples/01.Controller/SerialCommand/WebCommand
Normal file
308
Railuino/examples/01.Controller/SerialCommand/WebCommand
Normal file
@@ -0,0 +1,308 @@
|
||||
|
||||
|
||||
#ifndef ARDUINO_ARCH_ESP32
|
||||
#error "Select an ESP32 board"
|
||||
#endif
|
||||
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <WebServer.h>
|
||||
#include <SPIFFS.h>
|
||||
#include <ACAN_ESP32.h>
|
||||
#include "Config.h"
|
||||
#include "TrackController.h"
|
||||
|
||||
bool powerState = false; // Variable globale pour suivre l'état de l'alimentation
|
||||
const bool DEBUG = true;
|
||||
|
||||
byte cBuffer[13];
|
||||
byte sBuffer[13];
|
||||
|
||||
const gpio_num_t can_rx_pin = GPIO_NUM_22;
|
||||
const gpio_num_t can_tx_pin = GPIO_NUM_23;
|
||||
|
||||
//TrackController ctrl; // Instance without parameters
|
||||
//TrackController ctrl(500); // Instance by changing the default exchangeMessage timeout from 1000ms to 500ms
|
||||
//TrackController ctrl(0xDF24, DEBUG); // Instance with hash, debug and defaut exchangeMessage timeout = 1000
|
||||
TrackController ctrl(0xDF24, DEBUG, 500); // Instance with hash, debug and exchangeMessage timeout = 500
|
||||
|
||||
|
||||
|
||||
// const char *ssid = "**********";
|
||||
// const char *password = "**********";
|
||||
const char *ssid = "Livebox-BC90";
|
||||
const char *password = "V9b7qzKFxdQfbMT4Pa";
|
||||
|
||||
|
||||
IPAddress ip(192, 168, 1, 103);
|
||||
IPAddress gateway(192, 168, 1, 254);
|
||||
IPAddress subnet(255, 255, 255, 0);
|
||||
const uint port = 80;
|
||||
|
||||
WebServer server(port);
|
||||
|
||||
void handleRoot();
|
||||
void handleCss();
|
||||
void handleJs();
|
||||
void handleImage1();
|
||||
void handleImage2();
|
||||
void handleImage3();
|
||||
void handleImage4();
|
||||
void handleFavinco();
|
||||
void handleSetPower();
|
||||
void handleSetStop();
|
||||
void handleSetSystemHalt();
|
||||
void handleSetDirection();
|
||||
void handleSetSpeed();
|
||||
void handleSetAddress();
|
||||
void handleSetFunction();
|
||||
void handleNotFound();
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
if (!SPIFFS.begin(true))
|
||||
{
|
||||
Serial.print("An error has occurred while mounting SPIFFS\n");
|
||||
return;
|
||||
}
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected.");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
server.on("/", handleRoot);
|
||||
server.on("/style.css", handleCss);
|
||||
server.on("/script.js", handleJs);
|
||||
server.on("/image1.jpg", handleImage1);
|
||||
server.on("/image2.jpg", handleImage2);
|
||||
server.on("/image3.jpg", handleImage3);
|
||||
server.on("/image4.jpg", handleImage4);
|
||||
server.on("/favicon.ico", handleFavinco);
|
||||
|
||||
server.on("/setPower", HTTP_POST, handleSetPower);
|
||||
server.on("/setStop", HTTP_POST, handleSetStop);
|
||||
server.on("/setSystemHalt", HTTP_POST, handleSetSystemHalt);
|
||||
server.on("/setDirection", HTTP_POST, handleSetDirection);
|
||||
server.on("/setSpeed", HTTP_POST, handleSetSpeed);
|
||||
server.on("/setAddress", HTTP_POST, handleSetAddress);
|
||||
server.on("/setFunction", HTTP_POST, handleSetFunction);
|
||||
server.onNotFound(handleNotFound);
|
||||
|
||||
server.begin();
|
||||
ctrl.begin(can_rx_pin, can_tx_pin);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
server.handleClient();
|
||||
}
|
||||
|
||||
|
||||
void handleRoot()
|
||||
{
|
||||
File file = SPIFFS.open("/index.html", "r");
|
||||
if (!file)
|
||||
{
|
||||
server.send(500, "text/plain", "File not found");
|
||||
return;
|
||||
}
|
||||
size_t sent = server.streamFile(file, "text/html");
|
||||
file.close();
|
||||
}
|
||||
|
||||
void handleCss()
|
||||
{
|
||||
File file = SPIFFS.open("/style.css", "r");
|
||||
if (!file)
|
||||
{
|
||||
server.send(500, "text/plain", "File not found");
|
||||
return;
|
||||
}
|
||||
size_t sent = server.streamFile(file, "text/css");
|
||||
file.close();
|
||||
}
|
||||
|
||||
void handleJs()
|
||||
{
|
||||
File file = SPIFFS.open("/script.js", "r");
|
||||
if (!file)
|
||||
{
|
||||
server.send(500, "text/plain", "File not found");
|
||||
return;
|
||||
}
|
||||
size_t sent = server.streamFile(file, "text/javascript");
|
||||
file.close();
|
||||
}
|
||||
|
||||
void handleImage1()
|
||||
{
|
||||
File file = SPIFFS.open("/image1.jpg", "r");
|
||||
if (!file)
|
||||
{
|
||||
server.send(500, "text/plain", "File not found");
|
||||
return;
|
||||
}
|
||||
size_t sent = server.streamFile(file, "image/jpg");
|
||||
file.close();
|
||||
}
|
||||
|
||||
void handleImage2()
|
||||
{
|
||||
File file = SPIFFS.open("/image2.jpg", "r");
|
||||
if (!file)
|
||||
{
|
||||
server.send(500, "text/plain", "File not found");
|
||||
return;
|
||||
}
|
||||
size_t sent = server.streamFile(file, "image/jpg");
|
||||
file.close();
|
||||
}
|
||||
|
||||
void handleImage3()
|
||||
{
|
||||
File file = SPIFFS.open("/image3.jpg", "r");
|
||||
if (!file)
|
||||
{
|
||||
server.send(500, "text/plain", "File not found");
|
||||
return;
|
||||
}
|
||||
size_t sent = server.streamFile(file, "image/jpg");
|
||||
file.close();
|
||||
}
|
||||
|
||||
void handleImage4()
|
||||
{
|
||||
File file = SPIFFS.open("/image4.jpg", "r");
|
||||
if (!file)
|
||||
{
|
||||
server.send(500, "text/plain", "File not found");
|
||||
return;
|
||||
}
|
||||
size_t sent = server.streamFile(file, "image/jpg");
|
||||
file.close();
|
||||
}
|
||||
|
||||
void handleFavinco()
|
||||
{
|
||||
File file = SPIFFS.open("/favicon.ico", "r");
|
||||
if (!file)
|
||||
{
|
||||
server.send(500, "text/plain", "File not found");
|
||||
return;
|
||||
}
|
||||
size_t sent = server.streamFile(file, "image/x-icon");
|
||||
file.close();
|
||||
}
|
||||
|
||||
void handleSetPower()
|
||||
{
|
||||
auto togglePower = [&]() -> bool
|
||||
{
|
||||
powerState = !powerState;
|
||||
return ctrl.setPower(powerState);
|
||||
};
|
||||
|
||||
if (togglePower())
|
||||
{
|
||||
if (powerState)
|
||||
server.send(200, "text/plain", "true");
|
||||
else
|
||||
server.send(200, "text/plain", "false");
|
||||
}
|
||||
else
|
||||
server.send(200, "text/plain", "Error power function");
|
||||
}
|
||||
|
||||
void handleSetStop()
|
||||
{
|
||||
if (server.hasArg("address"))
|
||||
{
|
||||
uint16_t address = server.arg("address").toInt();
|
||||
const bool ok = ctrl.setLocoSpeed(address, 0);
|
||||
if (ok)
|
||||
server.send(200, "text/plain", "Stop");
|
||||
else
|
||||
server.send(400, "text/plain", "Server error");
|
||||
}
|
||||
}
|
||||
|
||||
void handleSetSystemHalt()
|
||||
{
|
||||
|
||||
if (server.hasArg("address"))
|
||||
{
|
||||
uint16_t address = server.arg("address").toInt();
|
||||
const bool ok = ctrl.systemHalt(address);
|
||||
if (ok)
|
||||
server.send(200, "text/plain", "SystemHalt");
|
||||
else
|
||||
server.send(200, "text/plain", " Server erro#");
|
||||
}
|
||||
else
|
||||
server.send(400, "text/plain", "Address parameter missing");
|
||||
}
|
||||
|
||||
void handleSetDirection()
|
||||
{
|
||||
if (server.hasArg("address"))
|
||||
{
|
||||
uint16_t address = server.arg("address").toInt();
|
||||
ctrl.toggleLocoDirection(address);
|
||||
server.send(200, "text/plain", "Direction toggled");
|
||||
}
|
||||
else
|
||||
server.send(400, "text/plain", "Address parameter missing");
|
||||
}
|
||||
|
||||
void handleSetSpeed()
|
||||
{
|
||||
uint16_t address = 0;
|
||||
uint16_t speed = 0;
|
||||
if (server.hasArg("address") && server.hasArg("speed"))
|
||||
{
|
||||
address = server.arg("address").toInt();
|
||||
speed = server.arg("speed").toInt();
|
||||
ctrl.setLocoSpeed(address, speed);
|
||||
server.send(200, "text/plain", "Speed set");
|
||||
}
|
||||
else
|
||||
server.send(400, "text/plain", "Speed parameter missing");
|
||||
}
|
||||
|
||||
void handleSetAddress()
|
||||
{
|
||||
if (server.hasArg("address"))
|
||||
{
|
||||
uint16_t address = server.arg("address").toInt();
|
||||
server.send(200, "text/plain", "Address set");
|
||||
}
|
||||
else
|
||||
server.send(400, "text/plain", "Address parameter missing");
|
||||
}
|
||||
|
||||
void handleSetFunction()
|
||||
{
|
||||
if (server.hasArg("address") && server.hasArg("function") && server.hasArg("power"))
|
||||
{
|
||||
uint16_t address = server.arg("address").toInt();
|
||||
uint8_t function = server.arg("function").toInt();
|
||||
uint8_t power = server.arg("power").toInt();
|
||||
ctrl.setLocoFunction(address, function, power);
|
||||
server.send(200, "text/plain", "Function set");
|
||||
}
|
||||
else
|
||||
server.send(400, "text/plain", "Function parameter missing");
|
||||
}
|
||||
|
||||
void handleNotFound()
|
||||
{
|
||||
server.send(404, "text/plain", "Not found");
|
||||
}
|
||||
BIN
Railuino/examples/01.Controller/Speed/.DS_Store
vendored
Normal file
BIN
Railuino/examples/01.Controller/Speed/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
Railuino/examples/01.Controller/Test_address_loco.zip
Normal file
BIN
Railuino/examples/01.Controller/Test_address_loco.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user