Skip to content

Commit a1d5d48

Browse files
Added power saving disabling to all examples + updated libmapper
1 parent 354f857 commit a1d5d48

File tree

5 files changed

+43
-86
lines changed

5 files changed

+43
-86
lines changed

compat/src/getnameinfo.c

Lines changed: 24 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,28 @@
1-
/*
2-
* Copyright (C) 2015 - 2018, IBEROXARXA SERVICIOS INTEGRALES, S.L.
3-
* Copyright (C) 2015 - 2018, Jaume Olivé Petrus ([email protected])
4-
*
5-
* All rights reserved.
6-
*
7-
* Redistribution and use in source and binary forms, with or without
8-
* modification, are permitted provided that the following conditions are met:
9-
*
10-
* * Redistributions of source code must retain the above copyright
11-
* notice, this list of conditions and the following disclaimer.
12-
* * Redistributions in binary form must reproduce the above copyright
13-
* notice, this list of conditions and the following disclaimer in the
14-
* documentation and/or other materials provided with the distribution.
15-
* * Neither the name of the <organization> nor the
16-
* names of its contributors may be used to endorse or promote products
17-
* derived from this software without specific prior written permission.
18-
* * The WHITECAT logotype cannot be changed, you can remove it, but you
19-
* cannot change it in any way. The WHITECAT logotype is:
20-
*
21-
* /\ /\
22-
* / \_____/ \
23-
* /_____________\
24-
* W H I T E C A T
25-
*
26-
* * Redistributions in binary form must retain all copyright notices printed
27-
* to any local or remote output device. This include any reference to
28-
* Lua RTOS, whitecatboard.org, Lua, and other copyright notices that may
29-
* appear in the future.
30-
*
31-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
32-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34-
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
35-
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36-
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37-
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
38-
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41-
*
42-
* Lua RTOS getnameinfo implementation
43-
*
44-
*/
45-
46-
/*
47-
* IMPORTANT NOTICE:
48-
*
49-
* In Lua RTOS the getnameinfo function implementation is incomplete.
50-
* We must found a method to do a reverse DNS query in LWIP to full
51-
* implement this function.
52-
*
53-
*/
54-
551
#include "netdb.h"
56-
#include "lwip/ip_addr.h"
572
#include "compat.h"
583

59-
int
60-
getnameinfo(const struct sockaddr *sa, socklen_t salen,
61-
char *host, size_t hostlen,
62-
char *serv, size_t servlen, int flags)
63-
{
64-
if (flags & ~(NI_NUMERICHOST | NI_NUMERICSERV)) {
65-
return EAI_BADFLAGS;
66-
}
67-
68-
const struct sockaddr_in *sinp = (const struct sockaddr_in *) sa;
69-
70-
switch (sa->sa_family) {
71-
case AF_INET:
72-
if (flags & NI_NUMERICHOST) {
73-
if (inet_ntop (AF_INET, &sinp->sin_addr, host, hostlen) == NULL) {
74-
return EAI_OVERFLOW;
75-
}
76-
}
77-
78-
if (flags & NI_NUMERICSERV) {
79-
if (snprintf(serv, servlen, "%d", ntohs (sinp->sin_port)) < 0) {
80-
return EAI_OVERFLOW;
81-
}
82-
}
83-
84-
break;
85-
}
86-
87-
88-
return 0;
4+
int getnameinfo(const struct sockaddr *sa, socklen_t salen,
5+
char *host, size_t hostlen,
6+
char *serv, size_t servlen, int flags) {
7+
if (flags & ~(NI_NUMERICHOST | NI_NUMERICSERV)) {
8+
return EAI_BADFLAGS;
9+
}
10+
11+
const struct sockaddr_in* sinp = (const struct sockaddr_in*) sa;
12+
13+
if (sa->sa_family == AF_INET) {
14+
if (flags & NI_NUMERICHOST) {
15+
if (inet_ntop(AF_INET, &sinp->sin_addr, host, hostlen) == NULL) {
16+
return EAI_OVERFLOW;
17+
}
18+
}
19+
if (flags & NI_NUMERICSERV) {
20+
if (snprintf(serv, servlen, "%d", ntohs(sinp->sin_port)) < 0) {
21+
return EAI_OVERFLOW;
22+
}
23+
}
24+
} else {
25+
return EAI_FAMILY;
26+
}
27+
return 0;
8928
}

examples/Example_AnalogRead/Example_AnalogRead.ino

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#include "WiFi.h"
44
#include "mapper.h"
55

6+
// For disabling power saving
7+
#include "esp_wifi.h"
8+
69
// WiFi ssid and password
710
const char* ssid = "ssid";
811
const char* password = "password";
@@ -16,6 +19,9 @@ void setup() {
1619
// Begin WiFi before creating mapper device
1720
WiFi.begin(ssid, password);
1821

22+
// Disable WiFi power save (huge latency improvements)
23+
esp_wifi_set_ps(WIFI_PS_NONE)
24+
1925
// Wait for connection
2026
while (WiFi.status() != WL_CONNECTED) {
2127
delay(500);

examples/Example_ESP32/Example_ESP32.ino

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include <WiFi.h>
22
#include "mapper.h"
33

4+
// For disabling power saving
5+
#include "esp_wifi.h"
6+
47
const char* ssid = "WIFI_SSID";
58
const char* password = "WIFI_PASSWORD";
69

@@ -13,6 +16,9 @@ float received_value = 0;
1316
void setup() {
1417
WiFi.begin(ssid, password);
1518

19+
// Disable WiFi power save (huge latency improvements)
20+
esp_wifi_set_ps(WIFI_PS_NONE)
21+
1622
while (WiFi.status() != WL_CONNECTED) {
1723
delay(500);
1824
}

examples/Example_M5StickC/Example_M5StickC.ino

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#include <M5StickC.h>
33
#include "mapper.h"
44

5+
// For disabling power saving
6+
#include "esp_wifi.h"
7+
58
const char* ssid = "WIFI_SSID";
69
const char* password = "WIFI_PASSWORD";
710

@@ -17,6 +20,9 @@ void setup() {
1720

1821
WiFi.begin(ssid, password);
1922

23+
// Disable WiFi power save (huge latency improvements)
24+
esp_wifi_set_ps(WIFI_PS_NONE)
25+
2026
while (WiFi.status() != WL_CONNECTED) {
2127
M5.Lcd.fillScreen(ORANGE);
2228
delay(250);

0 commit comments

Comments
 (0)