Skip to content
This repository was archived by the owner on Dec 14, 2025. It is now read-only.

Commit 4705e41

Browse files
committed
Initial changes, cleanup and improvements
1 parent d3c4025 commit 4705e41

11 files changed

Lines changed: 218 additions & 254 deletions

File tree

Lines changed: 78 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,93 @@
11
#include "helpers.hpp"
22

3-
char *Helpers::itoa(int value, char *result, int base)
4-
{
5-
// check that the base if valid
6-
if (base < 2 || base > 36)
7-
{
8-
*result = '\0';
9-
return result;
10-
}
3+
char* Helpers::itoa(int value, char* result, int base) {
4+
// check that the base if valid
5+
if (base < 2 || base > 36) {
6+
*result = '\0';
7+
return result;
8+
}
119

12-
char *ptr = result, *ptr1 = result, tmp_char;
13-
int tmp_value;
10+
char *ptr = result, *ptr1 = result, tmp_char;
11+
int tmp_value;
1412

15-
do
16-
{
17-
tmp_value = value;
18-
value /= base;
19-
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - value * base)];
20-
} while (value);
13+
do {
14+
tmp_value = value;
15+
value /= base;
16+
*ptr++ =
17+
"zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxy"
18+
"z"[35 + (tmp_value - value * base)];
19+
} while (value);
2120

22-
// Apply negative sign
23-
if (tmp_value < 0)
24-
*ptr++ = '-';
25-
*ptr-- = '\0';
26-
while (ptr1 < ptr)
27-
{
28-
tmp_char = *ptr;
29-
*ptr-- = *ptr1;
30-
*ptr1++ = tmp_char;
31-
}
32-
return result;
21+
// Apply negative sign
22+
if (tmp_value < 0)
23+
*ptr++ = '-';
24+
*ptr-- = '\0';
25+
while (ptr1 < ptr) {
26+
tmp_char = *ptr;
27+
*ptr-- = *ptr1;
28+
*ptr1++ = tmp_char;
29+
}
30+
return result;
3331
}
3432

