Skip to content

Commit

Permalink
various fixes after adding -Wall and -Wextra flags
Browse files Browse the repository at this point in the history
  • Loading branch information
PBrunot committed Nov 15, 2023
1 parent 8924abc commit 37fdfcc
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 32 deletions.
2 changes: 1 addition & 1 deletion include/card.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace card
}
inline void print(uint64_t uid)
{
Serial.printf("%08lx%08lx",
Serial.printf("%08x%08x",
static_cast<uint32_t>((uid >> 32) & 0xFFFFFFFF),
static_cast<uint32_t>(uid & 0xFFFFFFFF));
}
Expand Down
6 changes: 3 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ lib_deps =
Wire
adafruit/Adafruit NeoPixel@^1.11.0
build_unflags = -std=gnu++11
build_flags = -std=gnu++17 -D PINS_ESP32S3
build_flags = -std=gnu++17 -D PINS_ESP32S3 -Wall -Wextra
check_tool = clangtidy
check_flags =
clangtidy: --checks=-*,cert-*,clang-analyzer-*,llvm-* --fix
Expand All @@ -49,7 +49,7 @@ lib_deps =
Wire
adafruit/Adafruit NeoPixel@^1.11.0
build_unflags = -std=gnu++11
build_flags = -std=gnu++17 -D PINS_ESP32
build_flags = -std=gnu++17 -D PINS_ESP32 -Wall -Wextra
check_tool = clangtidy
check_flags =
clangtidy: --checks=-*,cert-*,clang-analyzer-*,llvm-* --fix
Expand All @@ -73,7 +73,7 @@ lib_deps =
terrorsl/sMQTTBroker
adafruit/Adafruit NeoPixel@^1.11.0
build_unflags = -std=gnu++11
build_flags = -std=gnu++17 -D WOKWI_SIMULATION
build_flags = -std=gnu++17 -D WOKWI_SIMULATION -Wall -Wextra
check_tool = clangtidy
check_flags =
clangtidy: --checks=-*,cert-*,clang-analyzer-*,llvm-* --fix
9 changes: 4 additions & 5 deletions src/BoardLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ void BoardLogic::refreshFromServer()
if (result->is_valid)
{
if (conf::debug::ENABLE_LOGS)
Serial.printf("The configured machine ID %d is valid, maintenance=%d, allowed=%d\r\n",
secrets::machine::machine_id, result->needs_maintenance, result->allowed);
Serial.printf("The configured machine ID %u is valid, maintenance=%d, allowed=%d\r\n",
secrets::machine::machine_id.id, result->needs_maintenance, result->allowed);

Board::machine.maintenanceNeeded = result->needs_maintenance;
Board::machine.allowed = result->allowed;
}
else
{
Serial.printf("The configured machine ID %d is unknown to the server\r\n",
secrets::machine::machine_id);
Serial.printf("The configured machine ID %u is unknown to the server\r\n",
secrets::machine::machine_id.id);
}
}
}
Expand Down Expand Up @@ -159,7 +159,6 @@ bool BoardLogic::longTap(std::string_view short_prompt) const

const BoardInfo bi = {Board::server.isOnline(), Board::machine.getPowerState(), Board::machine.isShutdownImminent()};

