Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisBrock committed Jul 24, 2024
1 parent 6742f1a commit 473d5f8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
9 changes: 5 additions & 4 deletions src/Components/Modbus/ModbusRTU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#include <WiFi.h>
#include "HardwareSerial.h"
#include "ModbusClientRTU.h"
#include "../../Configuration/Pins.h"
#include "../../Configuration/Constants.h"
#include "ModbusRTU.h"

ModbusClientRTU gModbusRTU(Constants::Pins::PinRTS); // Create a ModbusRTU client instance
HardwareSerial gRs485Serial(1); // Define a Serial for UART1
ModbusClientRTU gModbusRTU(Pins::PinRTS); // Create a ModbusRTU client instance
HardwareSerial gRs485Serial(1); // Define a Serial for UART1
constexpr uint8_t RegisterSize = 2;

ModbusRTU *ModbusRTU::Instance()
Expand All @@ -23,8 +24,8 @@ void ModbusRTU::Init()
gRs485Serial.begin(
Constants::HeidelbergWallbox::ModbusBaudrate,
SERIAL_8E1,
Constants::Pins::PinRX,
Constants::Pins::PinTX);
Pins::PinRX,
Pins::PinTX);

// Start Modbus RTU
Serial.println("Creating Modbus RTU instance");
Expand Down
11 changes: 0 additions & 11 deletions src/Configuration/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@

namespace Constants
{
namespace Pins
{
// Pin connections:
// ESP32 GPIO18 -> MAXRS485 RO (Receiver Output)
// ESP32 GPIO19 -> MAXRS485 DI (Driver Input)
// ESP32 GPIO21 -> MAXRS485 DE+RE
constexpr uint8_t PinRX = GPIO_NUM_18;
constexpr uint8_t PinTX = GPIO_NUM_19;
constexpr uint8_t PinRTS = GPIO_NUM_21;
};

namespace WiFi
{
constexpr const char *HotspotSSID = "HeidelBridge";
Expand Down
12 changes: 12 additions & 0 deletions src/Configuration/Pins.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

namespace Pins
{
// Pin connections:
// ESP32 GPIO18 -> MAXRS485 RO (Receiver Output)
// ESP32 GPIO19 -> MAXRS485 DI (Driver Input)
// ESP32 GPIO21 -> MAXRS485 DE+RE
constexpr uint8_t PinRX = GPIO_NUM_18;
constexpr uint8_t PinTX = GPIO_NUM_19;
constexpr uint8_t PinRTS = GPIO_NUM_21;
};
5 changes: 3 additions & 2 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void setup()
// Make sure WiFi connection is up and running
WifiConnection::Init();

// Initialize all other modules
// Initialize wallbox
#ifndef DUMMY_WALLBOX
Serial.println("Starting with Heidelberg wallbox in real mode");
ModbusRTU::Instance()->Init();
Expand All @@ -29,8 +29,9 @@ void setup()
Serial.println("Starting with dummy wallbox in simulated mode");
gWallbox = DummyWallbox::Instance();
#endif

gWallbox->Init();

// Start Modbus TCP server
ModbusTCP::Init(gWallbox);

Serial.println("Setup complete");
Expand Down

0 comments on commit 473d5f8

Please sign in to comment.