Skip to content

Commit b0458ad

Browse files
create COMMClass as separate module
1 parent 02506aa commit b0458ad

File tree

11 files changed

+107
-111
lines changed

11 files changed

+107
-111
lines changed

examples/CAN/ReadCan/ReadCan.ino

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include <Arduino_MachineControl.h>
1313
#include <CAN.h>
1414

15-
using namespace machinecontrol;
16-
1715
#define DATARATE_2MB 2000000
1816
#define DATARATE_1_5MB 1500000
1917
#define DATARATE_1MB 1000000

examples/CAN/WriteCan/WriteCan.ino

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
*/
1212
#include <Arduino_MachineControl.h>
1313
#include <CAN.h>
14-
using namespace machinecontrol;
1514

1615
#define DATARATE_2MB 2000000
1716
#define DATARATE_1_5MB 1500000

examples/RS232/RS232.ino

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
#include <Arduino_MachineControl.h>
1919

20-
using namespace machinecontrol;
21-
2220
constexpr unsigned long sendInterval { 1000 };
2321
unsigned long sendNow { 0 };
2422

examples/RS485_fullduplex/RS485_fullduplex.ino

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
#include "Arduino_MachineControl.h"
1919

20-
using namespace machinecontrol;
21-
2220
constexpr unsigned long sendInterval { 1000 };
2321
unsigned long sendNow { 0 };
2422
unsigned long counter = 0;

examples/RS485_halfduplex/RS485_halfduplex.ino

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
#include "Arduino_MachineControl.h"
1818

19-
using namespace machinecontrol;
20-
2119
constexpr unsigned long sendInterval { 1000 };
2220
unsigned long sendNow { 0 };
2321

src/Arduino_MachineControl.h

+4-89
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
#ifndef __MACHINE_CONTROL_H__
2-
#define __MACHINE_CONTROL_H__
3-
4-
#include "utility/MAX31865/MAX31865.h"
5-
#include "utility/THERMOCOUPLE/MAX31855.h"
6-
#include <ArduinoRS485.h>
7-
#include "utility/QEI/QEI.h"
8-
#include "utility/ioexpander/ArduinoIOExpander.h"
9-
#include "utility/RTC/PCF8563T.h"
10-
11-
#include <Arduino.h>
12-
#include <pinDefinitions.h>
13-
#include <mbed.h>
1+
#ifndef __ARDUINO_MACHINE_CONTROL_H
2+
#define __ARDUINO_MACHINE_CONTROL_H
143

154
#include "AnalogInClass.h"
165
#include "AnalogOutClass.h"
@@ -21,80 +10,6 @@
2110
#include "RtcControllerClass.h"
2211
#include "USBClass.h"
2312
#include "EncoderClass.h"
13+
#include "COMMClass.h"
2414

