From 10b96424cd0f57e20314182fb46a8a7d384a51bf Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Tue, 31 Oct 2023 13:16:52 +0100 Subject: [PATCH] started development of Rs485 lib Signed-off-by: Stephan Richter --- SoftRS485.cpp | 35 +++++++++++++++++++++++++++++++++++ SoftRS485.h | 22 ++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 SoftRS485.cpp create mode 100644 SoftRS485.h diff --git a/SoftRS485.cpp b/SoftRS485.cpp new file mode 100644 index 0000000..e0c11ac --- /dev/null +++ b/SoftRS485.cpp @@ -0,0 +1,35 @@ +/* + Library for Software Serial over RS485 connection + Created by Stepan Richter, November 2023 +*/ + +#include "Arduino.h" +#include "SoftRS485.h" + +SoftRS485 SoftRS485::instance; + +SoftRS485 SoftRS485::singleton(){ + return instance; +} + +void SoftRS485::isr(){ + instance.bam(); +} + +void SoftRS485::begin(int RO, int nRE, int DE, int DI){ + _RO = RO; + _RE = nRE; + _DE = DE; + _DI = DI; + Serial.begin(115200); + pinMode(_RE, OUTPUT); + pinMode(_DE, OUTPUT); + pinMode(_DI, OUTPUT); + pinMode(_RO, INPUT); + attachInterrupt(digitalPinToInterrupt(_RO),isr,CHANGE); + Serial.println("attached to interrupt!"); +} + +void SoftRS485::bam(){ + Serial.println("bam!"); +} diff --git a/SoftRS485.h b/SoftRS485.h new file mode 100644 index 0000000..b6b9fb8 --- /dev/null +++ b/SoftRS485.h @@ -0,0 +1,22 @@ +/* + Library for Software Serial over RS485 connection + Created by Stepan Richter, November 2023 +*/ + +#ifndef SoftRS485_h +#define SoftRS485_h + +#include "Arduino.h" + +class SoftRS485{ + public: + void begin(int RO, int nRE, int DE, int DI); + void bam(); + static SoftRS485 singleton(); + private: + static void isr(); + static SoftRS485 instance; + int _RO, _RE, _DE, _DI; +}; + +#endif