Skip to content

Commit

Permalink
Fix some printf formatting because esp-idf v5 defines int32_t as long…
Browse files Browse the repository at this point in the history
… instead of int
  • Loading branch information
DavidSchinazi committed Dec 22, 2024
1 parent a85c4d6 commit 0f82e2d
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/jazzlights/fastled_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ void FastLedRunner::Render() {
player_->set_power_limited(powerAtDesiredBrightness > JL_MAX_MILLIWATTS);
if (player_->is_power_limited()) { brightness = brightness * JL_MAX_MILLIWATTS / powerAtDesiredBrightness; }

jll_debug("pf%6u pd%5u bu%4u bs%4u mW%5u mA%5u%s", powerAtFullBrightness,
jll_debug("pf%6" PRIu32 " pd%5" PRIu32 " bu%4u bs%4" PRIu32 " mW%5" PRIu32 " mA%5" PRIu32 "%s",
powerAtFullBrightness,
powerAtDesiredBrightness, // Full-brightness power, desired-brightness power.
player_->brightness(), brightness, // Desired and selected brightness.
powerAtFullBrightness * brightness / 256,
Expand Down
4 changes: 1 addition & 3 deletions src/jazzlights/networks/arduino_esp_wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
jll_info("%u Wi-Fi connected to \"%s\"", timeMillis(), info.wifi_sta_connected.ssid);
break;
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
jll_info("%u Wi-Fi got IP %u.%u.%u.%u", timeMillis(), info.got_ip.ip_info.ip.addr & 0xFF,
(info.got_ip.ip_info.ip.addr >> 8) & 0xFF, (info.got_ip.ip_info.ip.addr >> 16) & 0xFF,
(info.got_ip.ip_info.ip.addr >> 24) & 0xFF);
jll_info("%u Wi-Fi got IP " IPSTR, timeMillis(), IP2STR(&info.got_ip.ip_info.ip));
break;
case ARDUINO_EVENT_WIFI_STA_LOST_IP: jll_info("%u Wi-Fi lost IP", timeMillis()); break;
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
Expand Down
2 changes: 1 addition & 1 deletion src/jazzlights/networks/esp32_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void Esp32BleNetwork::GapCallbackInner(esp_gap_ble_cb_event_t event, esp_ble_gap
jll_error(
"%u Unexpected scan result %s dev_type=%d ble_addr_type=%d"
" ble_evt_type=%d rssi=%d flag=%d num_resps=%d adv_data_len=%u"
" scan_rsp_len=%u num_dis=%u",
" scan_rsp_len=%u num_dis=%" PRIu32,
currentTime, macAddressString, param->scan_rst.dev_type, param->scan_rst.ble_addr_type,
param->scan_rst.ble_evt_type, param->scan_rst.rssi, param->scan_rst.flag, param->scan_rst.num_resps,
param->scan_rst.adv_data_len, param->scan_rst.scan_rsp_len, param->scan_rst.num_dis);
Expand Down
8 changes: 4 additions & 4 deletions src/jazzlights/networks/esp32_wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ void Esp32WiFiNetwork::HandleNetworkEvent(const Esp32WiFiNetworkEvent& networkEv
case Esp32WiFiNetworkEvent::Type::kStationDisconnected:
reconnectCount_++;
if (reconnectCount_ < kNumReconnectsBeforeDelay) {
jll_info("%u Esp32WiFiNetwork queue station disconnected (count %u) - reconnecting immediately", timeMillis(),
reconnectCount_);
jll_info("%u Esp32WiFiNetwork queue station disconnected (count %" PRIu32 ") - reconnecting immediately",
timeMillis(), reconnectCount_);
esp_wifi_connect();
} else {
jll_info("%u Esp32WiFiNetwork queue station disconnected (count %u)", timeMillis(), reconnectCount_);
jll_info("%u Esp32WiFiNetwork queue station disconnected (count %" PRIu32 ")", timeMillis(), reconnectCount_);
shouldArmQueueReconnectionTimeout_ = true;
}
break;
Expand Down Expand Up @@ -302,7 +302,7 @@ void Esp32WiFiNetwork::RunTask() {
shouldArmQueueReconnectionTimeout_ = false;
// Backoff exponentially from 1s to 32s.
queueDelay = 1 << std::min<uint32_t>(reconnectCount_ - kNumReconnectsBeforeDelay, 5);
jll_info("%u Esp32WiFiNetwork waiting for queue event with %us timeout", timeMillis(), queueDelay);
jll_info("%u Esp32WiFiNetwork waiting for queue event with %" PRIu32 "s timeout", timeMillis(), queueDelay);
queueDelay *= 1000 / portTICK_PERIOD_MS;
} else {
jll_info("%u Esp32WiFiNetwork waiting for queue event forever", timeMillis());
Expand Down
10 changes: 5 additions & 5 deletions src/jazzlights/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ bool Player::render(Milliseconds currentTime) {
return true;
}

void Player::GenerateFPSReport(uint32_t* fpsCompute, uint32_t* fpsWrites, uint8_t* utilization,
void Player::GenerateFPSReport(uint16_t* fpsCompute, uint16_t* fpsWrites, uint8_t* utilization,
Milliseconds* timeSpentComputingThisEpoch, Milliseconds* epochDuration) {
const Milliseconds currentTime = timeMillis();
*epochDuration = currentTime - fpsEpochStart_;
Expand Down Expand Up @@ -705,8 +705,8 @@ void Player::checkLeaderAndPattern(Milliseconds currentTime) {
lastOriginationTime = entry->lastOriginationTime;
if (currentPattern_ != entry->currentPattern) {
currentPattern_ = entry->currentPattern;
uint32_t fpsCompute;
uint32_t fpsWrites;
uint16_t fpsCompute;
uint16_t fpsWrites;
uint8_t utilization;
Milliseconds timeSpentComputingThisEpoch;
Milliseconds epochDuration;
Expand Down Expand Up @@ -739,8 +739,8 @@ void Player::checkLeaderAndPattern(Milliseconds currentTime) {
currentPattern_ = nextPattern_;
nextPattern_ = enforceForcedPalette(computeNextPattern(nextPattern_));
}
uint32_t fpsCompute;
uint32_t fpsWrites;
uint16_t fpsCompute;
uint16_t fpsWrites;
uint8_t utilization;
Milliseconds timeSpentComputingThisEpoch;
Milliseconds epochDuration;
Expand Down
3 changes: 2 additions & 1 deletion src/jazzlights/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "jazzlights/network.h"
#include "jazzlights/pseudorandom.h"
#include "jazzlights/renderer.h"
#include "jazzlights/types.h"

namespace jazzlights {

Expand Down Expand Up @@ -81,7 +82,7 @@ class Player {
/**
* Computes FPS information and resets counters.
*/
void GenerateFPSReport(uint32_t* fpsCompute, uint32_t* fpsWrites, uint8_t* utilization,
void GenerateFPSReport(uint16_t* fpsCompute, uint16_t* fpsWrites, uint8_t* utilization,
Milliseconds* timeSpentComputingThisEpoch, Milliseconds* epochDuration);

/**
Expand Down
5 changes: 4 additions & 1 deletion src/jazzlights/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

namespace jazzlights {

using PatternBits = uint32_t;
// We would normally define PatternBits as int32_t, but then some compilers would require us to use PRIu32 as a printf
// format, so we define it as int so we can use %u instead.
using PatternBits = unsigned int;
static_assert(sizeof(uint32_t) == sizeof(PatternBits), "bad int size");
using Precedence = uint16_t;
using NumHops = uint8_t;

Expand Down
5 changes: 4 additions & 1 deletion src/jazzlights/util/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

namespace jazzlights {

typedef int32_t Milliseconds;
// We would normally define Milliseconds as int32_t, but then some compilers would require us to use PRId32 as a printf
// format, so we define it as int so we can use %d instead.
typedef int Milliseconds;
static_assert(sizeof(int32_t) == sizeof(Milliseconds), "bad int size");

enum : Milliseconds {
ONE_SECOND = 1000,
Expand Down

0 comments on commit 0f82e2d

Please sign in to comment.