25-
namespace machinecontrol {
26-
27-
/**
28-
* The COMMClass is used to initialize the CAN and RS485 LEDs and
29-
* establish the power mode of the CAN bus.
30-
*/
31-
class COMMClass {
32-
public:
33-
// to be tested: check if can be made a big pin initialization
34-
35-
/**
36-
* Shutdown RS485 and CAN LEDs
37-
*/
38-
void init() {
39-
//SHUTDOWN OF RS485 LEDS
40-
digitalWrite(PinNameToIndex(PA_0), LOW);
41-
digitalWrite(PinNameToIndex(PI_9), LOW);
42-
//SHUTDOWN OF CAN LEDS
43-
digitalWrite(PinNameToIndex(PB_8), HIGH);
44-
digitalWrite(PinNameToIndex(PH_13), HIGH);
45-
46-
// SET DEFAULTS for RS485
47-
rs485Enable(false);
48-
rs485ModeRS232(false);
49-
rs485FullDuplex(false);
50-
rs485YZTerm(false);
51-
rs485ABTerm(false);
52-
rs485Slew(false);
53-
}
54-
55-
/**
56-
* Set the CAN transceiver in Normal mode. In this mode, the transceiver
57-
* can transmit and receive data via the bus lines CANH and CANL.
58-
*/
59-
void enableCAN() {
60-
can_disable = 0;
61-
}
62-
63-
/**
64-
* Set the CAN transceiver in standby (low power) mode. In this mode the
65-
* transceiver will not be able to transmit or correctly receive data via the bus lines.
66-
* The wake-up filter on the output of the low-power receiver does not latch bus dominant states,
67-
* but ensures that only bus dominant and bus recessive states that persist longer than tfltr(wake)
68-
* bus are reflected on pin RXD.
69-
*/
70-
void disableCAN() {
71-
can_disable = 1;
72-
}
73-
74-
arduino::UART _UART4_ {PA_0, PI_9, NC, NC};
75-
mbed::CAN can {PB_8, PH_13};
76-
77-
RS485Class rs485 {_UART4_, PinNameToIndex(PA_0), PinNameToIndex(PI_13), PinNameToIndex(PI_10)};
78-
79-
void rs485Enable(bool enable) { digitalWrite(PinNameToIndex(PG_9), enable ? HIGH : LOW); }
80-
void rs485ModeRS232(bool enable) { digitalWrite(PinNameToIndex(PA_10), enable ? LOW : HIGH); }
81-
void rs485YZTerm(bool enable) { digitalWrite(PinNameToIndex(PI_15), enable ? HIGH : LOW); }
82-
void rs485ABTerm(bool enable) { digitalWrite(PinNameToIndex(PI_14), enable ? HIGH : LOW); }
83-
void rs485Slew(bool enable) { digitalWrite(PinNameToIndex(PG_14), enable ? LOW : HIGH); }
84-
void rs485FullDuplex(bool enable) {
85-
digitalWrite(PinNameToIndex(PA_9), enable ? LOW : HIGH);
86-
if (enable) {
87-
// RS485 Full Duplex require YZ and AB 120 Ohm termination enabled
88-
rs485YZTerm(true);
89-
rs485ABTerm(true);
90-
}
91-
}
92-
93-
private:
94-
mbed::DigitalOut can_disable = mbed::DigitalOut(PA_13, 0);
95-
};
96-
97-
extern COMMClass comm_protocols;
98-
99-
}
100-
#endif
15+
#endif /* __ARDUINO_MACHINE_CONTROL_H */

src/COMMClass.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "COMMClass.h"
2+
3+
void COMMClass::init() {
4+
//SHUTDOWN OF RS485 LEDS
5+
digitalWrite(PinNameToIndex(PA_0), LOW);
6+
digitalWrite(PinNameToIndex(PI_9), LOW);
7+
//SHUTDOWN OF CAN LEDS
8+
digitalWrite(PinNameToIndex(PB_8), HIGH);
9+
digitalWrite(PinNameToIndex(PH_13), HIGH);
10+
11+
// SET DEFAULTS for RS485
12+
rs485Enable(false);
13+
rs485ModeRS232(false);
14+
rs485FullDuplex(false);
15+
rs485YZTerm(false);
16+
rs485ABTerm(false);
17+
rs485Slew(false);
18+
}
19+
20+
void COMMClass::enableCAN() {
21+
can_disable = 0;
22+
}
23+
24+
void COMMClass::disableCAN() {
25+
can_disable = 1;
26+
}
27+
28+
void COMMClass::rs485Enable(bool enable) { digitalWrite(PinNameToIndex(PG_9), enable ? HIGH : LOW); }
29+
30+
void COMMClass::rs485ModeRS232(bool enable) { digitalWrite(PinNameToIndex(PA_10), enable ? LOW : HIGH); }
31+
32+
void COMMClass::rs485YZTerm(bool enable) { digitalWrite(PinNameToIndex(PI_15), enable ? HIGH : LOW); }
33+
34+
void COMMClass::rs485ABTerm(bool enable) { digitalWrite(PinNameToIndex(PI_14), enable ? HIGH : LOW); }
35+
36+
void COMMClass::rs485Slew(bool enable) { digitalWrite(PinNameToIndex(PG_14), enable ? LOW : HIGH); }
37+
38+
void COMMClass::rs485FullDuplex(bool enable) {
39+
digitalWrite(PinNameToIndex(PA_9), enable ? LOW : HIGH);
40+
if (enable) {
41+
// RS485 Full Duplex require YZ and AB 120 Ohm termination enabled
42+
rs485YZTerm(true);
43+
rs485ABTerm(true);
44+
}
45+
}
46+
47+
COMMClass comm_protocols;

