Skip to content

Commit

Permalink
Fix some bugs in code thanks to warnings flag in compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
Tawank committed Feb 12, 2025
1 parent ccaa7d8 commit 4971929
Show file tree
Hide file tree
Showing 22 changed files with 69 additions and 69 deletions.
4 changes: 1 addition & 3 deletions boards/m5stack-cplus2/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ int getBattery() {
float mv = volt * 2;
percent = (mv - 3300) * 100 / (float)(4150 - 3350);

return (percent < 0) ? 0
: (percent >= 100) ? 100
: percent;
return (percent >= 100) ? 100 : percent;
}


Expand Down
2 changes: 1 addition & 1 deletion lib/TFT_eSPI_QRcode/src/qrencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ void addfmt(unsigned char masknum)
unsigned fmtbits;
unsigned char i, lvl = ECCLEVEL - 1;

fmtbits = pgm_read_word(&fmtword[masknum + (lvl << 3)]);
fmtbits = pgm_read_word_qr(&fmtword[masknum + (lvl << 3)]);
// low byte
for (i = 0; i < 8; i++, fmtbits >>= 1)
if (fmtbits & 1) {
Expand Down
2 changes: 1 addition & 1 deletion lib/TFT_eSPI_QRcode/src/qrencode.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define PROGMEM
#define memcpy_P memcpy
#define __LPM(x) *x
#define pgm_read_word(x) *x
#define pgm_read_word_qr(x) *x
#else
#include <avr/pgmspace.h>
#define USEPRECALC
Expand Down
4 changes: 2 additions & 2 deletions lib/utility/bq27220.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ bool BQ27220::unseal()
writeCtrlWord(BQ27220_UNSEAL_KEY2);
delayMicroseconds(5000);
status = OP_STATUS(readWord(BQ27220_CONTROL_CONTROL_STATUS));
if(status = OP_STATUS::UNSEALED)
if(status == OP_STATUS::UNSEALED)
{
return true;
}
Expand All @@ -25,7 +25,7 @@ bool BQ27220::seal()
writeCtrlWord(BQ27220_CONTROL_SEALED);
delayMicroseconds(5000);
status = OP_STATUS(readWord(BQ27220_CONTROL_CONTROL_STATUS));
if(status = OP_STATUS::SEALED)
if(status == OP_STATUS::SEALED)
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utility/bq27220.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ class BQ27220
uint16_t getId();

private:
TwoWire *wire;
uint8_t addr;
TwoWire *wire;
int scl;
int sda;
union battery_state bat_st;
Expand Down
30 changes: 15 additions & 15 deletions src/core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ JsonDocument BruceConfig::toJson() const {
setting["ledBright"] = ledBright;
setting["ledColor"] = String(ledColor, HEX);

JsonObject _webUI = setting.createNestedObject("webUI");
JsonObject _webUI = setting["webUI"].to<JsonObject>();
_webUI["user"] = webUI.user;
_webUI["pwd"] = webUI.pwd;

JsonObject _wifiAp = setting.createNestedObject("wifiAp");
JsonObject _wifiAp = setting["wifiAp"].to<JsonObject>();
_wifiAp["ssid"] = wifiAp.ssid;
_wifiAp["pwd"] = wifiAp.pwd;

setting["bleName"] = bleName;

JsonObject _wifi = setting.createNestedObject("wifi");
JsonObject _wifi = setting["wifi"].to<JsonObject>();
for (const auto& pair : wifi) {
_wifi[pair.first] = pair.second;
}
Expand All @@ -47,7 +47,7 @@ JsonDocument BruceConfig::toJson() const {

setting["rfidModule"] = rfidModule;

JsonArray _mifareKeys = setting.createNestedArray("mifareKeys");
JsonArray _mifareKeys = setting["mifareKeys"].to<JsonArray>();
for (auto key : mifareKeys) _mifareKeys.add(key);

setting["gpsBaudrate"] = gpsBaudrate;
Expand All @@ -56,14 +56,14 @@ JsonDocument BruceConfig::toJson() const {
setting["wigleBasicToken"] = wigleBasicToken;
setting["devMode"] = devMode;

JsonArray dm = setting.createNestedArray("disabledMenus");
JsonArray dm = setting["disabledMenus"].to<JsonArray>();
for(int i=0; i < disabledMenus.size(); i++){
dm.add(disabledMenus[i]);
}

JsonArray qrArray = setting.createNestedArray("qrCodes");
JsonArray qrArray = setting["qrCodes"].to<JsonArray>();
for (const auto& entry : qrCodes) {
JsonObject qrEntry = qrArray.createNestedObject();
JsonObject qrEntry = qrArray.add<JsonObject>();
qrEntry["menuName"] = entry.menuName;
qrEntry["content"] = entry.content;
}
Expand Down Expand Up @@ -205,7 +205,7 @@ void BruceConfig::saveFile() {


void BruceConfig::validateConfig() {
validateTheme();
// validateTheme();
validateRotationValue();
validateDimmerValue();
validateBrightValue();
Expand All @@ -227,16 +227,16 @@ void BruceConfig::setTheme(uint16_t primary, uint16_t secondary, uint16_t backgr
priColor = primary;
secColor = secondary == NULL ? primary - 0x2000 : secondary;
bgColor = background == NULL ? 0x0 : background;
validateTheme();
// validateTheme();
saveFile();
}


void BruceConfig::validateTheme() {
if (priColor < 0 || priColor > 0xFFFF) priColor = DEFAULT_PRICOLOR;
if (secColor < 0 || secColor > 0xFFFF) secColor = priColor - 0x2000;
if (bgColor < 0 || bgColor > 0xFFFF) bgColor = 0;
}
// uint16_t can't be lower than 0 or greater than 0xFFFF, thats its limit
// void BruceConfig::validateTheme() {
// if (priColor < 0 || priColor > 0xFFFF) priColor = DEFAULT_PRICOLOR;
// if (secColor < 0 || secColor > 0xFFFF) secColor = priColor - 0x2000;
// if (bgColor < 0 || bgColor > 0xFFFF) bgColor = 0;
// }


void BruceConfig::setRotation(int value) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class BruceConfig {

// Theme
void setTheme(uint16_t primary, uint16_t secondary = NULL, uint16_t background = NULL);
void validateTheme();
// void validateTheme();

// Settings
void setRotation(int value);
Expand Down
7 changes: 4 additions & 3 deletions src/core/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ void padprintln(const String &s, int16_t padx) {
}
}
void padprintln(const char str[], int16_t padx) {
if (str == "") {
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.println(str);
if (strcmp(str, "")) {
tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY());
tft.println(str);
return;
}

Expand Down Expand Up @@ -960,6 +960,7 @@ void *Gif::openFile(const char *fname, int32_t *pSize) {
*pSize = FSGifFile->size();
return (void *)FSGifFile;
}
return NULL;
}

void Gif::closeFile(void *pHandle) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/scrollableTextArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class ScrollableTextArea {
void show(bool force = false);

private:
String _title;
uint16_t _startLine;
bool _redraw;
String _title;
uint8_t _fontSize;
int16_t _startX, _startY;
int32_t _width, _height;
Expand Down
10 changes: 5 additions & 5 deletions src/modules/ir/custom_ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ struct IRCode {
filepath = String(code->filepath);
}

String name="";
String type="";
String protocol="";
String address="";
String command="";
uint16_t frequency=0;
String data="";
uint8_t bits=32;
String name="";
String type="";
uint16_t frequency=0;
//float duty_cycle;
String data="";
String filepath="";
};

Expand Down Expand Up @@ -404,7 +404,7 @@ void sendNECextCommand(String address, String command) {
irsend.begin();
displayTextLine("Sending..");

uint8_t first_zero_byte_pos = address.indexOf("00", 2);
int first_zero_byte_pos = address.indexOf("00", 2);
if(first_zero_byte_pos!=-1) address = address.substring(0, first_zero_byte_pos);
first_zero_byte_pos = command.indexOf("00", 2);
if(first_zero_byte_pos!=-1) command = command.substring(0, first_zero_byte_pos);
Expand Down
11 changes: 4 additions & 7 deletions src/modules/others/mic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

extern const unsigned char ImageData[768];

static SemaphoreHandle_t xSemaphore = NULL;
static SemaphoreHandle_t start_dis = NULL;
// static SemaphoreHandle_t xSemaphore = NULL;
// static SemaphoreHandle_t start_dis = NULL;

static uint16_t posData = 160;
static int8_t i2s_readraw_buff[2048];
static uint8_t fft_dis_buff[241][128] = {0};
// static int8_t i2s_readraw_buff[2048];
// static uint8_t fft_dis_buff[241][128] = {0};

static int8_t *_new_i2s_readraw_buff = nullptr;
static uint8_t **_new_fft_dis_buff = nullptr;
Expand Down Expand Up @@ -96,9 +96,6 @@ const unsigned char ImageData[768] = {
};

int rgb(unsigned char r, unsigned char g, unsigned char b) {
if (r < 0 || 255 < r || g < 0 || 255 < g || b < 0 || b > 255)
return -1;

int result;

//int red = r * 31 / 255;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/others/openhaystack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void set_payload_from_key(uint8_t *payload, uint8_t *public_key_decoded) {
payload[29] = public_key_decoded[0] >> 6;
}

void drawErrorMessage(esp_err_t status, char *text)
void drawErrorMessage(esp_err_t status, const char *text)
{
Serial.printf("%s: %s\n", text, esp_err_to_name(status));
tft.setCursor(0, 60);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/pwnagotchi/pwngrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef struct {
int uptime;
String version;
signed int rssi;
int last_ping;
unsigned long last_ping;
bool gone;
} pwngrid_peer;

Expand Down
8 changes: 5 additions & 3 deletions src/modules/pwnagotchi/spam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void loadFacesAndNames() {
look_for_file = true;
options.push_back({"SD Card", [&](){ fs=&SD; look_for_file = true; }});
}
if (checkLittleFsSizeNM) {
if (checkLittleFsSizeNM()) {
look_for_file = true;
options.push_back({"LittleFS faces", [&](){ fs=&LittleFS; look_for_file = true;}});
}
Expand Down Expand Up @@ -262,8 +262,10 @@ void loadFacesAndNames() {
names[i++]="System Breached oups";
names[i++]="Unauthorized Access";
names[i++]="Security Compromised.. reboot";
names[i++]="Warning...Bruce's here","Critical Error need reboot";
names[i++]="No more Battery","Never gonna give you up";
names[i++]="Warning...Bruce's here";
names[i++]="Critical Error need reboot";
names[i++]="No more Battery";
names[i++]="Never gonna give you up";
names[i++]="Never gonna let you down";
names[i++]="Never gonna run around";
names[i++]="and desert you";
Expand Down
11 changes: 6 additions & 5 deletions src/modules/rf/rf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ String rf_scan(float start_freq, float stop_freq, int max_loops)

float settingf1 = start_freq;
float settingf2 = stop_freq;
float freq;
long compare_freq;
float freq = 0;
long compare_freq = 0;
float mark_freq;
int rssi;
int mark_rssi=-100;
Expand Down Expand Up @@ -485,7 +485,7 @@ String hexStrToBinStr(const String& hexStr) {
char c = hexStr.charAt(i);

// Check if the character is a hexadecimal digit
if (c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f') {
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) {
hexByte += c;
if (hexByte.length() == 2) {
// Convert the hexadecimal pair to a decimal value
Expand Down Expand Up @@ -1630,8 +1630,9 @@ void rf_scan_copy() {
else options.push_back({ "Read RAW", [&]() { ReadRAW=true; } });
if(bruceConfig.devMode && !OnlyRAW) options.push_back({ "Only RAW", [&]() { ReadRAW=true; OnlyRAW=true; } });
else if(bruceConfig.devMode && OnlyRAW) options.push_back({ "RAW+Decode", [&]() { ReadRAW=true; OnlyRAW=false; } });
options.push_back({ "Close Menu", [&]() { option =-1; } });
options.push_back({ "Main Menu", [&]() { option =-2; } });

options.push_back({ "Close Menu", [&]() { option =-1; } });
options.push_back({ "Main Menu", [&]() { option =-2; } });


loopOptions(options);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/rfid/RFID2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ bool RFID2::read_data_blocks() {

bool RFID2::read_mifare_classic_data_blocks(byte piccType) {
byte no_of_sectors = 0;
bool sectorReadSuccess;
bool sectorReadSuccess = false;

switch (piccType) {
case MFRC522::PICC_TYPE_MIFARE_MINI:
Expand Down Expand Up @@ -432,7 +432,7 @@ bool RFID2::read_mifare_ultralight_data_blocks() {
byte cc;
String strPage = "";

for (byte page = 0; page < 256; page +=4) {
for (byte page = 0; page <= 252; page +=4) {
byteCount = sizeof(buffer);
status = mfrc522.MIFARE_Read(page, buffer, &byteCount);
if (status != MFRC522::STATUS_OK) {
Expand Down
3 changes: 3 additions & 0 deletions src/modules/rfid/chameleon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ void Chameleon::setMode(AppMode mode) {
case BATTERY_INFO_MODE:
case FACTORY_RESET_MODE:
break;
default:
padprintln("Mode not supported");
break;
}
delay(300);
}
Expand Down
3 changes: 3 additions & 0 deletions src/modules/rfid/pn532ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ void Pn532ble::setMode(AppMode mode)
case HF_14A_SCAN_MODE:
hf14aScan();
break;
case HF_14B_SCAN_MODE:
padprintln("Scan mode not supported");
break;
case HF_15_SCAN_MODE:
hf15Scan();
break;
Expand Down
15 changes: 5 additions & 10 deletions src/modules/rfid/rfid125.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,18 @@ bool RFID125::read_card_data() {
uint8_t checksum;
uint32_t tag_id;

if (!_stream)
return false;
if (!_stream) return false;

if (!_stream->available())
return false;
if (!_stream->available()) return false;

/* if a packet doesn't begin with the right byte, remove that byte */
if (_stream->peek() != RFID125_START_MARK && _stream->read())
return false;
if (_stream->peek() != RFID125_START_MARK && _stream->read()) return false;

/* if read a packet with the wrong size, drop it */
if (RFID125_PACKET_SIZE != _stream->readBytes(buff, RFID125_PACKET_SIZE))
return false;
if (RFID125_PACKET_SIZE != _stream->readBytes(buff, RFID125_PACKET_SIZE)) return false;

/* if a packet doesn't end with the right byte, drop it */
if (buff[13] != RFID125_END_MARK)
return false;
if (buff[13] != RFID125_END_MARK) return false;

for (int i=0; i<RFID125_PACKET_SIZE; i++) _tag_data[i] = buff[i];

Expand Down
2 changes: 1 addition & 1 deletion src/modules/wifi/ap_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ String getChannelWidth(wifi_second_chan_t secondChannel) {

void fillInfo(ScrollableTextArea& area){
wifi_ap_record_t ap_info;
err_t res;
esp_err_t res;
if( (res = esp_wifi_sta_get_ap_info(&ap_info)) != ESP_OK ){
String err;
switch (res) {
Expand Down
Loading

0 comments on commit 4971929

Please sign in to comment.