Skip to content

Commit 40e1f02

Browse files
committed
- Split most of the EspnowMeshBackend code into utility files and the new ConditionalPrinter, EspnowDatabase, EspnowConnectionManager, EspnowTransmitter and EspnowEncryptionBroker classes.
- Improve mutex handling. - Move verifyEncryptionRequestHmac function from JsonTranslator to EspnowEncryptionBroker. - Remove UtilityMethods.cpp.
1 parent 3f5495b commit 40e1f02

30 files changed

+3218
-2300
lines changed

libraries/ESP8266WiFiMesh/examples/HelloEspnow/HelloEspnow.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <ESP8266WiFi.h>
44
#include <EspnowMeshBackend.h>
5+
#include <TcpIpMeshBackend.h>
56
#include <TypeConversionFunctions.h>
67
#include <assert.h>
78

libraries/ESP8266WiFiMesh/examples/HelloTcpIp/HelloTcpIp.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <ESP8266WiFi.h>
44
#include <TcpIpMeshBackend.h>
5+
#include <EspnowMeshBackend.h>
56
#include <TypeConversionFunctions.h>
67
#include <assert.h>
78

libraries/ESP8266WiFiMesh/src/UtilityMethods.cpp renamed to libraries/ESP8266WiFiMesh/src/ConditionalPrinter.cpp

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
2-
* UtilityMethods
3-
* Copyright (C) 2018 Anders Löfgren
2+
* Copyright (C) 2020 Anders Löfgren
43
*
54
* License (MIT license):
65
*
@@ -27,24 +26,16 @@
2726
#include "MeshBackendBase.h"
2827
#include "EspnowMeshBackend.h"
2928

30-
void MeshBackendBase::setVerboseModeState(const bool enabled) {_verboseMode = enabled;}
31-
bool MeshBackendBase::verboseMode() const {return _verboseMode;}
32-
33-
void MeshBackendBase::verboseModePrint(const String &stringToPrint, const bool newline) const
29+
namespace
3430
{
35-
if(verboseMode())
36-
{
37-
if(newline)
38-
Serial.println(stringToPrint);
39-
else
40-
Serial.print(stringToPrint);
41-
}
31+
bool _staticVerboseMode = false;
32+
bool _printWarnings = true;
4233
}
4334

44-
void EspnowMeshBackend::setVerboseModeState(const bool enabled) {MeshBackendBase::setVerboseModeState(enabled); _staticVerboseMode = enabled;}
45-
bool EspnowMeshBackend::verboseMode() const {return staticVerboseMode();}
35+
void ConditionalPrinter::setVerboseModeState(const bool enabled) {_verboseMode = enabled;}
36+
bool ConditionalPrinter::verboseMode() const {return _verboseMode;}
4637

47-
void EspnowMeshBackend::verboseModePrint(const String &stringToPrint, const bool newline) const
38+
void ConditionalPrinter::verboseModePrint(const String &stringToPrint, const bool newline) const
4839
{
4940
if(verboseMode())
5041
{
@@ -55,9 +46,10 @@ void EspnowMeshBackend::verboseModePrint(const String &stringToPrint, const bool
5546
}
5647
}
5748

58-
bool EspnowMeshBackend::staticVerboseMode() {return _staticVerboseMode;}
49+
void ConditionalPrinter::setStaticVerboseModeState(const bool enabled) {_staticVerboseMode = enabled;};
50+
bool ConditionalPrinter::staticVerboseMode() {return _staticVerboseMode;}
5951

60-
void EspnowMeshBackend::staticVerboseModePrint(const String &stringToPrint, const bool newline)
52+
void ConditionalPrinter::staticVerboseModePrint(const String &stringToPrint, const bool newline)
6153
{
6254
if(staticVerboseMode())
6355
{
@@ -68,10 +60,10 @@ void EspnowMeshBackend::staticVerboseModePrint(const String &stringToPrint, cons
6860
}
6961
}
7062

71-
void MeshBackendBase::setPrintWarnings(const bool printEnabled) {_printWarnings = printEnabled;}
72-
bool MeshBackendBase::printWarnings() {return _printWarnings;}
63+
void ConditionalPrinter::setPrintWarnings(const bool printEnabled) {_printWarnings = printEnabled;}
64+
bool ConditionalPrinter::printWarnings() {return _printWarnings;}
7365

74-
void MeshBackendBase::warningPrint(const String &stringToPrint, const bool newline)
66+
void ConditionalPrinter::warningPrint(const String &stringToPrint, const bool newline)
7567
{
7668
if(printWarnings())
7769
{
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (C) 2020 Anders Löfgren
3+
*
4+
* License (MIT license):
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#ifndef __CONDITIONALPRINTER_H__
26+
#define __CONDITIONALPRINTER_H__
27+
28+
class ConditionalPrinter
29+
{
30+
31+
public:
32+
33+
/**
34+
* Set whether the normal events occurring in the library will be printed to Serial or not.
35+
*
36+
* @param enabled If true, library Serial prints are activated.
37+
*/
38+
void setVerboseModeState(const bool enabled);
39+
bool verboseMode() const;
40+
41+
/**
42+
* Only print stringToPrint if verboseMode() returns true.
43+
*
44+
* @param stringToPrint String to print.
45+
* @param newline If true, will end the print with a newline. True by default.
46+
*/
47+
void verboseModePrint(const String &stringToPrint, const bool newline = true) const;
48+
49+
/**
50+
* Same as verboseMode(), but used for printing from static functions.
51+
*
52+
* @param enabled If true, the normal events occurring in the library will be printed to Serial.
53+
*/
54+
static void setStaticVerboseModeState(const bool enabled);
55+
static bool staticVerboseMode();
56+
57+
/**
58+
* Only print stringToPrint if staticVerboseMode() returns true.
59+
*
60+
* @param stringToPrint String to print.
61+
* @param newline If true, will end the print with a newline. True by default.
62+
*/
63+
static void staticVerboseModePrint(const String &stringToPrint, const bool newline = true);
64+
65+
/**
66+
* Set whether the warnings occurring in the library will be printed to Serial or not. On by default.
67+
*
68+
* @param printEnabled If true, warning Serial prints from the library are activated.
69+
*/
70+
static void setPrintWarnings(const bool printEnabled);
71+
static bool printWarnings();
72+
73+
/**
74+
* Only print stringToPrint if printWarnings() returns true.
75+
*
76+
* @param stringToPrint String to print.
77+
* @param newline If true, will end the print with a newline. True by default.
78+
*/
79+
static void warningPrint(const String &stringToPrint, const bool newline = true);
80+
81+
private:
82+
83+
bool _verboseMode = false;
84+
85+
};
86+
87+
#endif

0 commit comments

Comments
 (0)