From 5d6aa75ea8e7d4c1d9417934f2c953c5beb6c2b4 Mon Sep 17 00:00:00 2001 From: GHOSCHT <31184695+GHOSCHT@users.noreply.github.com> Date: Sun, 10 Apr 2022 10:27:35 +0200 Subject: [PATCH] Implement Bluetooth --- .../lib/BluetoothCommunicator/BluetoothCommunicator.cpp | 8 ++++++++ .../lib/BluetoothCommunicator/BluetoothCommunicator.h | 8 ++++++++ Firmware/src/main.cpp | 8 +++++++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 Firmware/lib/BluetoothCommunicator/BluetoothCommunicator.cpp create mode 100644 Firmware/lib/BluetoothCommunicator/BluetoothCommunicator.h diff --git a/Firmware/lib/BluetoothCommunicator/BluetoothCommunicator.cpp b/Firmware/lib/BluetoothCommunicator/BluetoothCommunicator.cpp new file mode 100644 index 0000000..e572651 --- /dev/null +++ b/Firmware/lib/BluetoothCommunicator/BluetoothCommunicator.cpp @@ -0,0 +1,8 @@ +#include +#include + +BluetoothCommunicator::BluetoothCommunicator(BluetoothSerial &p_out, int timeout, __SIZE_TYPE__ bufferSize) : StreamCommunicator(p_out, bufferSize) +{ + p_out.begin("Heliox"); + p_out.setTimeout(timeout); +} \ No newline at end of file diff --git a/Firmware/lib/BluetoothCommunicator/BluetoothCommunicator.h b/Firmware/lib/BluetoothCommunicator/BluetoothCommunicator.h new file mode 100644 index 0000000..d8ec316 --- /dev/null +++ b/Firmware/lib/BluetoothCommunicator/BluetoothCommunicator.h @@ -0,0 +1,8 @@ +#include +#include "BluetoothSerial.h" + +class BluetoothCommunicator : public StreamCommunicator +{ +public: + BluetoothCommunicator(BluetoothSerial &p_out, int timeout, __SIZE_TYPE__ bufferSize); +}; diff --git a/Firmware/src/main.cpp b/Firmware/src/main.cpp index 0eb6daa..6f6cc36 100644 --- a/Firmware/src/main.cpp +++ b/Firmware/src/main.cpp @@ -1,24 +1,30 @@ #include #include #include -#include +#include #include StreamCommunicator *computer; +StreamCommunicator *phone; LightController *light; const int STEPS = 5; +BluetoothSerial bt; void setup() { int bjtCount = 4; const int bjtPin[bjtCount] = {SIG1A, SIG1B, SIG2A, SIG2B}; computer = new SerialCommunicator(Serial, 9600, 5, 50); + phone = new BluetoothCommunicator(bt,5,50); light = new LightController(bjtPin, bjtCount); } void loop() { light->updateState(computer->receiveMessage(), STEPS); + light->updateState(phone->receiveMessage(), STEPS); computer->sendMessage(light->getBjtState(), light->getBjtCount()); computer->clearBuffer(); + phone->sendMessage(light->getBjtState(), light->getBjtCount()); + phone->clearBuffer(); } \ No newline at end of file