bool user_bailed_out = false;
for (auto step = 0; step < STEPS_COUNT; step++)
{
std::stringstream ss;
Expand Down
7 changes: 2 additions & 5 deletions src/FabServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool FabServer::publish(String topic, String payload)
{
if (payload.length() > FabServer::MAX_MQTT_LENGTH)
{
Serial.printf("MQTT Client: Message is too long: %s\r\n", payload);
Serial.printf("MQTT Client: Message is too long: %s\r\n", payload.c_str());
return false;
}

Expand All @@ -66,7 +66,7 @@ bool FabServer::publish(const Query &query)

if (payload.length() > FabServer::MAX_MQTT_LENGTH)
{
Serial.printf("MQTT Client: Message is too long: %s\r\n", payload);
Serial.printf("MQTT Client: Message is too long: %s\r\n", payload.c_str());
return false;
}

Expand Down Expand Up @@ -173,9 +173,6 @@ bool FabServer::connectWiFi() noexcept
/// @return true if both operations succeeded
bool FabServer::connect()
{
constexpr uint8_t NB_TRIES = 3;
constexpr uint16_t DELAY_MS = 1000;

// Check server
if (this->connectWiFi())
{
Expand Down
4 changes: 2 additions & 2 deletions src/LCDWrapper.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool LCDWrapper<_COLS, _ROWS>::begin()

if (conf::debug::ENABLE_LOGS)
{
constexpr auto MAX_LEN = 80;
constexpr auto MAX_LEN = 100;
char buffer[MAX_LEN] = {0};
if (sprintf(buffer, "Configured LCD %d x %d (d4=%d, d5=%d, d6=%d, d7=%d, en=%d, rs=%d), backlight=%d", _COLS, _ROWS,
this->config.d0_pin, this->config.d1_pin, this->config.d2_pin, this->config.d3_pin,
Expand All @@ -57,7 +57,7 @@ std::string LCDWrapper<_COLS, _ROWS>::convertSecondsToHHMMSS(duration<uint16_t>
//! since something something does not support to_string we have to resort to ye olde cstring stuff
char buffer[9] = {0};

snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d",
snprintf(buffer, sizeof(buffer), "%02lu:%02lu:%02lu",
duration.count() / 3600UL,
(duration.count() % 3600UL) / 60UL,
duration.count() % 60UL);
Expand Down
4 changes: 2 additions & 2 deletions src/MQTTtypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace ServerMQTT
response->user_level = static_cast<FabUser::UserLevel>(doc["level"].as<int>());

if (conf::debug::ENABLE_LOGS)
Serial.printf("Parsed user response as request_ok %d result %d name %s level %d\r\n", response->request_ok, static_cast<int>(response->result), response->holder_name.data(), response->user_level);
Serial.printf("Parsed user response as request_ok %d result %u name %s level %u\r\n", response->request_ok, static_cast<uint8_t>(response->result), response->holder_name.data(), static_cast<uint8_t>(response->user_level));

return response;
}
Expand All @@ -88,7 +88,7 @@ namespace ServerMQTT
response->needs_maintenance = doc["maintenance"];
response->allowed = doc["allowed"];
if (conf::debug::ENABLE_LOGS)
Serial.printf("Parsed machine response as request_ok %d is_valid %d maintenance %d allowed %d name %s\r\n",
Serial.printf("Parsed machine response as request_ok %d is_valid %d maintenance %d allowed %d\r\n",
response->request_ok, response->is_valid, response->needs_maintenance, response->allowed);

return response;
Expand Down
10 changes: 6 additions & 4 deletions src/Machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ using namespace std::chrono;

/// @brief Creates a new machine
/// @param user_conf configuration of the machine
Machine::Machine(const Config user_conf, FabServer &server) : config(user_conf), active(false),
maintenanceNeeded(false), allowed(true),
server(server), power_state(PowerState::UNKNOWN)
Machine::Machine(const Config user_conf, FabServer &server) : maintenanceNeeded(false), allowed(true),
config(user_conf),
server(server),
active(false),
power_state(PowerState::UNKNOWN)
{
this->current_user = FabUser();
pinMode(this->config.control_pin, OUTPUT);
Expand Down Expand Up @@ -75,7 +77,7 @@ void Machine::logout()
{
this->logout_timestamp = system_clock::now();
if (conf::debug::ENABLE_LOGS)
Serial.printf("Machine will be shutdown in %d s\r\n",
Serial.printf("Machine will be shutdown in %lld s\r\n",
duration_cast<seconds>(conf::machine::POWEROFF_GRACE_PERIOD).count());
}
else
Expand Down
10 changes: 2 additions & 8 deletions src/MockRFIDWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,8 @@ bool MockRFIDWrapper::cardStillThere(const card::uid_t original) const
for (auto i = 0; i < 3; i++)
{
// Detect Tag without looking for collisions
byte bufferATQA[2];
byte bufferSize = sizeof(bufferATQA);

if (true)
{
if (this->readCardSerial() && this->getUid() == original)
return true;
}
if (this->readCardSerial() && this->getUid() == original)
return true;
delay(5);
}
return false;
Expand Down
2 changes: 0 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ void taskBlink()
/// @brief periodic check if the machine must be powered off
void taskPoweroffCheck()
{
static bool value = false;

if (conf::debug::ENABLE_TASK_LOGS)
Serial.println("taskPoweroffCheck");

Expand Down

0 comments on commit 37fdfcc

Please sign in to comment.