Skip to content

Commit

Permalink
Merge pull request #49 from hideakitai/refactor/add-wifi-related-methods
Browse files Browse the repository at this point in the history
refactor: add some wifi related methods
  • Loading branch information
hideakitai committed Nov 14, 2023
2 parents 9708288 + 95e5730 commit fd80df8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions ArduinoOSC/ArduinoOSCCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace osc {

void parse() {
#if defined(ARDUINOOSC_ENABLE_WIFI) && (defined(ESP_PLATFORM) || defined(ARDUINO_ARCH_RP2040))
if ((WiFi.status() == WL_CONNECTED) || (WiFi.getMode() != WIFI_STA)) {
if (this->isWiFiConnected() || this->isWiFiModeAP()) {
OscServerManager<S>::getInstance().parse();
} else {
LOG_ERROR(F("WiFi is not connected. Please connected to WiFi"));
Expand All @@ -87,7 +87,7 @@ namespace osc {
template <typename... Ts>
void send(const String& ip, const uint16_t port, const String& addr, Ts&&... ts) {
#if defined(ARDUINOOSC_ENABLE_WIFI) && (defined(ESP_PLATFORM) || defined(ARDUINO_ARCH_RP2040))
if ((WiFi.status() == WL_CONNECTED) || (WiFi.getMode() != WIFI_STA)) {
if (this->isWiFiConnected() || this->isWiFiModeAP()) {
OscClientManager<S>::getInstance().send(ip, port, addr, std::forward<Ts>(ts)...);
} else {
LOG_ERROR(F("WiFi is not connected. Please connected to WiFi"));
Expand All @@ -99,7 +99,7 @@ namespace osc {

void post() {
#if defined(ARDUINOOSC_ENABLE_WIFI) && (defined(ESP_PLATFORM) || defined(ARDUINO_ARCH_RP2040))
if ((WiFi.status() == WL_CONNECTED) || (WiFi.getMode() != WIFI_STA)) {
if (this->isWiFiConnected() || this->isWiFiModeAP()) {
OscClientManager<S>::getInstance().post();
} else {
LOG_ERROR(F("WiFi is not connected. Please connected to WiFi"));
Expand Down Expand Up @@ -133,6 +133,18 @@ namespace osc {
parse();
post();
}

private:
#if defined(ARDUINOOSC_ENABLE_WIFI) && (defined(ESP_PLATFORM) || defined(ARDUINO_ARCH_RP2040))
bool isWiFiConnected() {
return WiFi.status() == WL_CONNECTED;
}

bool isWiFiModeAP() {
auto mode = WiFi.getMode();
return (mode == WIFI_STA) || (mode == WIFI_AP_STA);
}
#endif
};

} // namespace osc
Expand Down

0 comments on commit fd80df8

Please sign in to comment.