Skip to content

Commit

Permalink
Introduce Network::shortNetworkName
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSchinazi committed Dec 11, 2023
1 parent 33ebb71 commit d2e689f
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/jazzlights/core2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,15 +627,11 @@ std::string bleStatus(Milliseconds currentTime) {
}

std::string otherStatus(Player& player, Milliseconds currentTime) {
char otherStatusStr[100] = "Leading";
if (player.followedNextHopNetwork() == ArduinoEspWiFiNetwork::get()) {
snprintf(otherStatusStr, sizeof(otherStatusStr) - 1, "Following Wi-Fi nh=%u", player.currentNumHops());
}
#if ESP32_BLE
else if (player.followedNextHopNetwork() == Esp32BleNetwork::get()) {
snprintf(otherStatusStr, sizeof(otherStatusStr) - 1, "Following BLE nh=%u", player.currentNumHops());
}
#endif // ESP32_BLE
const Network* followedNextHopNetwork = player.followedNextHopNetwork();
if (followedNextHopNetwork == nullptr) { return std::string("Leading"); }
char otherStatusStr[100] = {};
snprintf(otherStatusStr, sizeof(otherStatusStr) - 1, "Following %s nh=%u", followedNextHopNetwork->shortNetworkName(),
player.currentNumHops());
return std::string(otherStatusStr);
}

Expand Down
3 changes: 3 additions & 0 deletions src/jazzlights/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class Network {
// A static name for this network class suitable for logging.
virtual const char* networkName() const = 0;

// A static name for this network class suitable for displaying when screen size is limited.
virtual const char* shortNetworkName() const = 0;

// Whether we should advertise patterns on this network if that's where we received them.
virtual bool shouldEcho() const = 0;

Expand Down
1 change: 1 addition & 0 deletions src/jazzlights/networks/arduino_esp_wifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ArduinoEspWiFiNetwork : public UdpNetwork {
void send(void* buf, size_t bufsize) override;
NetworkDeviceId getLocalDeviceId() override { return localDeviceId_; }
const char* networkName() const override { return "ArduinoEspWiFiNetwork"; }
const char* shortNetworkName() const override { return "WiFi"; }
std::string getStatusStr(Milliseconds currentTime) const override;

struct Credentials {
Expand Down
1 change: 1 addition & 0 deletions src/jazzlights/networks/arduino_ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ArduinoEthernetNetwork : public UdpNetwork {
void send(void* buf, size_t bufsize) override;
NetworkDeviceId getLocalDeviceId() override { return localDeviceId_; }
const char* networkName() const override { return "ArduinoEthernet"; }
const char* shortNetworkName() const override { return "Eth"; }
std::string getStatusStr(Milliseconds currentTime) const override;

private:
Expand Down
1 change: 1 addition & 0 deletions src/jazzlights/networks/esp32_ble.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Esp32BleNetwork : public Network {
// Get this device's BLE MAC address.
NetworkDeviceId getLocalDeviceId() override { return localDeviceId_; }
const char* networkName() const override { return "ESP32BLE"; }
const char* shortNetworkName() const override { return "BLE"; }
bool shouldEcho() const override { return true; }
Milliseconds getLastReceiveTime() const override { return lastReceiveTime_; }
std::string getStatusStr(Milliseconds currentTime) const override;
Expand Down
1 change: 1 addition & 0 deletions src/jazzlights/networks/esp32_wifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Esp32WiFiNetwork : public Network {
NetworkStatus update(NetworkStatus status, Milliseconds currentTime) override;
NetworkDeviceId getLocalDeviceId() override { return localDeviceId_; }
const char* networkName() const override { return "Esp32WiFi"; }
const char* shortNetworkName() const override { return "WiFi"; }
std::string getStatusStr(Milliseconds currentTime) const override;
void setMessageToSend(const NetworkMessage& messageToSend, Milliseconds currentTime) override;
void disableSending(Milliseconds currentTime) override;
Expand Down
1 change: 1 addition & 0 deletions src/jazzlights/networks/unix_udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class UnixUdpNetwork : public UdpNetwork {
int recv(void* buf, size_t bufsize, std::string* details) override;
void send(void* buf, size_t bufsize) override;
const char* networkName() const override { return "UnixUDP"; }
const char* shortNetworkName() const override { return "Unix"; }
std::string getStatusStr(Milliseconds /*currentTime*/) const override { return "UnixUDP"; }

private:
Expand Down

0 comments on commit d2e689f

Please sign in to comment.