Created chrono controller Web API
This commit is contained in:
53
include/ChronoAPI.hpp
Normal file
53
include/ChronoAPI.hpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#include "I2C_COM_API.hpp"
|
||||||
|
|
||||||
|
buffer<ChronoAPICommand> resetCommand;
|
||||||
|
buffer<ChronoAPICommand> startCommand;
|
||||||
|
buffer<ChronoAPICommand> stopCommand;
|
||||||
|
|
||||||
|
buffer<long> ChronoMillisecondsBuffer;
|
||||||
|
volatile long lastMs = 0x00;
|
||||||
|
bool logged = true;
|
||||||
|
|
||||||
|
void ConfigureAPI()
|
||||||
|
{
|
||||||
|
// Inicializar instancias de comandos
|
||||||
|
resetCommand.data.command = ChronoCommands::ForceReset;
|
||||||
|
startCommand.data.command = ChronoCommands::ForceStart;
|
||||||
|
stopCommand.data.command = ChronoCommands::ForceStop;
|
||||||
|
resetCommand.data.type = DATAGRAM_HDR;
|
||||||
|
stopCommand.data.type = DATAGRAM_HDR;
|
||||||
|
startCommand.data.type = DATAGRAM_HDR;
|
||||||
|
|
||||||
|
Logger::Log("CMD Reset");
|
||||||
|
for (int i = 0; i < sizeof(resetCommand.data); i++)
|
||||||
|
Logger::Log(String(resetCommand.buffer[i]));
|
||||||
|
Logger::Log("CMD Start");
|
||||||
|
for (int i = 0; i < sizeof(startCommand.data); i++)
|
||||||
|
Logger::Log(String(startCommand.buffer[i]));
|
||||||
|
Logger::Log("CMD Stop");
|
||||||
|
for (int i = 0; i < sizeof(stopCommand.data); i++)
|
||||||
|
Logger::Log(String(stopCommand.buffer[i]));
|
||||||
|
|
||||||
|
server.on("/api/getElapsedTime", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
|
String response = "{\"elapsed\":" + String(ChronoMillisecondsBuffer.data) + "}";
|
||||||
|
request->send(200, MIME_JSON, response); });
|
||||||
|
|
||||||
|
server.on("/api/stop", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
|
//commandBuffer.buffer
|
||||||
|
Logger::Log(Logger::DEBUG, "Received Stop request");
|
||||||
|
Wire.flush();
|
||||||
|
Wire.writeTransmission(0x26, stopCommand.buffer, sizeof(stopCommand.data));
|
||||||
|
request->send(200, MIME_HTML); });
|
||||||
|
server.on("/api/start", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
|
Logger::Log(Logger::DEBUG, "Received Start request");
|
||||||
|
Wire.writeTransmission(0x26, startCommand.buffer, sizeof(startCommand.data));
|
||||||
|
request->send(200, MIME_HTML); });
|
||||||
|
server.on("/api/reset", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
|
Logger::Log(Logger::DEBUG, "Received Reset request");
|
||||||
|
Wire.writeTransmission(0x26, resetCommand.buffer, sizeof(resetCommand.data));
|
||||||
|
request->send(200, MIME_HTML); });
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user