Skip to content

Commit 3047826

Browse files
committed
Fix About page blank #29
Continue code cleanup
1 parent 242fb53 commit 3047826

16 files changed

+186
-138
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Special thanks goes also to all authors of 3rd party libraries which are used in
6666
- [plerup / EspSoftwareSerial](https://github.com/plerup/espsoftwareserial),
6767
- [marian-craciunescu / ESP32Ping](https://github.com/marian-craciunescu/ESP32Ping),
6868
- [sstaub / Ticker](https://github.com/sstaub/Ticker),
69-
- [knolleary / PubSubClient](https://github.com/knolleary/pubsubclient);
69+
- [knolleary / PubSubClient](https://github.com/knolleary/pubsubclient),
7070
- [ESP Async WebServer](https://github.com/me-no-dev/ESPAsyncWebServer),
7171
- [Martin-Laclaustra / CronAlarms](https://github.com/Martin-Laclaustra/CronAlarms)
7272

bin/UZG-01.bin

1010 KB
Binary file not shown.

bin/UZG-01_v0.2.5.full.bin

1.05 MB
Binary file not shown.

lib/CCTools/library.properties

+2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ author=xyzroe
44
maintainer=xyzroe
55
sentence="Work with TI CC(2538/1352/2652) series chips: read, write, verify firmware, get chip ID, etc."
66
paragraph=
7+
category=Communication
8+
url="https://github.com/xyzroe/CCTools"
79
includes=CCTools.h
810
architectures=esp32

lib/CCTools/src/CCTools.cpp

+54-23
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
#include <Arduino.h>
22
#include "CCTools.h"
33

4-
CommandInterface::CommandInterface(Stream &serial) : _stream(serial) {}
4+
#ifndef DEBUG_PRINT
5+
#ifdef DEBUG
6+
#define DEBUG_PRINT(x) Serial.print(String(x))
7+
#define DEBUG_PRINTLN(x) Serial.println(String(x))
8+
#else
9+
#define DEBUG_PRINT(x)
10+
#define DEBUG_PRINTLN(x)
11+
#endif
12+
#endif
513

14+
CommandInterface::CommandInterface(Stream &serial) : _stream(serial) {}
615

716
bool CommandInterface::_sendSynch()
817
{
@@ -54,7 +63,7 @@ uint32_t CommandInterface::_cmdGetChipId()
5463
// Serial.println("size " + String(sizeof(version)));
5564
if (_checkLastCmd())
5665
{
57-
66+
5867
uint32_t value = 0;
5968
value |= uint32_t(version[3]) << 0; // Least significant byte
6069
value |= uint32_t(version[2]) << 8;
@@ -146,13 +155,15 @@ void CommandInterface::_sendNAck()
146155
_stream.write(cmd2);
147156
}
148157

149-
void CommandInterface::_eraseFlash() {
150-
const u_int32_t cmd1 = 0x2C;
158+
void CommandInterface::_eraseFlash()
159+
{
160+
const u_int32_t cmd1 = 0x2C;
151161
_stream.write(cmd1);
152162
}
153163

154-
bool CommandInterface::_ping() {
155-
const u_int32_t cmd1 = 0x20;
164+
bool CommandInterface::_ping()
165+
{
166+
const u_int32_t cmd1 = 0x20;
156167
_stream.write(cmd1);
157168
return _wait_for_ack(1);
158169
}
@@ -268,46 +279,67 @@ byte CommandInterface::_calcChecks(byte cmd, unsigned long addr, unsigned long s
268279
return (byte)(sum & 0xFF);
269280
}
270281

271-
CCTools_detect::CCTools_detect(Stream &serial) : CommandInterface(serial) {}
272-
273-
bool CCTools_detect::begin(int CC_RST_PIN, int CC_BSL_PIN, int BSL_MODE)
282+
CCTools::CCTools(Stream &serial, int CC_RST_PIN, int CC_BSL_PIN, int BSL_MODE)
283+
: CommandInterface(serial), _CC_RST_PIN(CC_RST_PIN), _CC_BSL_PIN(CC_BSL_PIN), _BSL_MODE(BSL_MODE)
274284
{
275-
_CC_RST_PIN = CC_RST_PIN;
276-
_CC_BSL_PIN = CC_BSL_PIN;
277-
_BSL_MODE = BSL_MODE;
285+
}
278286

287+
bool CCTools::begin()
288+
{
279289
pinMode(_CC_RST_PIN, OUTPUT);
290+
digitalWrite(_CC_RST_PIN, HIGH);
280291
pinMode(_CC_BSL_PIN, OUTPUT);
292+
digitalWrite(_CC_BSL_PIN, HIGH);
293+
294+
enterBSL();
281295

282-
_enterBSLMode();
283296
if (!_sendSynch())
284297
{
285-
// Serial.print("begin NOT ok");
286298
return false;
287299
}
288300

289-
290301
return true;
291302
}
292303

293-
void CCTools_detect::_enterBSLMode()
304+
void CCTools::enterBSL()
294305
{
295306
if (_BSL_MODE == 0)
296307
{
297308
digitalWrite(_CC_RST_PIN, LOW);
298309
digitalWrite(_CC_BSL_PIN, LOW);
310+
DEBUG_PRINTLN(F("Zigbee RST pin ON"));
311+
DEBUG_PRINTLN(F("Zigbee BSL pin ON"));
299312
delay(250);
300313
digitalWrite(_CC_RST_PIN, HIGH);
301-
delay(2000);
314+
DEBUG_PRINTLN(F("Zigbee RST pin OFF"));
315+
delay(1000);
302316
digitalWrite(_CC_BSL_PIN, HIGH);
317+
DEBUG_PRINTLN(F("Zigbee BSL pin OFF"));
303318
delay(1000);
304-
//Serial.println("enter bsl mode...");
305319
}
320+
// Other modes BSL_MODE can be added later
321+
}
306322

307-
// Другие режимы BSL_MODE могут быть добавлены здесь в будущем
323+
void CCTools::restart()
324+
{
325+
digitalWrite(_CC_RST_PIN, LOW);
326+
DEBUG_PRINTLN(F("Zigbee RST pin ON"));
327+
delay(250);
328+
digitalWrite(_CC_RST_PIN, HIGH);
329+
DEBUG_PRINTLN(F("Zigbee RST pin OFF"));
330+
delay(1000);
308331
}
309332

310-
String CCTools_detect::detectChipInfo()
333+
void CCTools::routerRejoin()
334+
{
335+
digitalWrite(_CC_BSL_PIN, LOW);
336+
DEBUG_PRINTLN(F("ZB BSL pin ON"));
337+
delay(250);
338+
digitalWrite(_CC_BSL_PIN, HIGH);
339+
DEBUG_PRINTLN(F("ZB BSL pin OFF"));
340+
delay(500);
341+
}
342+
String CCTools::detectChipInfo()
311343
{
312344
uint32_t chip_id = _cmdGetChipId();
313345

@@ -366,11 +398,10 @@ String CCTools_detect::detectChipInfo()
366398
return chip_str;
367399
}
368400

369-
370-
bool CCTools_detect::eraseFlash()
401+
bool CCTools::eraseFlash()
371402
{
372403
_ping();
373404
_eraseFlash();
374-
405+
375406
return true;
376407
}

lib/CCTools/src/CCTools.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,23 @@ class CommandInterface
102102
byte *_cmdMemRead(uint32_t address);
103103
};
104104

105-
class CCTools_detect : public CommandInterface
105+
class CCTools : public CommandInterface
106106
{
107107
private:
108108
int _CC_RST_PIN, _CC_BSL_PIN, _BSL_MODE;
109-
110-
void _enterBSLMode();
109+
111110

112111
public:
113-
CCTools_detect(Stream &serial);
114-
bool begin(int CC_RST_PIN, int CC_BSL_PIN, int BSL_MODE = 0);
112+
// Adjusted constructor declaration
113+
CCTools(Stream &serial, int CC_RST_PIN, int CC_BSL_PIN, int BSL_MODE = 0);
114+
115+
bool begin();
115116
bool eraseFlash();
116117
bool ping();
117118
String detectChipInfo();
119+
void enterBSL();
120+
void restart();
121+
void routerRejoin();
118122
};
119123

120124
#endif // CCTools_DETECT_H

lib/IntelHex/library.properties

+2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ author="OpenAI's ChatGPT with contributions from xyzroe"
44
maintainer=xyzroe
55
sentence="Read and parse Intel Hex format files from the LittleFS file system."
66
paragraph=
7+
category=Communication
8+
url="https://github.com/xyzroe/IntelHex"
79
includes=IntelHex.h
810
architectures=esp32

src/config.h

+3-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define ETH_MDIO_PIN_1 18
1717
// ESP32 PINS TO CONTROL CC2652P
1818
#define CC2652P_RST 16
19-
#define CC2652P_FLSH 32
19+
#define CC2652P_FLASH 32
2020
#define CC2652P_RXD 36
2121
#define CC2652P_TXD 4
2222
#define BTN 35
@@ -27,8 +27,8 @@
2727
#define FORMAT_LITTLEFS_IF_FAILED true
2828

2929
// CC2652 settings (FOR BSL VALIDATION!)
30-
#define BSL_PIN 15 // CC2652 pin number (FOR BSL VALIDATION!)
31-
#define BSL_LEVEL 0 // 0-LOW 1-HIGH
30+
#define NEED_BSL_PIN 15 // CC2652 pin number (FOR BSL VALIDATION!)
31+
#define NEED_BSL_LEVEL 0 // 0-LOW 1-HIGH
3232

3333
const int16_t overseerInterval = 5 * 1000; // check lan or wifi connection every 5sec
3434
const uint8_t overseerMaxRetry = 3; // 5x12 = 60sec delay for AP start
@@ -55,13 +55,6 @@ extern const char *configFileMqtt;
5555
extern const char *configFileWg;
5656
extern const char *deviceModel;
5757

58-
// struct JsonConsts_t{
59-
// char* str;
60-
// };
61-
// JsonConsts_t JsonConsts {
62-
// "sadasd"
63-
// };
64-
6558
struct ConfigSettingsStruct
6659
{
6760
char ssid[50];

src/etc.cpp

+31-49
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <FS.h>
55
#include <LittleFS.h>
66
#include <ETH.h>
7+
#include <CCTools.h>
78

89
#include "config.h"
910
#include "web.h"
@@ -13,6 +14,8 @@
1314

1415
extern struct ConfigSettingsStruct ConfigSettings;
1516

17+
extern CCTools CCTool;
18+
1619
const char *coordMode = "coordMode"; // coordMode node name
1720
const char *prevCoordMode = "prevCoordMode"; // prevCoordMode node name
1821
const char *configFileSystem = "/config/system.json";
@@ -96,57 +99,29 @@ float getCPUtemp(bool clear)
9699

97100
void zigbeeRouterRejoin()
98101
{
99-
printLogMsg("Zigbee RST pin ON");
100-
DEBUG_PRINTLN(F("Zigbee RST pin ON"));
101-
digitalWrite(CC2652P_FLSH, 0);
102-
delay(250);
103-
104-
printLogMsg("Zigbee RST pin OFF");
105-
DEBUG_PRINTLN(F("Zigbee RST pin OFF"));
106-
digitalWrite(CC2652P_FLSH, 1);
107-
delay(500);
108-
109-
printLogMsg("Router reconnect");
110-
DEBUG_PRINTLN(F("Router Reconnect"));
102+
printLogMsg("Router rejoin begin");
103+
DEBUG_PRINTLN(F("Router rejoin begin"));
104+
CCTool.routerRejoin();
105+
printLogMsg("Router in join mode!");
106+
DEBUG_PRINTLN(F("Router in join mode!"));
111107
}
112108

113109
void zigbeeEnableBSL()
114110
{
115-
printLogMsg("Zigbee BSL pin ON");
116-
DEBUG_PRINTLN(F("Zigbee BSL pin ON"));
117-
digitalWrite(CC2652P_FLSH, 0);
118-
delay(100);
119-
120-
printLogMsg("Zigbee RST pin ON");
121-
DEBUG_PRINTLN(F("Zigbee RST pin ON"));
122-
digitalWrite(CC2652P_RST, 0);
123-
delay(250);
124-
125-
printLogMsg("Zigbee RST pin OFF");
126-
DEBUG_PRINTLN(F("Zigbee RST pin OFF"));
127-
digitalWrite(CC2652P_RST, 1);
128-
delay(2000);
129-
130-
printLogMsg("Zigbee BSL pin OFF");
131-
DEBUG_PRINTLN(F("Zigbee BSL pin OFF"));
132-
digitalWrite(CC2652P_FLSH, 1);
133-
delay(4000);
111+
printLogMsg("ZB enable BSL");
112+
DEBUG_PRINTLN(F("ZB enable BSL"));
113+
CCTool.enterBSL();
134114
printLogMsg("Now you can flash CC2652!");
135115
DEBUG_PRINTLN(F("Now you can flash CC2652!"));
136116
}
137117

138118
void zigbeeRestart()
139119
{
140-
printLogMsg("Zigbee RST pin ON");
141-
DEBUG_PRINTLN(F("Zigbee RST pin ON"));
142-
digitalWrite(CC2652P_RST, 0);
143-
delay(250);
144-
printLogMsg("Zigbee RST pin OFF");
145-
DEBUG_PRINTLN(F("Zigbee RST pin OFF"));
146-
digitalWrite(CC2652P_RST, 1);
147-
delay(2000);
148-
printLogMsg("Zigbee restart was done");
149-
DEBUG_PRINTLN(F("Zigbee restart was done"));
120+
printLogMsg("ZB RST begin");
121+
DEBUG_PRINTLN(F("ZB RST begin"));
122+
CCTool.restart();
123+
printLogMsg("ZB restart was done");
124+
DEBUG_PRINTLN(F("ZB restart was done"));
150125
}
151126

152127
void adapterModeUSB()
@@ -319,9 +294,12 @@ void setClock()
319294
configTime(0, 0, "pool.ntp.org", "time.google.com");
320295

321296
DEBUG_PRINT(F("Waiting for NTP time sync: "));
322-
int startTryingTime = millis()/1000;
297+
int startTryingTime = millis();
298+
DEBUG_PRINTLN(startTryingTime);
299+
startTryingTime = startTryingTime / 1000;
323300
time_t nowSecs = time(nullptr);
324-
while ((nowSecs-startTryingTime) < 60)
301+
DEBUG_PRINTLN(nowSecs);
302+
while ((nowSecs - startTryingTime) < 60)
325303
{
326304
delay(500);
327305
DEBUG_PRINT(F("."));
@@ -346,18 +324,18 @@ void setClock()
346324

347325
if (gmtOffset != nullptr)
348326
{
349-
DEBUG_PRINT("GMT Offset for ");
327+
DEBUG_PRINT(F("GMT Offset for "));
350328
DEBUG_PRINT(zoneToFind);
351-
DEBUG_PRINT(" is ");
329+
DEBUG_PRINT(F(" is "));
352330
DEBUG_PRINTLN(gmtOffset);
353331
timezone = gmtOffset;
354332
setTimezone(timezone);
355333
}
356334
else
357335
{
358-
DEBUG_PRINT("GMT Offset for ");
336+
DEBUG_PRINT(F("GMT Offset for "));
359337
DEBUG_PRINT(zoneToFind);
360-
DEBUG_PRINTLN(" not found.");
338+
DEBUG_PRINTLN(F(" not found."));
361339
}
362340
}
363341

@@ -369,8 +347,12 @@ void setTimezone(String timezone)
369347
time_t nowSecs = time(nullptr);
370348
struct tm timeinfo;
371349
localtime_r(&nowSecs, &timeinfo);
350+
351+
String timeNow = asctime(&timeinfo);
352+
timeNow.remove(timeNow.length() - 1);
372353
DEBUG_PRINT(F("Local time: "));
373-
DEBUG_PRINTLN(asctime(&timeinfo));
354+
DEBUG_PRINTLN(timeNow);
355+
printLogMsg("Local time: " + timeNow);
374356
}
375357

376358
const char *getGmtOffsetForZone(const char *zone)
@@ -389,5 +371,5 @@ const char *getGmtOffsetForZone(const char *zone)
389371

390372
void ledsScheduler()
391373
{
392-
DEBUG_PRINTLN("LEDS Scheduler");
374+
DEBUG_PRINTLN(F("LEDS Scheduler"));
393375
}

0 commit comments

Comments
 (0)