From 65f48f99c33574207d336494c4822e8f66a9f599 Mon Sep 17 00:00:00 2001 From: Aadi Desai <21363892+supleed2@users.noreply.github.com> Date: Tue, 8 Jun 2021 20:26:59 +0100 Subject: [PATCH] Create Energy<->Control reference doc --- Control/ref/energy.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Control/ref/energy.cpp diff --git a/Control/ref/energy.cpp b/Control/ref/energy.cpp new file mode 100644 index 0000000..4bf9d86 --- /dev/null +++ b/Control/ref/energy.cpp @@ -0,0 +1,37 @@ +#include +#include +#include + +#define RXpin 0 // Define your RX pin here +#define TXpin 0 // Define your TX pin here + +void setup() +{ + Serial.begin(115200); // Set up hardware UART0 (Connected to USB port) + Serial1.begin(9600, SERIAL_8N1, RXpin, TXpin); // Set up hardware UART1 + + // Other Drive setup stuff +} + +void loop() +{ + bool charge; + DynamicJsonDocument rdoc(1024); // receive doc, not sure how big this needs to be + if(Serial1.available()){ + deserializeJson(rdoc, Serial1); // Take JSON input from UART1 + charge = rdoc["ch"]; // {"ch":0} + } + + + float stateOfCharge = 0; + float batteryVoltage = 0; + float batteryCycles = 0; + + // Do Drive stuff, set the 5 values above + + DynamicJsonDocument tdoc(1024); // transmit doc, not sure how big this needs to be + tdoc["soc"] = stateOfCharge; + tdoc["mV"] = batteryVoltage; + tdoc["cyc"] = batteryCycles; + serializeJson(tdoc, Serial1); // Build JSON and send on UART1 +} \ No newline at end of file