diff --git a/boards.txt b/boards.txt index f8c1b2bfa40..d117860fc3e 100644 --- a/boards.txt +++ b/boards.txt @@ -6,59 +6,7 @@ menu.DebugLevel=Core Debug Level ############################################################## -nefrybtr3.name=Nefry BT R3 - -nefrybtr3.upload.tool=esptool -nefrybtr3.upload.maximum_size=1703936 -nefrybtr3.upload.maximum_data_size=294912 -nefrybtr3.upload.wait_for_upload_port=true - -nefrybtr3.serial.disableDTR=true -nefrybtr3.serial.disableRTS=true - -nefrybtr3.build.mcu=esp32 -nefrybtr3.build.core=esp32 -nefrybtr3.build.variant=nefrybt-r3 -nefrybtr3.build.board=Nefry_BT_R3 -nefrybtr3.build.partitions=default - -nefrybtr3.build.f_cpu=240000000L -nefrybtr3.build.flash_mode=dio -nefrybtr3.build.flash_size=4MB -nefrybtr3.build.boot=bootloader -nefrybtr3.build.flash_freq=80m - -nefrybtr3.menu.UploadSpeed.921600=921600 -nefrybtr3.menu.UploadSpeed.921600.upload.speed=921600 -nefrybtr3.menu.UploadSpeed.115200=115200 -nefrybtr3.menu.UploadSpeed.115200.upload.speed=115200 -nefrybtr3.menu.UploadSpeed.256000.windows=256000 -nefrybtr3.menu.UploadSpeed.256000.upload.speed=256000 -nefrybtr3.menu.UploadSpeed.230400.windows.upload.speed=256000 -nefrybtr3.menu.UploadSpeed.230400=230400 -nefrybtr3.menu.UploadSpeed.230400.upload.speed=230400 -nefrybtr3.menu.UploadSpeed.460800.linux=460800 -nefrybtr3.menu.UploadSpeed.460800.macosx=460800 -nefrybtr3.menu.UploadSpeed.460800.upload.speed=460800 -nefrybtr3.menu.UploadSpeed.512000.windows=512000 -nefrybtr3.menu.UploadSpeed.512000.upload.speed=512000 - -nefrybtr3.menu.DebugLevel.none=None -nefrybtr3.menu.DebugLevel.none.build.code_debug=0 -nefrybtr3.menu.DebugLevel.error=Error -nefrybtr3.menu.DebugLevel.error.build.code_debug=1 -nefrybtr3.menu.DebugLevel.warn=Warn -nefrybtr3.menu.DebugLevel.warn.build.code_debug=2 -nefrybtr3.menu.DebugLevel.info=Info -nefrybtr3.menu.DebugLevel.info.build.code_debug=3 -nefrybtr3.menu.DebugLevel.debug=Debug -nefrybtr3.menu.DebugLevel.debug.build.code_debug=4 -nefrybtr3.menu.DebugLevel.verbose=Verbose -nefrybtr3.menu.DebugLevel.verbose.build.code_debug=5 - -############################################################## - -nefrybtr2.name=Nefry BT R2 +nefrybtr2.name=Nefry BT R2 / R3 nefrybtr2.upload.tool=esptool nefrybtr2.upload.maximum_size=1703936 @@ -94,6 +42,8 @@ nefrybtr2.menu.UploadSpeed.460800.macosx=460800 nefrybtr2.menu.UploadSpeed.460800.upload.speed=460800 nefrybtr2.menu.UploadSpeed.512000.windows=512000 nefrybtr2.menu.UploadSpeed.512000.upload.speed=512000 +nefrybtr2.menu.UploadSpeed.1500000=1500000 +nefrybtr2.menu.UploadSpeed.1500000.upload.speed=1500000 nefrybtr2.menu.DebugLevel.none=None nefrybtr2.menu.DebugLevel.none.build.code_debug=0 diff --git a/cores/esp32/nefry/Nefry.cpp b/cores/esp32/nefry/Nefry.cpp index e69d5e8a9ff..40ed6de2bf7 100644 --- a/cores/esp32/nefry/Nefry.cpp +++ b/cores/esp32/nefry/Nefry.cpp @@ -24,11 +24,10 @@ BootMode 1 : WriteMode切替をする */ -#define LIBVERSION ("1.2.1") +#define LIBVERSION ("1.2.2") #include "Nefry.h" Adafruit_NeoPixel _NefryLEDNeo; -Adafruit_DotStar _NefryLEDStar; bool connectAnFlg = false; //main @@ -37,11 +36,7 @@ void Nefry_lib::nefry_init() { connectAnFlg = false; delay(10); NefryDisplay.begin();//logo表示 - if (boardId == 3) { - beginLed((const int)1, (const int)LED_DO, (uint8_t)DOTSTAR_BRG, LED_CLK); - } else { - beginLed((const int)1, (const int)16, (uint8_t)NEO_GRBW); - } + beginLed((const int)1, (const int)16, (uint8_t)NEO_GRBW); setLedBlink(0, 0, 0, false, 0); setLed(0x00, 0x0f, 0x00); enableSW(); @@ -88,6 +83,7 @@ void Nefry_lib::nefry_init() { if(Nefry.getWifiEnabled()){ printDeviceInfo(); } + MDNS.begin("nefrybt"); setLed(0x00, 0xff, 0xff); _nefryWifiWait = 0; } @@ -298,35 +294,22 @@ bool Nefry_lib::getPollingSW() } //LED -void Nefry_lib::beginLed(const int num, const int DataOut, uint8_t t ,const int clk) { - if (boardId == 3) { // Nefry BT r3 - _NefryLEDStar = Adafruit_DotStar(num, DataOut, clk, DOTSTAR_BRG); - _NefryLEDStar.begin(); - _NefryLEDStar.show(); - } - else { - _NefryLEDNeo = Adafruit_NeoPixel(num, DataOut, t); - _NefryLEDNeo.begin(); - _NefryLEDNeo.show(); - } +void Nefry_lib::beginLed(const int num, const int DataOut, uint8_t t, const int clk) { + _NefryLEDNeo = Adafruit_NeoPixel(num, DataOut, t); + _NefryLEDNeo.begin(); + _NefryLEDNeo.show(); } void Nefry_lib::setLed(const int r, const int g, const int b, const char w, const int pin, const int num) { - if (boardId == 3) { // Nefry BT r3 - _NefryLEDStar.setBrightness(w); - _NefryLEDStar.setPixelColor(num, r, g, b); - _NefryLEDStar.show(); - } - else { - _NefryLEDNeo.setPixelColor(num, 0, 0, 0); - delay(1); - _NefryLEDNeo.show(); - _NefryLEDNeo.setBrightness(w); - _NefryLEDNeo.setPixelColor(num, map(r, 0, 255, 0, 150), g, b); - delay(1); - _NefryLEDNeo.show(); - } + _NefryLEDNeo.setPixelColor(num, 0, 0, 0); + delay(1); + _NefryLEDNeo.show(); + _NefryLEDNeo.setBrightness(w); + _NefryLEDNeo.setPixelColor(num, map(r, 0, 255, 0, 150), g, b); + delay(1); + _NefryLEDNeo.show(); } + void Nefry_lib::setLed(String _colorStr, const char w, const int pin, const int num) { int _color[3]; for (int i = 0; i < 3; i++) { @@ -421,7 +404,7 @@ void Nefry_lib::setIndexLink(const char title[32], const char url[32]){ ESP32WebServer* Nefry_lib::getWebServer(){ return NefryWebServer.getWebServer(); } -String Nefry_lib::getlistWifi(){ +String Nefry_lib::getWiFiList(){ return NefryWiFi.getlistWifi(); } @@ -485,10 +468,7 @@ bool Nefry_lib::setAnalyticsData(String action) { url += "r1"; break; case 2: - url += "r2"; - break; - case 3: - url += "r3"; + url += "r2/r3"; break; default: url += "error"; diff --git a/cores/esp32/nefry/Nefry.h b/cores/esp32/nefry/Nefry.h index c9f95954664..bcf9c4b4ba2 100644 --- a/cores/esp32/nefry/Nefry.h +++ b/cores/esp32/nefry/Nefry.h @@ -2,7 +2,6 @@ #define Nefry_h #include -#include "./inc/led/Adafruit_DotStar.h" #include "./inc/led/Adafruit_NeoPixel.h" #include "./inc/Preferences/src/Preferences.h" #include "NefryWiFi.h" @@ -13,6 +12,7 @@ #include "NefryWeb.h" #include "NefryWebServer.h" #include "./inc/WiFi/src/WiFiClient.h" +#include "./inc/ESPmDNS/src/ESPmDNS.h" // Offset: W R G B @@ -54,7 +54,7 @@ class Nefry_lib /* Console */ read(), - getlistWifi(), + getWiFiList(), createHtml(String title, String head, String body); long diff --git a/cores/esp32/nefry/inc/ESPmDNS/examples/mDNS-SD_Extended/mDNS-SD_Extended.ino b/cores/esp32/nefry/inc/ESPmDNS/examples/mDNS-SD_Extended/mDNS-SD_Extended.ino new file mode 100644 index 00000000000..6f2dfddfb3b --- /dev/null +++ b/cores/esp32/nefry/inc/ESPmDNS/examples/mDNS-SD_Extended/mDNS-SD_Extended.ino @@ -0,0 +1,80 @@ +/* + ESP8266 mDNS-SD responder and query sample + + This is an example of announcing and finding services. + + Instructions: + - Update WiFi SSID and password as necessary. + - Flash the sketch to two ESP8266 boards + - The last one powered on should now find the other. + */ + +#include +#include + +const char* ssid = "..."; +const char* password = "..."; + +void setup() { + Serial.begin(115200); + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(250); + Serial.print("."); + } + Serial.println(""); + Serial.print("Connected to "); + Serial.println(ssid); + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); + + if (!MDNS.begin("ESP32_Browser")) { + Serial.println("Error setting up MDNS responder!"); + while(1){ + delay(1000); + } + } +} + +void loop() { + browseService("http", "tcp"); + delay(1000); + browseService("arduino", "tcp"); + delay(1000); + browseService("workstation", "tcp"); + delay(1000); + browseService("smb", "tcp"); + delay(1000); + browseService("afpovertcp", "tcp"); + delay(1000); + browseService("ftp", "tcp"); + delay(1000); + browseService("ipp", "tcp"); + delay(1000); + browseService("printer", "tcp"); + delay(10000); +} + +void browseService(const char * service, const char * proto){ + Serial.printf("Browsing for service _%s._%s.local. ... ", service, proto); + int n = MDNS.queryService(service, proto); + if (n == 0) { + Serial.println("no services found"); + } else { + Serial.print(n); + Serial.println(" service(s) found"); + for (int i = 0; i < n; ++i) { + // Print details for each service found + Serial.print(" "); + Serial.print(i + 1); + Serial.print(": "); + Serial.print(MDNS.hostname(i)); + Serial.print(" ("); + Serial.print(MDNS.IP(i)); + Serial.print(":"); + Serial.print(MDNS.port(i)); + Serial.println(")"); + } + } + Serial.println(); +} diff --git a/cores/esp32/nefry/inc/ESPmDNS/examples/mDNS_Web_Server/mDNS_Web_Server.ino b/cores/esp32/nefry/inc/ESPmDNS/examples/mDNS_Web_Server/mDNS_Web_Server.ino new file mode 100644 index 00000000000..b25e33b9602 --- /dev/null +++ b/cores/esp32/nefry/inc/ESPmDNS/examples/mDNS_Web_Server/mDNS_Web_Server.ino @@ -0,0 +1,120 @@ +/* + ESP32 mDNS responder sample + + This is an example of an HTTP server that is accessible + via http://esp32.local URL thanks to mDNS responder. + + Instructions: + - Update WiFi SSID and password as necessary. + - Flash the sketch to the ESP32 board + - Install host software: + - For Linux, install Avahi (http://avahi.org/). + - For Windows, install Bonjour (http://www.apple.com/support/bonjour/). + - For Mac OSX and iOS support is built in through Bonjour already. + - Point your browser to http://esp32.local, you should see a response. + + */ + + +#include +#include +#include + +const char* ssid = "............"; +const char* password = ".............."; + +// TCP server at port 80 will respond to HTTP requests +WiFiServer server(80); + +void setup(void) +{ + Serial.begin(115200); + + // Connect to WiFi network + WiFi.begin(ssid, password); + Serial.println(""); + + // Wait for connection + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println(""); + Serial.print("Connected to "); + Serial.println(ssid); + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); + + // Set up mDNS responder: + // - first argument is the domain name, in this example + // the fully-qualified domain name is "esp8266.local" + // - second argument is the IP address to advertise + // we send our IP address on the WiFi network + if (!MDNS.begin("esp32")) { + Serial.println("Error setting up MDNS responder!"); + while(1) { + delay(1000); + } + } + Serial.println("mDNS responder started"); + + // Start TCP (HTTP) server + server.begin(); + Serial.println("TCP server started"); + + // Add service to MDNS-SD + MDNS.addService("http", "tcp", 80); +} + +void loop(void) +{ + // Check if a client has connected + WiFiClient client = server.available(); + if (!client) { + return; + } + Serial.println(""); + Serial.println("New client"); + + // Wait for data from client to become available + while(client.connected() && !client.available()){ + delay(1); + } + + // Read the first line of HTTP request + String req = client.readStringUntil('\r'); + + // First line of HTTP request looks like "GET /path HTTP/1.1" + // Retrieve the "/path" part by finding the spaces + int addr_start = req.indexOf(' '); + int addr_end = req.indexOf(' ', addr_start + 1); + if (addr_start == -1 || addr_end == -1) { + Serial.print("Invalid request: "); + Serial.println(req); + return; + } + req = req.substring(addr_start + 1, addr_end); + Serial.print("Request: "); + Serial.println(req); + client.flush(); + + String s; + if (req == "/") + { + IPAddress ip = WiFi.localIP(); + String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]); + s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\nHello from ESP32 at "; + s += ipStr; + s += "\r\n\r\n"; + Serial.println("Sending 200"); + } + else + { + s = "HTTP/1.1 404 Not Found\r\n\r\n"; + Serial.println("Sending 404"); + } + client.print(s); + + Serial.println("Done with client"); +} + diff --git a/cores/esp32/nefry/inc/ESPmDNS/keywords.txt b/cores/esp32/nefry/inc/ESPmDNS/keywords.txt new file mode 100644 index 00000000000..cbc59312026 --- /dev/null +++ b/cores/esp32/nefry/inc/ESPmDNS/keywords.txt @@ -0,0 +1,25 @@ +####################################### +# Syntax Coloring Map For Ultrasound +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +ESPmDNS KEYWORD1 +MDNS KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +begin KEYWORD2 +end KEYWORD2 +addService KEYWORD2 +enableArduino KEYWORD2 +disableArduino KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + diff --git a/cores/esp32/nefry/inc/ESPmDNS/library.properties b/cores/esp32/nefry/inc/ESPmDNS/library.properties new file mode 100644 index 00000000000..4f9561961b9 --- /dev/null +++ b/cores/esp32/nefry/inc/ESPmDNS/library.properties @@ -0,0 +1,9 @@ +name=ESPmDNS +version=1.0 +author=Hristo Gochkov, Ivan Grokhtkov +maintainer=Hristo Gochkov +sentence=ESP32 mDNS Library +paragraph= +category=Communication +url= +architectures=esp32 diff --git a/cores/esp32/nefry/inc/ESPmDNS/src/ESPmDNS.cpp b/cores/esp32/nefry/inc/ESPmDNS/src/ESPmDNS.cpp new file mode 100644 index 00000000000..e18da71e56f --- /dev/null +++ b/cores/esp32/nefry/inc/ESPmDNS/src/ESPmDNS.cpp @@ -0,0 +1,187 @@ +/* + +ESP8266 Multicast DNS (port of CC3000 Multicast DNS library) +Version 1.1 +Copyright (c) 2013 Tony DiCola (tony@tonydicola.com) +ESP8266 port (c) 2015 Ivan Grokhotkov (ivan@esp8266.com) +MDNS-SD Suport 2015 Hristo Gochkov (hristo@espressif.com) +Extended MDNS-SD support 2016 Lars Englund (lars.englund@gmail.com) + + +License (MIT license): + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +// Important RFC's for reference: +// - DNS request and response: http://www.ietf.org/rfc/rfc1035.txt +// - Multicast DNS: http://www.ietf.org/rfc/rfc6762.txt +// - MDNS-SD: https://tools.ietf.org/html/rfc6763 + +#ifndef LWIP_OPEN_SRC +#define LWIP_OPEN_SRC +#endif + +#include "ESPmDNS.h" +#include +#include "esp_wifi.h" + +MDNSResponder::MDNSResponder() : mdns(NULL), _if(TCPIP_ADAPTER_IF_STA) {} +MDNSResponder::~MDNSResponder() { + end(); +} + +bool MDNSResponder::begin(const char* hostName, tcpip_adapter_if_t tcpip_if, uint32_t ttl){ + _if = tcpip_if; + if(!mdns && mdns_init(_if, &mdns)){ + log_e("Failed starting MDNS"); + return false; + } + _hostname = hostName; + if(mdns_set_hostname(mdns, hostName)) { + log_e("Failed setting MDNS hostname"); + return false; + } + return true; +} + +void MDNSResponder::end() { + if(!mdns){ + return; + } + mdns_free(mdns); + mdns = NULL; +} + +void MDNSResponder::setInstanceName(String name) { + if (name.length() > 63) return; + if(mdns_set_instance(mdns, name.c_str())){ + log_e("Failed setting MDNS instance"); + return; + } +} + +void MDNSResponder::enableArduino(uint16_t port, bool auth){ + const char * arduTxtData[4] = { + "board=" ARDUINO_BOARD, + "tcp_check=no", + "ssh_upload=no", + "auth_upload=no" + }; + if(auth){ + arduTxtData[3] = "auth_upload=yes"; + } + + if(mdns_service_add(mdns, "_arduino", "_tcp", port)) { + log_e("Failed adding Arduino service"); + } else if(mdns_service_txt_set(mdns, "_arduino", "_tcp", 4, arduTxtData)) { + log_e("Failed setting Arduino service TXT"); + } +} + +void MDNSResponder::disableArduino(){ + if(mdns_service_remove(mdns, "_arduino", "_tcp")) { + log_w("Failed removing Arduino service"); + } +} + +void MDNSResponder::enableWorkstation(){ + char winstance[21+_hostname.length()]; + uint8_t mac[6]; + esp_wifi_get_mac((wifi_interface_t)_if, mac); + sprintf(winstance, "%s [%02x:%02x:%02x:%02x:%02x:%02x]", _hostname.c_str(), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + + if(mdns_service_add(mdns, "_workstation", "_tcp", 9)) { + log_e("Failed adding Workstation service"); + } else if(mdns_service_instance_set(mdns, "_workstation", "_tcp", winstance)) { + log_e("Failed setting Workstation service instance name"); + } +} + +void MDNSResponder::disableWorkstation(){ + if(mdns_service_remove(mdns, "_workstation", "_tcp")) { + log_w("Failed removing Workstation service"); + } +} + +void MDNSResponder::addService(char *name, char *proto, uint16_t port){ + if(mdns_service_add(mdns, name, proto, port)) { + log_e("Failed adding service %s.%s.\n", name, proto); + } +} + +bool MDNSResponder::addServiceTxt(char *name, char *proto, char *key, char *value){ + //ToDo: implement it in IDF. This will set the TXT to one record currently + String txt = String(key) + "=" + String(value); + const char * txt_chr[1] = {txt.c_str()}; + if(mdns_service_txt_set(mdns, name, proto, 1, txt_chr)) { + log_e("Failed setting service TXT"); + return false; + } + return true; +} + +int MDNSResponder::queryService(char *service, char *proto) { + mdns_result_free(mdns); + if(proto){ + char srv[strlen(service)+2]; + char prt[strlen(proto)+2]; + sprintf(srv, "_%s", service); + sprintf(prt, "_%s", proto); + return mdns_query(mdns, srv, prt, 2000); + } + return mdns_query(mdns, service, NULL, 2000); +} + +IPAddress MDNSResponder::queryHost(char *host){ + mdns_result_free(mdns); + if(!mdns_query(mdns, host, NULL, 2000)){ + return IPAddress(); + } + return IP(0); +} + +String MDNSResponder::hostname(int idx) { + const mdns_result_t * result = mdns_result_get(mdns, idx); + if(!result){ + log_e("Result %d not found", idx); + return String(); + } + return String(result->host); +} + +IPAddress MDNSResponder::IP(int idx) { + const mdns_result_t * result = mdns_result_get(mdns, idx); + if(!result){ + log_e("Result %d not found", idx); + return IPAddress(); + } + return IPAddress(result->addr.addr); +} + +uint16_t MDNSResponder::port(int idx) { + const mdns_result_t * result = mdns_result_get(mdns, idx); + if(!result){ + log_e("Result %d not found", idx); + return 0; + } + return result->port; +} + +MDNSResponder MDNS; diff --git a/cores/esp32/nefry/inc/ESPmDNS/src/ESPmDNS.h b/cores/esp32/nefry/inc/ESPmDNS/src/ESPmDNS.h new file mode 100644 index 00000000000..7c0cd65b0fb --- /dev/null +++ b/cores/esp32/nefry/inc/ESPmDNS/src/ESPmDNS.h @@ -0,0 +1,117 @@ +/* +ESP8266 Multicast DNS (port of CC3000 Multicast DNS library) +Version 1.1 +Copyright (c) 2013 Tony DiCola (tony@tonydicola.com) +ESP8266 port (c) 2015 Ivan Grokhotkov (ivan@esp8266.com) +MDNS-SD Suport 2015 Hristo Gochkov (hristo@espressif.com) +Extended MDNS-SD support 2016 Lars Englund (lars.englund@gmail.com) +Rewritten for ESP32 by Hristo Gochkov (hristo@espressif.com) + +This is a simple implementation of multicast DNS query support for an Arduino +running on ESP32 chip. + +Usage: +- Include the ESP32 Multicast DNS library in the sketch. +- Call the begin method in the sketch's setup and provide a domain name (without + the '.local' suffix, i.e. just provide 'foo' to resolve 'foo.local'), and the + Adafruit CC3000 class instance. Optionally provide a time to live (in seconds) + for the DNS record--the default is 1 hour. +- Call the update method in each iteration of the sketch's loop function. + +License (MIT license): + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + +*/ +#ifndef ESP32MDNS_H +#define ESP32MDNS_H + +#include "Arduino.h" +#include "mdns.h" + +//this should be defined at build time +#ifndef ARDUINO_BOARD +#define ARDUINO_BOARD "esp32" +#endif + +class MDNSResponder { +public: + MDNSResponder(); + ~MDNSResponder(); + bool begin(const char* hostName, tcpip_adapter_if_t tcpip_if=TCPIP_ADAPTER_IF_STA, uint32_t ttl=120); + void end(); + + void setInstanceName(String name); + void setInstanceName(const char * name){ + setInstanceName(String(name)); + } + void setInstanceName(char * name){ + setInstanceName(String(name)); + } + + void addService(char *service, char *proto, uint16_t port); + void addService(const char *service, const char *proto, uint16_t port){ + addService((char *)service, (char *)proto, port); + } + void addService(String service, String proto, uint16_t port){ + addService(service.c_str(), proto.c_str(), port); + } + + bool addServiceTxt(char *name, char *proto, char * key, char * value); + void addServiceTxt(const char *name, const char *proto, const char *key,const char * value){ + addServiceTxt((char *)name, (char *)proto, (char *)key, (char *)value); + } + void addServiceTxt(String name, String proto, String key, String value){ + addServiceTxt(name.c_str(), proto.c_str(), key.c_str(), value.c_str()); + } + + void enableArduino(uint16_t port=3232, bool auth=false); + void disableArduino(); + + void enableWorkstation(); + void disableWorkstation(); + + IPAddress queryHost(char *host); + IPAddress queryHost(const char *host){ + return queryHost((char *)host); + } + IPAddress queryHost(String host){ + return queryHost(host.c_str()); + } + + int queryService(char *service, char *proto); + int queryService(const char *service, const char *proto){ + return queryService((char *)service, (char *)proto); + } + int queryService(String service, String proto){ + return queryService(service.c_str(), proto.c_str()); + } + + String hostname(int idx); + IPAddress IP(int idx); + uint16_t port(int idx); + +private: + mdns_server_t * mdns; + tcpip_adapter_if_t _if; + String _hostname; +}; + +extern MDNSResponder MDNS; + +#endif //ESP32MDNS_H diff --git a/cores/esp32/nefry/inc/led/Adafruit_DotStar.cpp b/cores/esp32/nefry/inc/led/Adafruit_DotStar.cpp deleted file mode 100644 index 6950fbce670..00000000000 --- a/cores/esp32/nefry/inc/led/Adafruit_DotStar.cpp +++ /dev/null @@ -1,417 +0,0 @@ -/*------------------------------------------------------------------------ - Arduino library to control Adafruit Dot Star addressable RGB LEDs. - - Written by Limor Fried and Phil Burgess for Adafruit Industries. - - Adafruit invests time and resources providing this open source code, - please support Adafruit and open-source hardware by purchasing products - from Adafruit! - - ------------------------------------------------------------------------ - This file is part of the Adafruit Dot Star library. - - Adafruit Dot Star is free software: you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public License - as published by the Free Software Foundation, either version 3 of - the License, or (at your option) any later version. - - Adafruit Dot Star is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with DotStar. If not, see . - ------------------------------------------------------------------------*/ - -#include "Adafruit_DotStar.h" -#if !defined(__AVR_ATtiny85__) - #include "./../SPI/src/SPI.h" -#endif -SPIClass SPI2; -#define USE_HW_SPI 255 // Assign this to dataPin to indicate 'hard' SPI - - // Constructor for hardware SPI -- must connect to MOSI, SCK pins -Adafruit_DotStar::Adafruit_DotStar() : - numLEDs(0), dataPin(USE_HW_SPI), brightness(0), pixels(NULL), - rOffset(3), gOffset((2) & 3), bOffset((4) & 3) -{ - updateLength(0); -} - -// Constructor for hardware SPI -- must connect to MOSI, SCK pins -Adafruit_DotStar::Adafruit_DotStar(uint16_t n, uint8_t o) : - numLEDs(n), dataPin(USE_HW_SPI), brightness(0), pixels(NULL), - rOffset(o & 3), gOffset((o >> 2) & 3), bOffset((o >> 4) & 3) -{ - updateLength(n); -} - -// Constructor for 'soft' (bitbang) SPI -- any two pins can be used -Adafruit_DotStar::Adafruit_DotStar(uint16_t n, uint8_t data, uint8_t clock, - uint8_t o) : - dataPin(data), clockPin(clock), brightness(0), pixels(NULL), - rOffset(o & 3), gOffset((o >> 2) & 3), bOffset((o >> 4) & 3) -{ - updateLength(n); -} - -Adafruit_DotStar::~Adafruit_DotStar(void) { // Destructor - if(pixels) free(pixels); - if(dataPin == USE_HW_SPI) hw_spi_end(); - else sw_spi_end(); -} - -void Adafruit_DotStar::begin(void) { // Initialize SPI - if(dataPin == USE_HW_SPI) hw_spi_init(); - else sw_spi_init(); -} - -// Pins may be reassigned post-begin(), so a sketch can store hardware -// config in flash, SD card, etc. rather than hardcoded. Also permits -// "recycling" LED ram across multiple strips: set pins to first strip, -// render & write all data, reassign pins to next strip, render & write, -// etc. They won't update simultaneously, but usually unnoticeable. - -// Change to hardware SPI -- must connect to MOSI, SCK pins -void Adafruit_DotStar::updatePins(void) { - sw_spi_end(); - dataPin = USE_HW_SPI; - hw_spi_init(); -} - -// Change to 'soft' (bitbang) SPI -- any two pins can be used -void Adafruit_DotStar::updatePins(uint8_t data, uint8_t clock) { - hw_spi_end(); - dataPin = data; - clockPin = clock; - sw_spi_init(); -} - -// Length can be changed post-constructor for similar reasons (sketch -// config not hardcoded). But DON'T use this for "recycling" strip RAM... -// all that reallocation is likely to fragment and eventually fail. -// Instead, set length once to longest strip. -void Adafruit_DotStar::updateLength(uint16_t n) { - if(pixels) free(pixels); - uint16_t bytes = (rOffset == gOffset) ? - n + ((n + 3) / 4) : // MONO: 10 bits/pixel, round up to next byte - n * 3; // COLOR: 3 bytes/pixel - if((pixels = (uint8_t *)malloc(bytes))) { - numLEDs = n; - clear(); - } else { - numLEDs = 0; - } -} - -// SPI STUFF --------------------------------------------------------------- - -void Adafruit_DotStar::hw_spi_init(void) { // Initialize hardware SPI -#ifdef __AVR_ATtiny85__ - PORTB &= ~(_BV(PORTB1) | _BV(PORTB2)); // Outputs - DDRB |= _BV(PORTB1) | _BV(PORTB2); // DO (NOT MOSI) + SCK -#elif (SPI_INTERFACES_COUNT > 0) || !defined(SPI_INTERFACES_COUNT) - SPI2.begin(); - #if defined(__AVR__) || defined(CORE_TEENSY) || defined(__ARDUINO_ARC__) || defined(__ARDUINO_X86__) - SPI2.setClockDivider(SPI_CLOCK_DIV2); // 8 MHz (6 MHz on Pro Trinket 3V) - #else - #if defined(ESP8266) || defined(ESP31B) || defined(ESP32) - SPI2.setFrequency(8000000L); - #elif defined(PIC32) - // Use begin/end transaction to set SPI clock rate - SPI2.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0)); - SPI2.endTransaction(); - #else - SPI2.setClockDivider((F_CPU + 4000000L) / 8000000L); // 8-ish MHz on Due - #endif - #endif - SPI2.setBitOrder(MSBFIRST); - SPI2.setDataMode(SPI_MODE0); -#endif -} - -void Adafruit_DotStar::hw_spi_end(void) { // Stop hardware SPI -#ifdef __AVR_ATtiny85__ - DDRB &= ~(_BV(PORTB1) | _BV(PORTB2)); // Inputs -#elif (SPI_INTERFACES_COUNT > 0) || !defined(SPI_INTERFACES_COUNT) - SPI2.end(); -#endif -} - -void Adafruit_DotStar::sw_spi_init(void) { // Init 'soft' (bitbang) SPI - pinMode(dataPin , OUTPUT); - pinMode(clockPin, OUTPUT); -#ifdef __AVR__ - dataPort = portOutputRegister(digitalPinToPort(dataPin)); - clockPort = portOutputRegister(digitalPinToPort(clockPin)); - dataPinMask = digitalPinToBitMask(dataPin); - clockPinMask = digitalPinToBitMask(clockPin); - *dataPort &= ~dataPinMask; - *clockPort &= ~clockPinMask; -#else - digitalWrite(dataPin , LOW); - digitalWrite(clockPin, LOW); -#endif -} - -void Adafruit_DotStar::sw_spi_end() { // Stop 'soft' SPI - pinMode(dataPin , INPUT); - pinMode(clockPin, INPUT); -} - -#ifdef __AVR_ATtiny85__ - -// Teensy/Gemma-specific stuff for hardware-half-assisted SPI - -#define SPIBIT \ - USICR = ((1< 0) || !defined(SPI_INTERFACES_COUNT) - -// All other boards have full-featured hardware support for SPI - -#define spi_out(n) (void)SPI2.transfer(n) -// Pipelining reads next byte while current byte is clocked out -#if (defined(__AVR__) && !defined(__AVR_ATtiny85__)) || defined(CORE_TEENSY) - #define SPI_PIPELINE -#endif - -#else // no hardware spi -#define spi_out(n) sw_spi_out(n) - -#endif - -void Adafruit_DotStar::sw_spi_out(uint8_t n) { // Bitbang SPI write - for(uint8_t i=8; i--; n <<= 1) { -#ifdef __AVR__ - if(n & 0x80) *dataPort |= dataPinMask; - else *dataPort &= ~dataPinMask; - *clockPort |= clockPinMask; - *clockPort &= ~clockPinMask; -#else - if(n & 0x80) digitalWrite(dataPin, HIGH); - else digitalWrite(dataPin, LOW); - digitalWrite(clockPin, HIGH); - digitalWrite(clockPin, LOW); -#endif - } -} - -/* ISSUE DATA TO LED STRIP ------------------------------------------------- - - Although the LED driver has an additional per-pixel 5-bit brightness - setting, it is NOT used or supported here because it's a brain-dead - misfeature that's counter to the whole point of Dot Stars, which is to - have a much faster PWM rate than NeoPixels. It gates the high-speed - PWM output through a second, much slower PWM (about 400 Hz), rendering - it useless for POV. This brings NOTHING to the table that can't be - already handled better in one's sketch code. If you really can't live - without this abomination, you can fork the library and add it for your - own use, but any pull requests for this will NOT be merged, nuh uh! -*/ - -void Adafruit_DotStar::show(void) { - - if(!pixels) return; - - uint8_t *ptr = pixels, i; // -> LED data - uint16_t n = numLEDs; // Counter - uint16_t b16 = (uint16_t)brightness; // Type-convert for fixed-point math - - if(dataPin == USE_HW_SPI) { - -#ifdef SPI_PIPELINE - uint8_t next; - for(i=0; i<3; i++) spi_out(0x00); // First 3 start-frame bytes - SPDR = 0x00; // 4th is pipelined - do { // For each pixel... - while(!(SPSR & _BV(SPIF))); // Wait for prior byte out - SPDR = 0xFF; // Pixel start - for(i=0; i<3; i++) { // For R,G,B... - next = brightness ? (*ptr++ * b16) >> 8 : *ptr++; // Read, scale - while(!(SPSR & _BV(SPIF))); // Wait for prior byte out - SPDR = next; // Write scaled color - } - } while(--n); - while(!(SPSR & _BV(SPIF))); // Wait for last byte out -#else - for(i=0; i<4; i++) spi_out(0x00); // 4 byte start-frame marker - if(brightness) { // Scale pixel brightness on output - do { // For each pixel... - spi_out(0xFF); // Pixel start - for(i=0; i<3; i++) spi_out((*ptr++ * b16) >> 8); // Scale, write RGB - } while(--n); - } else { // Full brightness (no scaling) - do { // For each pixel... - spi_out(0xFF); // Pixel start - for(i=0; i<3; i++) spi_out(*ptr++); // Write R,G,B - } while(--n); - } -#endif - // Four end-frame bytes are seemingly indistinguishable from a white - // pixel, and empirical testing suggests it can be left out...but it's - // always a good idea to follow the datasheet, in case future hardware - // revisions are more strict (e.g. might mandate use of end-frame - // before start-frame marker). i.e. let's not remove this. But after - // testing a bit more the suggestion is to use at least (numLeds+1)/2 - // high values (1) or (numLeds+15)/16 full bytes as EndFrame. For details see also: - // https://cpldcpu.wordpress.com/2014/11/30/understanding-the-apa102-superled/ - for(i=0; i<((numLEDs + 15) / 16); i++) spi_out(0xFF); - - } else { // Soft (bitbang) SPI - - for(i=0; i<4; i++) sw_spi_out(0); // Start-frame marker - if(brightness) { // Scale pixel brightness on output - do { // For each pixel... - sw_spi_out(0xFF); // Pixel start - for(i=0; i<3; i++) sw_spi_out((*ptr++ * b16) >> 8); // Scale, write - } while(--n); - } else { // Full brightness (no scaling) - do { // For each pixel... - sw_spi_out(0xFF); // Pixel start - for(i=0; i<3; i++) sw_spi_out(*ptr++); // R,G,B - } while(--n); - } - for(i=0; i<((numLEDs + 15) / 16); i++) sw_spi_out(0xFF); // End-frame marker (see note above) - } -} - -void Adafruit_DotStar::clear() { // Write 0s (off) to full pixel buffer - memset(pixels, 0, (rOffset == gOffset) ? - numLEDs + ((numLEDs + 3) / 4) : // MONO: 10 bits/pixel - numLEDs * 3); // COLOR: 3 bytes/pixel -} - -// Set pixel color, separate R,G,B values (0-255 ea.) -void Adafruit_DotStar::setPixelColor( - uint16_t n, uint8_t r, uint8_t g, uint8_t b) { - if(n < numLEDs) { - uint8_t *p = &pixels[n * 3]; - p[rOffset] = r; - p[gOffset] = g; - p[bOffset] = b; - } -} - -// Set pixel color, 'packed' RGB value (0x000000 - 0xFFFFFF) -void Adafruit_DotStar::setPixelColor(uint16_t n, uint32_t c) { - if(n < numLEDs) { - uint8_t *p = &pixels[n * 3]; - p[rOffset] = (uint8_t)(c >> 16); - p[gOffset] = (uint8_t)(c >> 8); - p[bOffset] = (uint8_t)c; - } -} - -// Convert separate R,G,B to packed value -uint32_t Adafruit_DotStar::Color(uint8_t r, uint8_t g, uint8_t b) { - return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b; -} - -// Read color from previously-set pixel, returns packed RGB value. -uint32_t Adafruit_DotStar::getPixelColor(uint16_t n) const { - if(n >= numLEDs) return 0; - uint8_t *p = &pixels[n * 3]; - return ((uint32_t)p[rOffset] << 16) | - ((uint32_t)p[gOffset] << 8) | - (uint32_t)p[bOffset]; -} - -uint16_t Adafruit_DotStar::numPixels(void) { // Ret. strip length - return numLEDs; -} - -// Set global strip brightness. This does not have an immediate effect; -// must be followed by a call to show(). Not a fan of this...for various -// reasons I think it's better handled in one's sketch, but it's here for -// parity with the NeoPixel library. Good news is that brightness setting -// in this library is 'non destructive' -- it's applied as color data is -// being issued to the strip, not during setPixel(), and also means that -// getPixelColor() returns the exact value originally stored. -void Adafruit_DotStar::setBrightness(uint8_t b) { - // Stored brightness value is different than what's passed. This - // optimizes the actual scaling math later, allowing a fast 8x8-bit - // multiply and taking the MSB. 'brightness' is a uint8_t, adding 1 - // here may (intentionally) roll over...so 0 = max brightness (color - // values are interpreted literally; no scaling), 1 = min brightness - // (off), 255 = just below max brightness. - brightness = b + 1; -} - -uint8_t Adafruit_DotStar::getBrightness(void) const { - return brightness - 1; // Reverse above operation -} - -// Return pointer to the library's pixel data buffer. Use carefully, -// much opportunity for mayhem. It's mostly for code that needs fast -// transfers, e.g. SD card to LEDs. Color data is in BGR order. -uint8_t *Adafruit_DotStar::getPixels(void) const { - return pixels; -} - -/* A PROGMEM (flash mem) table containing 8-bit unsigned sine wave (0-255). - Copy & paste this snippet into a Python REPL to regenerate: -import math -for x in range(256): - print("{:3},".format(int((math.sin(x/128.0*math.pi)+1.0)*127.5+0.5))), - if x&15 == 15: print -*/ -static const uint8_t PROGMEM _sineTable[256] = { - 128,131,134,137,140,143,146,149,152,155,158,162,165,167,170,173, - 176,179,182,185,188,190,193,196,198,201,203,206,208,211,213,215, - 218,220,222,224,226,228,230,232,234,235,237,238,240,241,243,244, - 245,246,248,249,250,250,251,252,253,253,254,254,254,255,255,255, - 255,255,255,255,254,254,254,253,253,252,251,250,250,249,248,246, - 245,244,243,241,240,238,237,235,234,232,230,228,226,224,222,220, - 218,215,213,211,208,206,203,201,198,196,193,190,188,185,182,179, - 176,173,170,167,165,162,158,155,152,149,146,143,140,137,134,131, - 128,124,121,118,115,112,109,106,103,100, 97, 93, 90, 88, 85, 82, - 79, 76, 73, 70, 67, 65, 62, 59, 57, 54, 52, 49, 47, 44, 42, 40, - 37, 35, 33, 31, 29, 27, 25, 23, 21, 20, 18, 17, 15, 14, 12, 11, - 10, 9, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 9, - 10, 11, 12, 14, 15, 17, 18, 20, 21, 23, 25, 27, 29, 31, 33, 35, - 37, 40, 42, 44, 47, 49, 52, 54, 57, 59, 62, 65, 67, 70, 73, 76, - 79, 82, 85, 88, 90, 93, 97,100,103,106,109,112,115,118,121,124}; - -/* Similar to above, but for an 8-bit gamma-correction table. - Copy & paste this snippet into a Python REPL to regenerate: -import math -gamma=2.6 -for x in range(256): - print("{:3},".format(int(math.pow((x)/255.0,gamma)*255.0+0.5))), - if x&15 == 15: print -*/ -static const uint8_t PROGMEM _gammaTable[256] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, - 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, - 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, - 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, - 20, 21, 21, 22, 22, 23, 24, 24, 25, 25, 26, 27, 27, 28, 29, 29, - 30, 31, 31, 32, 33, 34, 34, 35, 36, 37, 38, 38, 39, 40, 41, 42, - 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - 58, 59, 60, 61, 62, 63, 64, 65, 66, 68, 69, 70, 71, 72, 73, 75, - 76, 77, 78, 80, 81, 82, 84, 85, 86, 88, 89, 90, 92, 93, 94, 96, - 97, 99,100,102,103,105,106,108,109,111,112,114,115,117,119,120, - 122,124,125,127,129,130,132,134,136,137,139,141,143,145,146,148, - 150,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180, - 182,184,186,188,191,193,195,197,199,202,204,206,209,211,213,215, - 218,220,223,225,227,230,232,235,237,240,242,245,247,250,252,255}; - -uint8_t Adafruit_DotStar::sine8(uint8_t x) const { - return pgm_read_byte(&_sineTable[x]); // 0-255 in, 0-255 out -} - -uint8_t Adafruit_DotStar::gamma8(uint8_t x) const { - return pgm_read_byte(&_gammaTable[x]); // 0-255 in, 0-255 out -} - diff --git a/cores/esp32/nefry/inc/led/Adafruit_DotStar.h b/cores/esp32/nefry/inc/led/Adafruit_DotStar.h deleted file mode 100644 index 8e4dc2d9946..00000000000 --- a/cores/esp32/nefry/inc/led/Adafruit_DotStar.h +++ /dev/null @@ -1,95 +0,0 @@ -/*------------------------------------------------------------------------ - This file is part of the Adafruit Dot Star library. - - Adafruit Dot Star is free software: you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public License - as published by the Free Software Foundation, either version 3 of - the License, or (at your option) any later version. - - Adafruit Dot Star is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with DotStar. If not, see . - ------------------------------------------------------------------------*/ - -#ifndef _ADAFRUIT_DOT_STAR_H_ -#define _ADAFRUIT_DOT_STAR_H_ - -#if (ARDUINO >= 100) - #include -#else - #include - #include -#endif - -// Color-order flag for LED pixels (optional extra parameter to constructor): -// Bits 0,1 = R index (0-2), bits 2,3 = G index, bits 4,5 = B index -#define DOTSTAR_RGB (0 | (1 << 2) | (2 << 4)) -#define DOTSTAR_RBG (0 | (2 << 2) | (1 << 4)) -#define DOTSTAR_GRB (1 | (0 << 2) | (2 << 4)) -#define DOTSTAR_GBR (2 | (0 << 2) | (1 << 4)) -#define DOTSTAR_BRG (1 | (2 << 2) | (0 << 4)) -#define DOTSTAR_BGR (2 | (1 << 2) | (0 << 4)) -#define DOTSTAR_MONO 0 // Single-color strip WIP DO NOT USE YET - -class Adafruit_DotStar { - - public: - Adafruit_DotStar(); - Adafruit_DotStar(uint16_t n, uint8_t o=DOTSTAR_BRG); - Adafruit_DotStar(uint16_t n, uint8_t d, uint8_t c, uint8_t o=DOTSTAR_BRG); - ~Adafruit_DotStar(void); - void - begin(void), // Prime pins/SPI for output - clear(), // Set all pixel data to zero - setBrightness(uint8_t), // Set global brightness 0-255 - setPixelColor(uint16_t n, uint32_t c), - setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b), - show(void), // Issue color data to strip - updatePins(void), // Change pin assignments (HW) - updatePins(uint8_t d, uint8_t c), // Change pin assignments (SW) - updateLength(uint16_t n); // Change length - uint32_t - Color(uint8_t r, uint8_t g, uint8_t b), // R,G,B to 32-bit color - getPixelColor(uint16_t n) const; // Return 32-bit pixel color - uint16_t - numPixels(void); // Return number of pixels - uint8_t - getBrightness(void) const, // Return global brightness - *getPixels(void) const, // Return pixel data pointer - sine8(uint8_t) const, - gamma8(uint8_t) const; - - private: - - uint16_t - numLEDs; // Number of pixels - uint8_t - dataPin, // If soft SPI, data pin # - clockPin, // If soft SPI, clock pin # - brightness, // Global brightness setting - *pixels, // LED RGB values (3 bytes ea.) - rOffset, // Index of red in 3-byte pixel - gOffset, // Index of green byte - bOffset; // Index of blue byte -#ifdef __AVR__ - uint8_t - dataPinMask, // If soft SPI, data pin bitmask - clockPinMask; // If soft SPI, clock pin bitmask - volatile uint8_t - *dataPort, // If soft SPI, data PORT - *clockPort; // If soft SPI, clock PORT -#endif - void - hw_spi_init(void), // Start hardware SPI - hw_spi_end(void), // Stop hardware SPI - sw_spi_init(void), // Start bitbang SPI - sw_spi_out(uint8_t n), // Bitbang SPI write - sw_spi_end(void); // Stop bitbang SPI - -}; - -#endif // _ADAFRUIT_DOT_STAR_H_ diff --git a/libraries/Nefry/Nefry.h b/libraries/Nefry/Nefry.h index d46ae821b91..c1cc29aab4b 100644 --- a/libraries/Nefry/Nefry.h +++ b/libraries/Nefry/Nefry.h @@ -11,14 +11,14 @@ class Nefry_lib setModuleClass(String className), setUser(String user), setUserPass(String pass), - setStoreValue(long value, const int pointer), - setStoreStr(String str, const int pointer), + setStoreValue(long value,const int pointer), + setStoreStr(String str,const int pointer), getWriteMode(), readSW(), getPollingSW(), getWifiEnabled(), getDisplayStatusEnabled(); - + String getModuleID(), getModuleClass(), @@ -30,8 +30,8 @@ class Nefry_lib getDefaultModuleId(), /* Console */ read(), - - getlistWifi(), + + getWiFiList(), createHtml(String title, String head, String body); long @@ -45,9 +45,9 @@ class Nefry_lib void reset(), sleep(const int sec), - setProgramName(const char * pn), + setProgramName(const char * pn), beginLed(const int num, const int dataOut, uint8_t t = 0, const int clk = -1), - setLed(const int r, const int g, const int b, const char w = 122, const int pin = 16, const int num = 0), + setLed(const int r, const int g, const int b, const char w = 80, const int pin = 16, const int num = 0), setLed(String _colorStr, const char w = 122, const int pin = 16, const int num = 0), addWiFi(String ssid, String pass), deleteWiFi(const int id), @@ -93,39 +93,41 @@ class Nefry_lib println(String text), setIndexLink(const char title[32], const char url[32]), - getDisplayInfo(), + printDeviceInfo(), - setNefryState(int state); + setNefryState(int state), + setLedBlink(int red, int green, int blue, bool EN, int wait), + LedBlinkTask(); - ESP32WebServer* getWebServer(); + ESP32WebServer* getWebServer(); - //下位互換 + //下位互換 - String getConfStr(const int num) { + String getConfStr(const int num){ return getStoreStr(num); } - void setConfHtmlStr(const char set[15], const int num) { - setStoreTitle(set, num); + void setConfHtmlStr(const char set[15], const int num){ + setStoreTitle(set,num); } - void setConfStr(const char *str, const int pt) { - setStoreStr(str, pt); + void setConfStr(const char *pt, const int num){ + setStoreStr(pt,num); } void setStoreTitleStr(const char set[15], const int pt) { setStoreTitle(set, pt); } - int getConfValue(const int num) { - return getStoreValue(num + 10); + int getConfValue(const int num){ + return getStoreValue(num+10); } - void setConfHtmlValue(const char set[15], const int num) { - setStoreTitle(set, num + 10); + void setConfHtmlValue(const char set[15], const int num){ + setStoreTitle(set,num+10); } - void setConfValue(const int pt, const int num) { - setStoreValue(num, pt + 10); + void setConfValue(const int pt, const int num){ + setStoreValue(num,pt+10); } void setStoreTitleValue(const char set[15], const int pt) { - setStoreTitle(set, pt + 10); + setStoreTitle(set, pt+10); } - String getModuleName() { + String getModuleName(){ return getModuleID(); } @@ -137,12 +139,15 @@ class Nefry_lib _swPushingflg = false, _wifiEnableFlg = true,/* Wi-Fiの有効無効化 */ _displayStatusFlg = true;/* ディスプレイの状態表示の有効無効化 */ + + bool setAnalyticsData(String action); - int + int _bootMode = -1, /* Boot状態を管理 -1:初期化中 0:起動中 1:通常起動 2:書き込みモード */ hextonum(char c), - _nefryState = 0; - + _nefryState = 0, + _nefryWifiWait; + int _nefryLedBlinkState[5]; const char * program; }; extern Nefry_lib Nefry; diff --git a/libraries/Nefry/examples/DefaultProgram/DefaultProgram.ino b/libraries/Nefry/examples/DefaultProgram/DefaultProgram.ino new file mode 100644 index 00000000000..6d3ff203b74 --- /dev/null +++ b/libraries/Nefry/examples/DefaultProgram/DefaultProgram.ino @@ -0,0 +1,39 @@ +#include +#include +#include + +String Event, SecretKey, LineAuth, SendMessageLINE; + +void setup() { + Nefry.setStoreTitle("SecretKey", 0); //Nefry DataStoreのタイトルを指定 + Nefry.setStoreTitle("Event", 1); //Nefry DataStoreのタイトルを指定 + Nefry.setStoreTitle("LINE Auth", 2); //Nefry DataStoreのタイトルを指定 + Nefry.setStoreTitle("LINEMessage", 3); //Nefry DataStoreのタイトルを指定 + + SecretKey = Nefry.getStoreStr(0); //Nefry DataStoreからデータを取得 + Event = Nefry.getStoreStr(1); //Nefry DataStoreからデータを取得 + LineAuth = Nefry.getStoreStr(2); //Nefry DataStoreからデータを取得 + SendMessageLINE = Nefry.getStoreStr(3); //Nefry DataStoreからデータを取得 + + Nefry.enableSW(); //スイッチ有効化 + Nefry.setProgramName("NefryBT Default Program");//プログラム名登録 +} + +void loop() { + if (Nefry.readSW()) { //スイッチを押した時 + if (!SecretKey.equals("") && !Event.equals("")) { + if (!IFTTT.send(Event, SecretKey)) {//IFTTTにデータを送信 + Nefry.setLed(255, 0, 0); //Errの時、赤色点灯 + } + } + if (!LineAuth.equals("")) { + if (SendMessageLINE.equals("")) + SendMessageLINE = "Welcome to the NefryBT world!"; + LineNotify.send(L + FeineAuth, SendMessageLINE); //LINE送信 + } + delay(1000); //送信後1秒間待つ + } + Nefry.setLed(random(255), random(255), random(255)); + delay(500); //送信後0.5秒間待つ +} \ No newline at end of file diff --git a/libraries/Nefry/examples/ReadSW/ReadSW.ino b/libraries/Nefry/examples/ReadSW/ReadSW.ino new file mode 100644 index 00000000000..5b43c565da1 --- /dev/null +++ b/libraries/Nefry/examples/ReadSW/ReadSW.ino @@ -0,0 +1,16 @@ +#include +void setup() { +} +void loop() { + //SWを押した時にLEDが赤色に点灯する + if(Nefry.readSW()){ + //押した時 + //赤色になる(r,g,b)の順で色を指定できる + Nefry.setLed(0,0,255); + Nefry.println("Push SW"); + }else{ + //離した時 + Nefry.setLed(255,0,0); + } + delay(100); +} diff --git a/libraries/Nefry/examples/Sleep/Sleep.ino b/libraries/Nefry/examples/Sleep/Sleep.ino new file mode 100644 index 00000000000..4eeac11f5f2 --- /dev/null +++ b/libraries/Nefry/examples/Sleep/Sleep.ino @@ -0,0 +1,12 @@ +#include +//Sleepモードの例 30秒したらスリープから復帰します。 +void setup() { +} +void loop() { + Nefry.println("Sleep!"); + Nefry.setLed(0, 0, 255);//青色に点灯します。 + delay(5000); + Nefry.setLed(0, 0, 0, 0); //消灯します。 + Nefry.sleep(30);//秒数で指定します。 +} + diff --git a/libraries/Nefry/examples/WiFiControl/WiFiControl.ino b/libraries/Nefry/examples/WiFiControl/WiFiControl.ino new file mode 100644 index 00000000000..3d3e9a9a130 --- /dev/null +++ b/libraries/Nefry/examples/WiFiControl/WiFiControl.ino @@ -0,0 +1,11 @@ +#include +void setup() { + Nefry.addWiFi("SSID", "Password"); //WiFiの保存をします。 + Nefry.println(Nefry.getWiFiList());//保存されているWiFiリストを表示します。 + Nefry.deleteWiFi(1);//保存されているWiFiリストを削除します。 + Nefry.println(Nefry.getWiFiList());//保存されているWiFiリストを表示します。 + Nefry.saveWiFi();//この関数で今までの変更を保存します +} + +void loop() { +} diff --git a/libraries/Nefry/keywords.txt b/libraries/Nefry/keywords.txt index b3e817802cc..6b3f96624f8 100644 --- a/libraries/Nefry/keywords.txt +++ b/libraries/Nefry/keywords.txt @@ -65,7 +65,7 @@ getProgramName KEYWORD2 getVersion KEYWORD2 getAddressStr KEYWORD2 setStoreTitle KEYWORD2 -getlistWiFi KEYWORD2 +getWiFiList KEYWORD2 createHtml KEYWORD2 setIndexLink KEYWORD2 getDisplayInfo KEYWORD2 diff --git a/libraries/Nefry/library.properties b/libraries/Nefry/library.properties index 97fea9a1d3f..e9bc12b307b 100644 --- a/libraries/Nefry/library.properties +++ b/libraries/Nefry/library.properties @@ -1,5 +1,5 @@ name=Nefry -version=1.2.1 +version=1.2.2 author=Nefry community maintainer= sentence=nefry. diff --git a/libraries/Nefry_AzureIoTHub/keywords.txt b/libraries/Nefry_AzureIoTHub/keywords.txt index aae46fc5f8c..9992f3dcf1e 100644 --- a/libraries/Nefry_AzureIoTHub/keywords.txt +++ b/libraries/Nefry_AzureIoTHub/keywords.txt @@ -9,6 +9,7 @@ NefryAzureIoTHub KEYWORD1 AzureIoTHub KEYWORD1 DataElement KEYWORD1 +Azure KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) diff --git a/libraries/Nefry_LINE_Notify/NefryLineNotify.cpp b/libraries/Nefry_LINE_Notify/NefryLineNotify.cpp new file mode 100644 index 00000000000..9077f29129a --- /dev/null +++ b/libraries/Nefry_LINE_Notify/NefryLineNotify.cpp @@ -0,0 +1,109 @@ +/** +Nefry IFTTT lib + +Copyright (c) 2015 wami + +This software is released under the MIT License. +http://opensource.org/licenses/mit-license.php +*/ + +#include "NefryLineNotify.h" + +bool Nefry_LINE_Notify::send(String auth,String message) +{ + WiFiClientSecure client; + if (client.connect("notify-api.line.me", 443)) { + String url = "/api/notify"; + url += "?message="; + url += StrPerEncord(escapeParameter(message).c_str()); + + client.print(String("POST ") + url + " HTTP/1.1\r\n" + + "Authorization: Bearer " + auth + "\r\n" + + "Content-Type: application/x-www-form-urlencoded\r\n" + + "Host: notify-api.line.me\r\n" + + "Connection: close\r\n\r\n"); + client.println(); + + unsigned long timeout = millis(); + while (client.available() == 0) { + if (millis() - timeout > 5000) { + Serial.println(">>> Client Timeout !"); + client.stop(); + return false; + } + } + // Read all the lines of the reply from server and print them to Serial + while (client.available()) { + String line = client.readStringUntil('\r'); + Serial.print(line); + } + Serial.println(); + Serial.println("closing connection"); + delay(10); + return true; + } + return false; +} + +//********************UTF-8文字列をパーセントエンコード************************* +String Nefry_LINE_Notify::StrPerEncord(const char* c_str) { + uint16_t i = 0; + String str_ret = ""; + char c1[3], c2[3], c3[3]; + + while (c_str[i] != '\0') { + if (c_str[i] >= 0xC2 && c_str[i] <= 0xD1) { //2バイト文字 + sprintf(c1, "%2x", c_str[i]); + sprintf(c2, "%2x", c_str[i + 1]); + str_ret += "%" + String(c1) + "%" + String(c2); + i = i + 2; + } + else if (c_str[i] >= 0xE2 && c_str[i] <= 0xEF) { + sprintf(c1, "%2x", c_str[i]); + sprintf(c2, "%2x", c_str[i + 1]); + sprintf(c3, "%2x", c_str[i + 2]); + str_ret += "%" + String(c1) + "%" + String(c2) + "%" + String(c3); + i = i + 3; + } + else { + str_ret += String(c_str[i]); + i++; + } + } + return str_ret; +} + +String Nefry_LINE_Notify::escapeParameter(String param) { + param.replace("%", "%25"); + param.replace("+", "%2B"); + param.replace(" ", "+"); + param.replace("\"", "%22"); + param.replace("#", "%23"); + param.replace("$", "%24"); + param.replace("&", "%26"); + param.replace("'", "%27"); + param.replace("(", "%28"); + param.replace(")", "%29"); + param.replace("*", "%2A"); + param.replace(",", "%2C"); + param.replace("/", "%2F"); + param.replace(":", "%3A"); + param.replace(";", "%3B"); + param.replace("<", "%3C"); + param.replace("=", "%3D"); + param.replace(">", "%3E"); + param.replace("?", "%3F"); + param.replace("@", "%40"); + param.replace("[", "%5B"); + param.replace("\\", "%5C"); + param.replace("]", "%5D"); + param.replace("^", "%5E"); + param.replace("'", "%60"); + param.replace("{", "%7B"); + param.replace("|", "%7C"); + param.replace("}", "%7D"); + return param; +} + + +Nefry_LINE_Notify LineNotify; diff --git a/libraries/Nefry_LINE_Notify/NefryLineNotify.h b/libraries/Nefry_LINE_Notify/NefryLineNotify.h new file mode 100644 index 00000000000..7ffb1879c84 --- /dev/null +++ b/libraries/Nefry_LINE_Notify/NefryLineNotify.h @@ -0,0 +1,18 @@ +#ifndef NefryLINENotify_h +#define NefryLINENotify_h + +#include +#include + +class Nefry_LINE_Notify +{ +public: + bool + send(String auth, String message); +private: + String + escapeParameter(String param), + StrPerEncord(const char* c_str); +}; +extern Nefry_LINE_Notify LineNotify; +#endif \ No newline at end of file diff --git a/libraries/Nefry_LINE_Notify/examples/LineNotify/LineNotify.ino b/libraries/Nefry_LINE_Notify/examples/LineNotify/LineNotify.ino new file mode 100644 index 00000000000..67d50246eaf --- /dev/null +++ b/libraries/Nefry_LINE_Notify/examples/LineNotify/LineNotify.ino @@ -0,0 +1,20 @@ +#include +#include +String auth, message; + +void setup() { + Nefry.setStoreTitle("Auth",0); //Nefry DataStoreのタイトルを指定 + Nefry.setStoreTitle("Message",1); //Nefry DataStoreのタイトルを指定 + auth = Nefry.getStoreStr(0); //Nefry DataStoreからデータを取得 + message = Nefry.getStoreStr(1); //Nefry DataStoreからデータを取得 + Nefry.enableSW(); //SW有効化 +} + +void loop() { + if (Nefry.readSW()) { //SWを押した時 + if (!LineNotify.send(auth, message)) {//IFTTTにデータを送信 + Nefry.setLed(255, 0, 0); //Errの時、赤色点灯 + } + Nefry.ndelay(1000); //送信後1秒間待つ + } +} diff --git a/libraries/Nefry_LINE_Notify/keywords.txt b/libraries/Nefry_LINE_Notify/keywords.txt new file mode 100644 index 00000000000..362e1241441 --- /dev/null +++ b/libraries/Nefry_LINE_Notify/keywords.txt @@ -0,0 +1,18 @@ +####################################### +# Syntax Coloring Map For nefry +####################################### +# Class +####################################### + +NefryLineNotify KEYWORD1 +LineNotify KEYWORD1 +####################################### +# Methods and Functions +####################################### + +send KEYWORD2 + +####################################### +# Constants +####################################### + diff --git a/libraries/Nefry_LINE_Notify/library.properties b/libraries/Nefry_LINE_Notify/library.properties new file mode 100644 index 00000000000..ee614e916e3 --- /dev/null +++ b/libraries/Nefry_LINE_Notify/library.properties @@ -0,0 +1,10 @@ +name=Nefry LINE Notify +version=1.0.0 +author=Nefry community +maintainer= +sentence=nefry. +paragraph=nefry. +category=Communication +url= +architectures=esp32 +includes=NefryLineNotify.h diff --git a/libraries/TutorialBookExample b/libraries/TutorialBookExample index 60a5540e2e2..2a317d9ffc6 160000 --- a/libraries/TutorialBookExample +++ b/libraries/TutorialBookExample @@ -1 +1 @@ -Subproject commit 60a5540e2e2a9a7780a5b08bd74e9659d4dd4d6f +Subproject commit 2a317d9ffc62f974454d4311682f4e4499e3f1be diff --git a/release note.md b/release note.md index 60a81888812..9ff3491511b 100644 --- a/release note.md +++ b/release note.md @@ -1,5 +1,22 @@ # このノートはNefry(ESP32版)のリリースノートになります。 +## 1.2.2 + +NefryBTr3の仕様変更に対応しました。 +MDNS対応やサンプルコードの追加を行いました。 + +新規機能 + +- LINE Notifyライブラリを追加しました。 +- MDNS対応しました。(http://nefrybt.local)で接続できます。 +- サンプルコードの追加を行いました。 + +バグ修正 + +- Nefry BT r3の仕様変更に伴いライブラリの修正を行いました。 +- Azureライブラリの更新を行いました。 +- チュートリアル本のサンプルコードを更新しました。 + ## 1.2.1 NefryBTr3に対応しました。それに伴い多数のバグ、新規機能が追加されました。 diff --git a/variants/nefrybt-r2/pins_arduino.h b/variants/nefrybt-r2/pins_arduino.h index 4b6d2bdb7cf..d5d432b6f6e 100644 --- a/variants/nefrybt-r2/pins_arduino.h +++ b/variants/nefrybt-r2/pins_arduino.h @@ -53,6 +53,6 @@ static const uint8_t DAC2 = 26; static const uint8_t LED_CLK = -1; static const uint8_t LED_DO = 16; -static const uint8_t boardId = 2;//Nefry BT R2 +static const uint8_t boardId = 2;//Nefry BT R2/R3 #endif /* Pins_Arduino_h */ diff --git a/variants/nefrybt-r3/pins_arduino.h b/variants/nefrybt-r3/pins_arduino.h deleted file mode 100644 index 369e197366f..00000000000 --- a/variants/nefrybt-r3/pins_arduino.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef Pins_Arduino_h -#define Pins_Arduino_h - -#include - -#define EXTERNAL_NUM_INTERRUPTS 16 -#define NUM_DIGITAL_PINS 40 -#define NUM_ANALOG_INPUTS 16 - -#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1) -#define digitalPinToInterrupt(p) (((p)<40)?(p):-1) -#define digitalPinHasPWM(p) (p < 34) - -static const uint8_t TX = 1; -static const uint8_t RX = 3; - -static const uint8_t SDA = 21; -static const uint8_t SCL = 22; - -//Display -static const uint8_t SDA2 = 17; -static const uint8_t SCL2 = 5; - -static const uint8_t SS = 25; -static const uint8_t MOSI = 23; -static const uint8_t MISO = 19; -static const uint8_t SCK = 18; - -static const uint8_t D0 = 22; -static const uint8_t D1 = 21; -static const uint8_t D2 = 23; -static const uint8_t D3 = 18; -static const uint8_t D4 = 19; -static const uint8_t D5 = 25; -static const uint8_t D6 = 26; -static const uint8_t D7 = 13; -static const uint8_t D8 = 14; - -static const uint8_t A0 = 33; -static const uint8_t A1 = 32; -static const uint8_t A2 = 39; -static const uint8_t A3 = 36; - -static const uint8_t T0 = 13; -static const uint8_t T1 = 14; -static const uint8_t T2 = 33; -static const uint8_t T3 = 32; - -static const uint8_t DAC1 = 25; -static const uint8_t DAC2 = 26; - -static const uint8_t LED_CLK = 27; -static const uint8_t LED_DO = 12; - -static const uint8_t boardId = 3;//Nefry BT R3 - -#endif /* Pins_Arduino_h */