Skip to content

1.2 develop #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ tools/xtensa-esp32-elf
tools/dist
tools/esptool
tools/esptool.exe
.vs/
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
url = https://github.com/wamisnet/ConfigurableFirmata.git
[submodule "libraries/Nefry_ThingSpeak/src/include"]
path = libraries/Nefry_ThingSpeak/src/include
url=https://github.com/wamisnet/thingspeak-arduino.git
url=https://github.com/wamisnet/thingspeak-arduino.git
[submodule "libraries/TutorialBookExample"]
path = libraries/TutorialBookExample
url = https://github.com/Nefry-Community/TutorialExample.git
52 changes: 52 additions & 0 deletions boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,58 @@ 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.upload.tool=esptool
Expand Down
139 changes: 124 additions & 15 deletions cores/esp32/nefry/Nefry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,24 @@ BootMode
1 : WriteMode切替をする
*/

#define LIBVERSION ("1.2.0")
#define LIBVERSION ("1.2.1")
#include "Nefry.h"

Adafruit_NeoPixel _NefryLED[40];

Adafruit_NeoPixel _NefryLEDNeo;
Adafruit_DotStar _NefryLEDStar;
bool connectAnFlg = false;
//main

void Nefry_lib::nefry_init() {
/* Display設定 */
connectAnFlg = false;
delay(10);
NefryDisplay.begin();//logo表示
beginLed((const int)1, (const int)16, (uint8_t)NEO_GRBW);
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);
}
setLedBlink(0, 0, 0, false, 0);
setLed(0x00, 0x0f, 0x00);
enableSW();
Expand Down Expand Up @@ -92,6 +98,9 @@ void Nefry_lib::nefry_loop() {
if (_nefryWifiWait > 1000) {//WiFiに接続する間隔を10秒ごとに修正
_nefryWifiWait = 0;
NefryWiFi.run();
if (connectAnFlg != true) {
connectAnFlg = setAnalyticsData("connect");
}
}
}
}
Expand Down Expand Up @@ -289,18 +298,34 @@ bool Nefry_lib::getPollingSW()
}

//LED
void Nefry_lib::beginLed(const int num, const int pin, uint8_t t = NEO_GRB) {
_NefryLED[pin] = Adafruit_NeoPixel(num, pin, t);
_NefryLED[pin].begin();
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::setLed(const int r, const int g, const int b, const char w, const int pin, const int num) {
_NefryLED[pin].setPixelColor(num,0, 0, 0);
delay(1);
_NefryLED[pin].show();
_NefryLED[pin].setBrightness(w);
_NefryLED[pin].setPixelColor(num, map(r,0,255,0,150), g, b);
delay(1);
_NefryLED[pin].show();
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();
}
}
void Nefry_lib::setLed(String _colorStr, const char w, const int pin, const int num) {
int _color[3];
Expand Down Expand Up @@ -343,7 +368,10 @@ String Nefry_lib::getDefaultModuleId() {
String _devstr,ms;
switch (boardId)
{
case 0:case 1:
case 0:
case 1:
case 2:
case 3:
moduleName = "NefryBT";
break;
}
Expand Down Expand Up @@ -439,4 +467,85 @@ bool Nefry_lib::getDisplayStatusEnabled() {
return _displayStatusFlg;
}

bool Nefry_lib::setAnalyticsData(String action) {
bool state = false;
if (WiFi.status() == WL_CONNECTED) {
WiFiClient client;
const int httpPort = 80;
if (!client.connect("google-analytics.com", httpPort)) {
//Serial.println("connection failed");
return state;
}

// We now create a URI for the request
String url = "/collect?v=1&t=event&tid=UA-78080011-2&cid=NefryBT&ec=";
url += "NefryBT";
switch (boardId) {
case 1:
url += "r1";
break;
case 2:
url += "r2";
break;
case 3:
url += "r3";
break;
default:
url += "error";
break;
}
url += "&el=v";
url += getVersion();
url += "&ea=";
url += action;
url += "&ds=";

String _devstr;
_devstr = WiFi.macAddress();
_devstr.replace(":", "");
url += (String)"NefryBT-" + _devstr.substring(8);
//Serial.print("Requesting URL: ");
//Serial.println(url);

// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: google-analytics.com\r\n" +
"Connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
//Serial.println(">>> Client Timeout !");
client.stop();
return state;
}
}

// Read all the lines of the reply from server and print them to Serial
while (client.available()) {
size_t len = client.available();
if (len > 0) {
String headerLine = client.readStringUntil('\n');
headerLine.trim(); // remove \r
//Serial.print(headerLine);
log_d("[HTTP-Client][handleHeaderResponse] RX: '%s'", headerLine.c_str());

if (headerLine.startsWith("HTTP/1.")) {
int _returnCode = headerLine.substring(9, headerLine.indexOf(' ', 9)).toInt();
//Serial.printf("[HTTP] GET... code: %d\n", _returnCode);
if (_returnCode == 200) {
state = true;
break;
}
else {
state = false;
break;
}
}
}
}
client.stop();
}
return state;
}

