Skip to content

Commit c89b277

Browse files
committed
static functions
1 parent ca7233c commit c89b277

File tree

6 files changed

+76
-70
lines changed

6 files changed

+76
-70
lines changed

mqtt_utils.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static PubSubClient xPsClient(xWifiClient);
2929
*/
3030
void vMqttLoop(void) {
3131
if (!xPsClient.connected()) {
32-
vServerConnect();
32+
_vServerConnect();
3333
xPostStateADCtimer.every(ADC_CHECK_PERIOD_MS, vPostADC, (void *)&xPsClient);
3434
xPostStateGPIOtimer.every(GPIO_CHECK_PERIOD_MS, vPostGPIO, (void *)&xPsClient);
3535
}
@@ -44,7 +44,7 @@ void vMqttLoop(void) {
4444
* Connect to MQTT broker
4545
*
4646
*/
47-
void vServerConnect(void) {
47+
static void _vServerConnect(void) {
4848
static VirtualDelay singleDelay;
4949
xPsClient.disconnect();
5050
xPsClient.setServer(xGlobalSettings.acMQTTserver, xGlobalSettings.uiMQTTport);

mqtt_utils.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010

1111

1212
void vMqttLoop(void);
13-
void vServerConnect(void);
13+
14+
static void _vServerConnect(void);

periphery.cpp

+34-34
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,16 @@ void vPostGPIO(void* vContext) {
9999
32 * bit5 + 64 * bit6 + 128 * bit7 + 256 * bit8;
100100
if (uiValue != uiOld) {
101101
uiOld = uiValue;
102-
vStateBit(bit0, "GPIO0", pxPsClient);
103-
vStateBit(bit1, "GPIO2", pxPsClient);
104-
vStateBit(bit2, "GPIO4", pxPsClient);
105-
vStateBit(bit3, "GPIO5", pxPsClient);
106-
vStateBit(bit4, "GPIO12", pxPsClient);
107-
vStateBit(bit5, "GPIO13", pxPsClient);
108-
vStateBit(bit6, "GPIO14", pxPsClient);
109-
vStateBit(bit7, "GPIO15", pxPsClient);
110-
vStateBit(bit8, "GPIO16", pxPsClient);
111-
vStateBit(uiValue, "GPIOALL", pxPsClient);
102+
_vStateBit(bit0, "GPIO0", pxPsClient);
103+
_vStateBit(bit1, "GPIO2", pxPsClient);
104+
_vStateBit(bit2, "GPIO4", pxPsClient);
105+
_vStateBit(bit3, "GPIO5", pxPsClient);
106+
_vStateBit(bit4, "GPIO12", pxPsClient);
107+
_vStateBit(bit5, "GPIO13", pxPsClient);
108+
_vStateBit(bit6, "GPIO14", pxPsClient);
109+
_vStateBit(bit7, "GPIO15", pxPsClient);
110+
_vStateBit(bit8, "GPIO16", pxPsClient);
111+
_vStateBit(uiValue, "GPIOALL", pxPsClient);
112112
}
113113
}
114114

@@ -123,36 +123,36 @@ void vPostGPIO(void* vContext) {
123123
*/
124124
void vRecieveCallback(char* acTopic, byte* abPayload, unsigned int uiLength) {
125125
char acToken[20];
126-
strcpy(acToken, acGetToken(acTopic, 2));
127-
char * acMessage = acPayload2string(abPayload, uiLength);
126+
strcpy(acToken, _acGetToken(acTopic, 2));
127+
char * acMessage = _acPayload2string(abPayload, uiLength);
128128
if (strcmp(acToken, "GPIO0") == 0) {
129-
vSetOut(acMessage, 0);
129+
_vSetOut(acMessage, 0);
130130
} else if (strcmp(acToken, "GPIO2") == 0) {
131-
vSetOut(acMessage, 2); // BUILTIN_LED for WEMOS D1 mini
131+
_vSetOut(acMessage, 2); // BUILTIN_LED for WEMOS D1 mini
132132
} else if (strcmp(acToken, "GPIO4") == 0) {
133-
vSetOut(acMessage, 4);
133+
_vSetOut(acMessage, 4);
134134
} else if (strcmp(acToken, "GPIO5") == 0) {
135-
vSetOut(acMessage, 5);
135+
_vSetOut(acMessage, 5);
136136
} else if (strcmp(acToken, "GPIO12") == 0) {
137-
vSetOut(acMessage, 12);
137+
_vSetOut(acMessage, 12);
138138
} else if (strcmp(acToken, "GPIO13") == 0) {
139-
vSetOut(acMessage, 13);
139+
_vSetOut(acMessage, 13);
140140
} else if (strcmp(acToken, "GPIO14") == 0) {
141-
vSetOut(acMessage, 14);
141+
_vSetOut(acMessage, 14);
142142
} else if (strcmp(acToken, "GPIO15") == 0) {
143-
vSetOut(acMessage, 15);
143+
_vSetOut(acMessage, 15);
144144
} else if (strcmp(acToken, "GPIO16") == 0) {
145-
vSetOut(acMessage, 16);
145+
_vSetOut(acMessage, 16);
146146
} else if (strcmp(acToken, "GPIOALL") == 0) {
147-
vSetOut(acMessage, 0);
148-
vSetOut(acMessage, 2); // BUILTIN_LED for WEMOS D1 mini
149-
vSetOut(acMessage, 4);
150-
vSetOut(acMessage, 5);
151-
vSetOut(acMessage, 12);
152-
vSetOut(acMessage, 13);
153-
vSetOut(acMessage, 14);
154-
vSetOut(acMessage, 15);
155-
vSetOut(acMessage, 16);
147+
_vSetOut(acMessage, 0);
148+
_vSetOut(acMessage, 2); // BUILTIN_LED for WEMOS D1 mini
149+
_vSetOut(acMessage, 4);
150+
_vSetOut(acMessage, 5);
151+
_vSetOut(acMessage, 12);
152+
_vSetOut(acMessage, 13);
153+
_vSetOut(acMessage, 14);
154+
_vSetOut(acMessage, 15);
155+
_vSetOut(acMessage, 16);
156156
}
157157
}
158158

@@ -165,7 +165,7 @@ void vRecieveCallback(char* acTopic, byte* abPayload, unsigned int uiLength) {
165165
* @param uiNumber - number of returned member
166166
* @return - selected member of topic message
167167
*/
168-
char* acGetToken(char* acTopicStr, unsigned int uiNumber) {
168+
static char* _acGetToken(char* acTopicStr, unsigned int uiNumber) {
169169
char acTopic[80];
170170
strcpy(acTopic, acTopicStr);
171171
char* aacTokens[20];
@@ -185,7 +185,7 @@ char* acGetToken(char* acTopicStr, unsigned int uiNumber) {
185185
* @param cMessage - message ("0" of "1")
186186
* @param bOutNumber - GPIO number
187187
*/
188-
void vSetOut(char * cMessage, byte bOutNumber) {
188+
static void _vSetOut(char * cMessage, byte bOutNumber) {
189189
if (strcmp(cMessage, "1") == 0) {
190190
digitalWrite(bOutNumber, HIGH);
191191
}
@@ -203,7 +203,7 @@ void vSetOut(char * cMessage, byte bOutNumber) {
203203
* @param acId - name of parameter (e.g. "ADC" or "GPIO1")
204204
* @param pxPsClient - PubSubClient object
205205
*/
206-
void vStateBit(unsigned int uiValue, char* acId, PubSubClient *pxPsClient) {
206+
static void _vStateBit(unsigned int uiValue, char* acId, PubSubClient *pxPsClient) {
207207
char acMessage[33];
208208
char acTopic[80];
209209
sprintf(acMessage, "%d", uiValue);
@@ -221,7 +221,7 @@ void vStateBit(unsigned int uiValue, char* acId, PubSubClient *pxPsClient) {
221221
* @param uiLength - length of byte array
222222
* @return - converted string
223223
*/
224-
char * acPayload2string(byte* abPayload, unsigned int uiLength) {
224+
static char* _acPayload2string(byte* abPayload, unsigned int uiLength) {
225225

226226
char* acMessageBuffer = new char[uiLength+1];
227227

periphery.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ void initPeripheral(void);
1111
void vPostADC(void* context);
1212
void vPostGPIO(void* vContext);
1313
void vRecieveCallback(char* acTopic, byte* abPayload, unsigned int uiLength);
14-
char* acGetToken(char* acTopicStr, unsigned int uiNumber);
15-
void vSetOut(char * cMessage, byte bNumber);
16-
void vStateBit(unsigned int uiValue, char* acId, PubSubClient *pxPsClient);
17-
char * acPayload2string(byte* abPayload, unsigned int uiLength);
14+
15+
static char* _acGetToken(char* acTopicStr, unsigned int uiNumber);
16+
static void _vSetOut(char * cMessage, byte bNumber);
17+
static void _vStateBit(unsigned int uiValue, char* acId, PubSubClient *pxPsClient);
18+
static char* _acPayload2string(byte* abPayload, unsigned int uiLength);

serial_utils.cpp

+32-28
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,40 @@ Vladimir Kirievskiy (C) 2019
2020
Timer xRecieveStringTimer;
2121

2222

23+
24+
25+
26+
/*
27+
* @brief
28+
* Serial port initialization routine
29+
*
30+
*/
31+
void vInitSerial(void) {
32+
Serial.begin(SERIAL_PORT_SPEED);
33+
delay(1000);
34+
xRecieveStringTimer.every(SERIAL_PORT_CHECKING_PERIOD_MS, _vGetMessage, (void*)0);
35+
}
36+
37+
38+
/*
39+
* @brief
40+
* Serial scan procedure for placement in the main loop
41+
*
42+
*/
43+
void vSerialLoop(void) {
44+
xRecieveStringTimer.update();
45+
}
46+
47+
2348
/*
2449
* @brief
2550
* Get JSON string from serial port, parse it and save it to xGlobalSettings and EEPROM.
2651
* See /doc/settings_example.txt
2752
* If word "reset" comes then set xGlobalSettings to defaults (see settings.h)
2853
*
29-
* @param context - dummy variable need for compatibility with Timer v2.1 only
54+
* @param context - dummy variable need for compatibility with Timer v2.1 only
3055
*/
31-
void vGetMessage(void* context) {
56+
static void _vGetMessage(void* context) {
3257
String input = "";
3358
while (Serial.available()) {
3459
input = Serial.readString();
@@ -38,7 +63,8 @@ void vGetMessage(void* context) {
3863
vRestoreDefaultSettings();
3964
vSaveCurrentSettingsToEEPROM();
4065
Serial.println("Return to default setting. REBOOT THE DEVICE!");
41-
} else { //json comes
66+
}
67+
else { //json comes
4268
char* acInput = new char[input.length() + 1];
4369
input.toCharArray(acInput, input.length() + 1);
4470
Serial.println("New settings:");
@@ -48,32 +74,10 @@ void vGetMessage(void* context) {
4874
xGlobalSettings.ulCheckSum = DEFAULT_CRC;
4975
vSaveCurrentSettingsToEEPROM();
5076
Serial.println("Success load new settings. REBOOT THE DEVICE!");
51-
} else { // -1
77+
}
78+
else { // -1
5279
Serial.println("Incorrect setting string!");
53-
5480
}
5581
}
5682
}
57-
}
58-
59-
60-
/*
61-
* @brief
62-
* Serial port initialization routine
63-
*
64-
*/
65-
void vInitSerial(void) {
66-
Serial.begin(SERIAL_PORT_SPEED);
67-
delay(1000);
68-
xRecieveStringTimer.every(SERIAL_PORT_CHECKING_PERIOD_MS, vGetMessage, (void*)0);
69-
}
70-
71-
72-
/*
73-
* @brief
74-
* Serial scan procedure for placement in the main loop
75-
*
76-
*/
77-
void vSerialLoop(void) {
78-
xRecieveStringTimer.update();
79-
}
83+
}

serial_utils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88

99
void vInitSerial(void);
10-
void vGetMessage(void* context);
1110
void vSerialLoop(void);
1211

12+
static void _vGetMessage(void* context);

0 commit comments

Comments
 (0)