35-
void split(const std::string &str, const std::string &splitBy, std::vector<std::string> &tokens)
36-
{
37-
/* Store the original string in the array, so we can loop the rest
38-
* of the algorithm. */
39-
tokens.emplace_back(str);
33+
void split(const std::string& str,
34+
const std::string& splitBy,
35+
std::vector<std::string>& tokens) {
36+
/* Store the original string in the array, so we can loop the rest
37+
* of the algorithm. */
38+
tokens.emplace_back(str);
4039

41-
// Store the split index in a 'size_t' (unsigned integer) type.
42-
size_t splitAt;
43-
// Store the size of what we're splicing out.
44-
size_t splitLen = splitBy.size();
45-
// Create a string for temporarily storing the fragment we're processing.
46-
std::string frag;
47-
// Loop infinitely - break is internal.
48-
while (true)
49-
{
50-
/* Store the last string in the vector, which is the only logical
51-
* candidate for processing. */
52-
frag = tokens.back();
53-
/* The index where the split is. */
54-
splitAt = frag.find(splitBy);
55-
// If we didn't find a new split point...
56-
if (splitAt == std::string::npos)
57-
{
58-
// Break the loop and (implicitly) return.
59-
break;
60-
}
61-
/* Put everything from the left side of the split where the string
62-
* being processed used to be. */
63-
tokens.back() = frag.substr(0, splitAt);
64-
/* Push everything from the right side of the split to the next empty
65-
* index in the vector. */
66-
tokens.emplace_back(frag.substr(splitAt + splitLen, frag.size() - (splitAt + splitLen)));
40+
// Store the split index in a 'size_t' (unsigned integer) type.
41+
size_t splitAt;
42+
// Store the size of what we're splicing out.
43+
size_t splitLen = splitBy.size();
44+
// Create a string for temporarily storing the fragment we're processing.
45+
std::string frag;
46+
// Loop infinitely - break is internal.
47+
while (true) {
48+
/* Store the last string in the vector, which is the only logical
49+
* candidate for processing. */
50+
frag = tokens.back();
51+
/* The index where the split is. */
52+
splitAt = frag.find(splitBy);
53+
// If we didn't find a new split point...
54+
if (splitAt == std::string::npos) {
55+
// Break the loop and (implicitly) return.
56+
break;
6757
}
58+
/* Put everything from the left side of the split where the string
59+
* being processed used to be. */
60+
tokens.back() = frag.substr(0, splitAt);
61+
/* Push everything from the right side of the split to the next empty
62+
* index in the vector. */
63+
tokens.emplace_back(
64+
frag.substr(splitAt + splitLen, frag.size() - (splitAt + splitLen)));
65+
}
6866
}
6967

70-
std::vector<std::string> Helpers::split(const std::string &s, char delimiter)
71-
{
72-
std::vector<std::string> parts;
73-
std::string part;
74-
std::istringstream tokenStream(s);
75-
while (std::getline(tokenStream, part, delimiter))
76-
{
77-
parts.push_back(part);
78-
}
79-
return parts;
68+
std::vector<std::string> Helpers::split(const std::string& s, char delimiter) {
69+
std::vector<std::string> parts;
70+
std::string part;
71+
std::istringstream tokenStream(s);
72+
while (std::getline(tokenStream, part, delimiter)) {
73+
parts.push_back(part);
74+
}
75+
return parts;
8076
}
8177

82-
void Helpers::update_progress_bar(int progress, int total)
83-
{
84-
int barWidth = 70;
78+
void Helpers::update_progress_bar(int progress, int total) {
79+
int barWidth = 70;
8580

86-
std::cout << "\r[";
87-
int pos = barWidth * progress / total;
88-
for (int i = 0; i < barWidth; ++i)
89-
{
90-
if (i < pos)
91-
std::cout << "=";
92-
else if (i == pos)
93-
std::cout << ">";
94-
else
95-
std::cout << " ";
96-
}
97-
std::cout << "] " << int(progress * 100.0 / total) << " %\r";
98-
std::cout.flush();
81+
std::cout << "\r[";
82+
int pos = barWidth * progress / total;
83+
for (int i = 0; i < barWidth; ++i) {
84+
if (i < pos)
85+
std::cout << "=";
86+
else if (i == pos)
87+
std::cout << ">";
88+
else
89+
std::cout << " ";
90+
}
91+
std::cout << "] " << int(progress * 100.0 / total) << " %\r";
92+
std::cout.flush();
9993
}
Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
#ifndef HELPERS_HPP
22
#define HELPERS_HPP
3-
#include <string>
4-
#include <sstream>
5-
#include <vector>
63
#include <iostream>
74
#include <memory>
5+
#include <sstream>
6+
#include <string>
7+
#include <vector>
8+
9+
const unsigned char ETVR_HEADER[] = {0xFF, 0xA0, 0xFF, 0xA1, 0x01};
10+
const char* const ETVR_HEADER_BYTES = "\xff\xa0\xff\xa1";
811

9-
namespace Helpers
10-
{
11-
char *itoa(int value, char *result, int base);
12-
void split(std::string str, std::string splitBy, std::vector<std::string> &tokens);
13-
std::vector<std::string> split(const std::string &s, char delimiter);
14-
void update_progress_bar(int progress, int total);
12+
namespace Helpers {
13+
char* itoa(int value, char* result, int base);
14+
void split(std::string str,
15+
std::string splitBy,
16+
std::vector<std::string>& tokens);
17+
std::vector<std::string> split(const std::string& s, char delimiter);
18+
void update_progress_bar(int progress, int total);
1519

16-
/// @brief
17-
/// @tparam ...Args
18-
/// @param format
19-
/// @param ...args
20-
/// @return
21-
template <typename... Args>
22-
std::string format_string(const std::string &format, Args... args)
23-
{
24-
int size_s = std::snprintf(nullptr, 0, format.c_str(), args...) + 1; // Extra space for '\0'
25-
if (size_s <= 0)
26-
{
27-
std::cout << "Error during formatting.";
28-
return "";
29-
}
30-
auto size = static_cast<size_t>(size_s);
31-
std::unique_ptr<char[]> buf(new char[size]);
32-
std::snprintf(buf.get(), size, format.c_str(), args...);
33-
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
20+
/// @brief
21+
/// @tparam ...Args
22+
/// @param format
23+
/// @param ...args
24+
/// @return
25+
template <typename... Args>
26+
std::string format_string(const std::string& format, Args... args) {
27+
int size_s = std::snprintf(nullptr, 0, format.c_str(), args...) +
28+
1; // Extra space for '\0'
29+
if (size_s <= 0) {
30+
std::cout << "Error during formatting.";
31+
return "";
3432
}
35-
}
33+
auto size = static_cast<size_t>(size_s);
34+
std::unique_ptr<char[]> buf(new char[size]);
35+
std::snprintf(buf.get(), size, format.c_str(), args...);
36+
return std::string(buf.get(),
37+
buf.get() + size - 1); // We don't want the '\0' inside
38+
}
39+
} // namespace Helpers
3640

37-
#endif // HELPERS_HPP
41+
#endif // HELPERS_HPP

ESP/lib/src/io/LEDManager/LEDManager.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*between blinks.
1010
*/
1111

12+
// TODO rethink this
1213
LEDManager::ledStateMap_t LEDManager::ledStateMap = {
1314
{LEDStates_e::_LedStateNone, {{0, 500}}},
1415
{LEDStates_e::_Improv_Error,
@@ -58,15 +59,20 @@ LEDManager::~LEDManager() {}
5859

5960
void LEDManager::begin() {
6061
pinMode(_ledPin, OUTPUT);
61-
// the defualt state is _LedStateNone so we're fine
62+
// the default state is _LedStateNone so we're fine
6263
this->currentState = ledStateManager.getCurrentState();
6364
this->currentPatternIndex = 0;
6465
BlinkPatterns_t pattern =
6566
this->ledStateMap[this->currentState][this->currentPatternIndex];
6667
this->toggleLED(pattern.state);
6768
this->nextStateChangeMillis = pattern.delayTime;
6869

69-
log_d("begin %d", this->currentPatternIndex);
70+
log_d("Led manager began with: %d", this->currentPatternIndex);
71+
72+
#ifdef CONFIG_CAMERA_MODULE_SWROOM_BABBLE_S3
73+
log_d("Setting up LED for the Babble board");
74+
this->setupBabbeLed();
75+
#endif
7076
}
7177

7278
/**
@@ -120,6 +126,19 @@ void LEDManager::handleLED() {
120126
log_d("updated stage %d", this->currentPatternIndex);
121127
}
122128

129+
#ifdef CONFIG_CAMERA_MODULE_SWROOM_BABBLE_S3
130+
void LEDManager::setupBabbeLed() {
131+
// Set IR emitter strength to 100%.
132+
const int ledPin = 1; // Replace this with a command endpoint eventually.
133+
const int freq = 5000;
134+
const int ledChannel = 0;
135+
const int resolution = 8;
136+
const int dutyCycle = 255;
137+
ledcSetup(ledChannel, freq, resolution);
138+
ledcAttachPin(ledPin, ledChannel);
139+
ledcWrite(ledChannel, dutyCycle);
140+
}
141+
#endif
123142
/**
124143
* @brief Turn the LED on or off
125144
*
Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
#ifndef LEDMANAGER_HPP
22
#define LEDMANAGER_HPP
3-
#include <vector>
43
#include <Arduino.h>
54
#include <data/StateManager/StateManager.hpp>
65
#include <unordered_map>
6+
#include <vector>
77

8-
class LEDManager
9-
{
10-
public:
11-
LEDManager(byte pin);
12-
virtual ~LEDManager();
8+
class LEDManager {
9+
public:
10+
LEDManager(byte pin);
11+
virtual ~LEDManager();
1312

14-
void begin();
15-
void handleLED();
16-
void toggleLED(bool state) const;
13+
void begin();
14+
void handleLED();
15+
void toggleLED(bool state) const;
16+
#ifdef CONFIG_CAMERA_MODULE_SWROOM_BABBLE_S3
17+
void setupBabbeLed();
18+
#endif
1719

18-
private:
19-
byte _ledPin;
20-
unsigned long nextStateChangeMillis = 0;
21-
bool _ledState;
20+
private:
21+
byte _ledPin;
22+
unsigned long nextStateChangeMillis = 0;
23+
bool _ledState;
2224

23-
struct BlinkPatterns_t
24-
{
25-
int state;
26-
int delayTime;
27-
};
25+
struct BlinkPatterns_t {
26+
int state;
27+
int delayTime;
28+
};
2829

29-
typedef std::unordered_map<LEDStates_e, std::vector<BlinkPatterns_t>> ledStateMap_t;
30-
static ledStateMap_t ledStateMap;
31-
static std::vector<LEDStates_e> keepAliveStates;
32-
LEDStates_e currentState;
33-
unsigned int currentPatternIndex = 0;
30+
typedef std::unordered_map<LEDStates_e, std::vector<BlinkPatterns_t>>
31+
ledStateMap_t;
32+
static ledStateMap_t ledStateMap;
33+
static std::vector<LEDStates_e> keepAliveStates;
34+
LEDStates_e currentState;
35+
unsigned int currentPatternIndex = 0;
3436
};
3537

36-
#endif // LEDMANAGER_HPP
38+
#endif // LEDMANAGER_HPP

ESP/lib/src/network/api/baseAPI/Hash.h

Lines changed: 0 additions & 17 deletions
This file was deleted.

ESP/lib/src/network/api/baseAPI/baseAPI.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,6 @@ void BaseAPI::setWiFi(AsyncWebServerRequest* request) {
102102
projectConfig.setWifiConfig(networkName, ssid, password, channel, power,
103103
adhoc, true);
104104

105-
/* if (WiFiStateManager->getCurrentState() ==
106-
WiFiState_e::WiFiState_ADHOC)
107-
{
108-
projectConfig.setAPWifiConfig(ssid, password, &channel, adhoc,
109-
true);
110-
}
111-
else
112-
{
113-
114-
} */
115-
116105
request->send(200, MIMETYPE_JSON,
117106
"{\"msg\":\"Done. Wifi Creds have been set.\"}");
118107
break;

0 commit comments

Comments
 (0)