Nefry_lib Nefry;
9 changes: 7 additions & 2 deletions cores/esp32/nefry/Nefry.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define Nefry_h

#include <Esp.h>
#include "./inc/led/Adafruit_DotStar.h"
#include "./inc/led/Adafruit_NeoPixel.h"
#include "./inc/Preferences/src/Preferences.h"
#include "NefryWiFi.h"
Expand All @@ -11,6 +12,8 @@
#include "NefryDisplay.h"
#include "NefryWeb.h"
#include "NefryWebServer.h"
#include "./inc/WiFi/src/WiFiClient.h"


// Offset: W R G B
#define NEO_RGB ((0 << 6) | (0 << 4) | (1 << 2) | (2))
Expand Down Expand Up @@ -65,8 +68,8 @@ class Nefry_lib
void
reset(),
sleep(const int sec),
setProgramName(const char * pn),
beginLed(const int num, const int pin, uint8_t t),
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 = 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),
Expand Down Expand Up @@ -159,6 +162,8 @@ class Nefry_lib
_swPushingflg = false,
_wifiEnableFlg = true,/* Wi-Fiの有効無効化 */
_displayStatusFlg = true;/* ディスプレイの状態表示の有効無効化 */

bool setAnalyticsData(String action);

int
_bootMode = -1, /* Boot状態を管理 -1:初期化中 0:起動中 1:通常起動 2:書き込みモード */
Expand Down
8 changes: 6 additions & 2 deletions cores/esp32/nefry/NefryDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

SSD1306 _nefrySsdDisplay(0x3c, SDA2, SCL2);
String _nefryPrintDisplay1 = "", _nefryPrintDisplay2 = "", _nefryPrintDisplay3 = "";

String _dialogTitle = "Nefry PrintDialog";
/* 初期化 */
bool Nefry_Display::begin()
{
Expand All @@ -19,9 +19,13 @@ bool Nefry_Display::begin()
return true;
}

void Nefry_Display::setTitle(String title) {
_dialogTitle = title;
}

void setPrintDialogDisplay() {
NefryDisplay.setFont(Arimo_12);
NefryDisplay.drawString(15, 0,"Nefry PrintDialog");
NefryDisplay.drawString(15, 0, _dialogTitle);
NefryDisplay.drawStringWithHScroll(0, 20, _nefryPrintDisplay1,10);
NefryDisplay.drawStringWithHScroll(0, 35, _nefryPrintDisplay2, 10);
NefryDisplay.drawStringWithHScroll(0, 50, _nefryPrintDisplay3, 10);
Expand Down
2 changes: 2 additions & 0 deletions cores/esp32/nefry/NefryDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class Nefry_Display

void autoScrollTask ();

void setTitle(String title);

private:
GeneralFunction _func = NULL;
uint16_t _scrollTextCount = 0;
Expand Down
36 changes: 36 additions & 0 deletions cores/esp32/nefry/inc/SPI/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#######################################
# Syntax Coloring Map SPI
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

SPI KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################
begin KEYWORD2
end KEYWORD2
transfer KEYWORD2
setBitOrder KEYWORD2
setDataMode KEYWORD2
setClockDivider KEYWORD2


#######################################
# Constants (LITERAL1)
#######################################
SPI_CLOCK_DIV4 LITERAL1
SPI_CLOCK_DIV16 LITERAL1
SPI_CLOCK_DIV64 LITERAL1
SPI_CLOCK_DIV128 LITERAL1
SPI_CLOCK_DIV2 LITERAL1
SPI_CLOCK_DIV8 LITERAL1
SPI_CLOCK_DIV32 LITERAL1
SPI_CLOCK_DIV64 LITERAL1
SPI_MODE0 LITERAL1
SPI_MODE1 LITERAL1
SPI_MODE2 LITERAL1
SPI_MODE3 LITERAL1
9 changes: 9 additions & 0 deletions cores/esp32/nefry/inc/SPI/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=SPI
version=1.0
author=Hristo Gochkov
maintainer=Hristo Gochkov <hristo@espressif.com>
sentence=Enables the communication with devices that use the Serial Peripheral Interface (SPI) Bus. For all Arduino boards, BUT Arduino DUE.
paragraph=
category=Signal Input/Output
url=http://arduino.cc/en/Reference/SPI
architectures=esp32
Loading