src/COMMClass.h

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <ArduinoRS485.h>
2+
#include <Arduino.h>
3+
#include <pinDefinitions.h>
4+
#include <mbed.h>
5+
6+
/**
7+
* The COMMClass is used to initialize the CAN and RS485 LEDs and
8+
* establish the power mode of the CAN bus.
9+
*/
10+
class COMMClass {
11+
public:
12+
// to be tested: check if can be made a big pin initialization
13+
14+
/**
15+
* Shutdown RS485 and CAN LEDs
16+
*/
17+
void init();
18+
19+
/**
20+
* Set the CAN transceiver in Normal mode. In this mode, the transceiver
21+
* can transmit and receive data via the bus lines CANH and CANL.
22+
*/
23+
void enableCAN();
24+
25+
/**
26+
* Set the CAN transceiver in standby (low power) mode. In this mode the
27+
* transceiver will not be able to transmit or correctly receive data via the bus lines.
28+
* The wake-up filter on the output of the low-power receiver does not latch bus dominant states,
29+
* but ensures that only bus dominant and bus recessive states that persist longer than tfltr(wake)
30+
* bus are reflected on pin RXD.
31+
*/
32+
void disableCAN();
33+
34+
void rs485Enable(bool enable);
35+
void rs485ModeRS232(bool enable);
36+
void rs485YZTerm(bool enable);
37+
void rs485ABTerm(bool enable);
38+
void rs485Slew(bool enable);
39+
void rs485FullDuplex(bool enable);
40+
41+
arduino::UART _UART4_ {PA_0, PI_9, NC, NC};
42+
mbed::CAN can {PB_8, PH_13};
43+
RS485Class rs485 {_UART4_, PinNameToIndex(PA_0), PinNameToIndex(PI_13), PinNameToIndex(PI_10)};
44+
45+
private:
46+
mbed::DigitalOut can_disable = mbed::DigitalOut(PA_13, 0);
47+
};
48+
49+
extern COMMClass comm_protocols;

src/EncoderClass.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
/* Functions -----------------------------------------------------------------*/
1111
EncoderClass::EncoderClass(PinName enc0_A_pin, PinName enc0_B_pin, PinName enc0_I_pin,
1212
PinName enc1_A_pin, PinName enc1_B_pin, PinName enc1_I_pin)
13-
: enc_0(enc0_A_pin, enc0_B_pin, enc0_I_pin, 0),
14-
enc_1(enc1_A_pin, enc1_B_pin, enc1_I_pin, 0)
13+
: _enc0(enc0_A_pin, enc0_B_pin, enc0_I_pin, 0),
14+
_enc1(enc1_A_pin, enc1_B_pin, enc1_I_pin, 0)
1515
{ }
1616

1717
EncoderClass::~EncoderClass()
@@ -20,12 +20,12 @@ EncoderClass::~EncoderClass()
2020
QEI& EncoderClass::operator[](int index) {
2121
switch (index) {
2222
case 0:
23-
return enc_0;
23+
return _enc0;
2424
case 1:
25-
return enc_1;
25+
return _enc1;
2626
default:
2727
// Return encoder 0 by default if an invalid index is provided
28-
return enc_0;
28+
return _enc0;
2929
}
3030
}
3131

src/EncoderClass.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class EncoderClass {
5959
QEI& operator[](int index);
6060

6161
private:
62-
QEI enc_0; // QEI object for encoder 0
63-
QEI enc_1; // QEI object for encoder 1
62+
QEI _enc0; // QEI object for encoder 0
63+
QEI _enc1; // QEI object for encoder 1
6464
};
6565

6666
extern EncoderClass MachineControl_Encoders;

src/Objects.cpp

-6
This file was deleted.

0 commit comments

Comments
 (0)