forgot to commit everything...

This commit is contained in:
2018-02-03 16:55:37 +01:00
parent 20d46af1fb
commit 3da4722748
15 changed files with 991 additions and 0 deletions

2
Buzzer.config Executable file
View File

@@ -0,0 +1,2 @@
// Add predefined macros for your project here. For example:
// #define THE_ANSWER 42

1
Buzzer.creator Executable file
View File

@@ -0,0 +1 @@
[General]

19
Buzzer.files Executable file
View File

@@ -0,0 +1,19 @@
user/FadeOnce.h
user/RainbowBeat.h
user/Rainbow.h
user/user_config.h
user/user_main.c
user/user_main.cpp
user/run_Buzzer.h
user/ESP8266lib/Debug.h
user/ESP8266lib/c++.h
user/ESP8266lib/ext/led/WS2812B.h
user/ESP8266lib/net/IP.h
user/ESP8266lib/net/MAC.h
user/ESP8266lib/net/UDP.h
user/ESP8266lib/io/fastGPIO.h
user/Fader.h
user/Buzzer.h
user/ADC.h

10
Buzzer.includes Executable file
View File

@@ -0,0 +1,10 @@
user
.
user/audio
user/data
user/net
user/rssi
user/com
user/io
../../MilesTag/src
user/rfid

157
Makefile Executable file
View File

@@ -0,0 +1,157 @@
# Makefile based on https://github.com/esp8266/source-code-examples/blob/master/example.Makefile
# C++ adjustment: https://gist.github.com/jcmvbkbc/795b51494aea52bf2d1e
# adjust the PATH variable [needed e.g. for esptool.py
export PATH := /apps/esp/esp-open-sdk/xtensa-lx106-elf/bin:$(PATH)
ROOT = /apps/esp/esp-open-sdk/sdk
BUILD_BASE = build
FW_BASE = firmware
# base directory for the compiler
XTENSA_TOOLS_ROOT ?= /apps/esp/esp-open-sdk/xtensa-lx106-elf/bin
# base directory of the ESP8266 SDK package, absolute
SDK_BASE ?= /apps/esp/esp-open-sdk/sdk
# esptool.py path and port
ESPTOOL ?= esptool.py
ESPPORT ?= /dev/ttyUSB3
# name for the target project
TARGET = app
# which modules (subdirectories) of the project to include in compiling
MODULES = driver user
EXTRA_INCDIR = include $(ROOT)/include/ $(ROOT)/driver_lib/include/ ../../MilesTag/src
# libraries used in this project, mainly provided by the SDK
#LIBS = c gcc hal pp phy net80211 lwip wpa wpa2 crypto main
#LIBS = c gcc pp phy net80211 lwip wpa main
LIBS = c gcc hal phy pp net80211 lwip wpa main wps crypto
# compiler flags using during compilation of source files
#CFLAGS = -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH
CFLAGS = -Os -Wpointer-arith -Wall -Wextra -Wundef -Werror=return-type -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH
CXXFLAGS = $(CFLAGS) -fno-rtti -fno-exceptions -std=c++11
# linker flags used to generate the main object file
LDFLAGS = -nostdlib -Wl,--no-check-sections -Wl,--gc-sections -u call_user_start -Wl,-static
# linker script used for the above linkier step
#LD_SCRIPT = eagle.app.v6.ld
LD_SCRIPT = eagle.app.v6.modified.ld
#http://www.esp8266.com/viewtopic.php?f=9&t=478&start=8
# various paths from the SDK used in this project
SDK_LIBDIR = lib
SDK_LDDIR = ld
SDK_INCDIR = include include/json examples/driver_lib/include/driver
# we create two different files for uploading into the flash
# these are the names and options to generate them
FW_FILE_1_ADDR := 0x00000
FW_FILE_2_ADDR := 0x10000
# select which tools to use as compiler, librarian and linker
CC := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc
CXX := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-g++
AR := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-ar
LD := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc
####
#### no user configurable options below here
####
SRC_DIR := $(MODULES)
BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES))
SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR))
SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR))
SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c*))
C_OBJ := $(patsubst %.c,%.o,$(SRC))
CXX_OBJ := $(patsubst %.cpp,%.o,$(C_OBJ))
OBJ := $(patsubst %.o,$(BUILD_BASE)/%.o,$(CXX_OBJ))
LIBS := $(addprefix -l,$(LIBS))
APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a)
TARGET_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).out)
LD_SCRIPT := $(addprefix -T$(SDK_BASE)/$(SDK_LDDIR)/,$(LD_SCRIPT))
INCDIR := $(addprefix -I,$(SRC_DIR))
EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR))
MODULE_INCDIR := $(addsuffix /include,$(INCDIR))
FW_FILE_1 := $(addprefix $(FW_BASE)/,$(FW_FILE_1_ADDR).bin)
FW_FILE_2 := $(addprefix $(FW_BASE)/,$(FW_FILE_2_ADDR).bin)
V ?= $(VERBOSE)
ifeq ("$(V)","1")
Q :=
vecho := @true
else
Q := @
vecho := @echo
endif
vpath %.c $(SRC_DIR)
vpath %.cpp $(SRC_DIR)
define compile-objects
$1/%.o: %.c
$(vecho) "CC $$<"
$(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@
$1/%.o: $(wildcard **/*.cpp)
$(vecho) "C+ $$<"
$(Q) $(CXX) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CXXFLAGS) -c $$< -o $$@
endef
.PHONY: all checkdirs flash clean
all: checkdirs $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2)
$(FW_BASE)/%.bin: $(TARGET_OUT) | $(FW_BASE)
$(vecho) "FW $(FW_BASE)/"
$(Q) $(ESPTOOL) elf2image -o $(FW_BASE)/ $(TARGET_OUT)
$(Q) echo ""
$(Q) echo "final firmware:"
$(Q) ls -l firmware/*.bin
$(Q) xtensa-lx106-elf-size --format=sysv $(TARGET_OUT)
$(TARGET_OUT): $(APP_AR)
$(vecho) "LD $@"
$(Q) $(LD) -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $@
$(APP_AR): $(OBJ)
$(vecho) "AR $@"
$(Q) $(AR) cru $@ $^
$(Q) echo ""
$(Q) echo "custom code size:"
$(Q) ls -l build/app_app.a
checkdirs: $(BUILD_DIR) $(FW_BASE)
$(BUILD_DIR):
$(Q) mkdir -p $@
$(FW_BASE):
$(Q) mkdir -p $@
flash: $(FW_FILE_1) $(FW_FILE_2)
$(ESPTOOL) --port $(ESPPORT) write_flash $(FW_FILE_1_ADDR) $(FW_FILE_1) $(FW_FILE_2_ADDR) $(FW_FILE_2)
clean:
$(Q) rm -rf $(FW_BASE) $(BUILD_BASE)
# note: each new ESP2866 has to be initialized once!
# the memory addresses for those files, depend on the flash size
# below it is configured for 32mbit flash [4096kb]
# see: https://espressif.com/en/support/explore/get-started/esp8266/getting-started-guidek
init:
$(ESPTOOL) --port $(ESPPORT) write_flash 0x3FC000 $(ROOT)/bin/esp_init_data_default.bin 0x3FE000 $(ROOT)/bin/blank.bin
$(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir))))

21
user/ADC.h Executable file
View File

@@ -0,0 +1,21 @@
#ifndef ADC_H
#define ADC_H
class ADC {
public:
static uint16_t getA0() {
return 0xffff & system_adc_read();
}
static uint16_t getVcc() {
static constexpr float SCALER = 1.93; // divider of 10k / 10k -> * 2
static constexpr int V_REF = 330; // 3.3 volt
static constexpr int MUL = SCALER * V_REF;
return getA0() * MUL / 1024;
}
};
#endif // ADC_H

320
user/Buzzer.h Executable file
View File

@@ -0,0 +1,320 @@
#ifndef BUZZER_H
#define BUZZER_H
#include "ESP8266lib/net/UDP.h"
#include "ESP8266lib/net/IP.h"
#include "ESP8266lib/net/MAC.h"
#include "ESP8266lib/net/WiFiRaw.h"
#include "ESP8266lib/io/IO.h"
#include "Fader.h"
#include "FadeOnce.h"
#include "Rainbow.h"
#include "RainbowBeat.h"
#define FIRMWARE_NR 5
#define CODE(a, b, c, d) (a << 24 | b << 16 | c << 8 | d)
enum LEDMode {
OFF,
FIXED_COLOR,
RAINBOW_COLOR,
FADE_BETWEEN_COLOR,
FADE_ONCE,
STROBO_COLOR,
RAINBOW_BEAT,
};
class Buzzer;
extern Buzzer buzzer;
class Buzzer {
private:
static constexpr const char* NAME = "Buzzer";
UDP udp;
IP server = IP();
WS2812B<1> leds;
LEDMode ledMode;
WiFiRaw::MACAddress myMac;
FadeBetween fadeBetween;
FadeOnce fadeOnce;
Rainbow rainbow;
RainbowBeat rainbowBeat;
public:
/** ctor */
Buzzer() {
debugMod(NAME, "ctor()");
udp.bind(localPort);
udp.setRecvCallback(&Buzzer::onUDP);
ledMode = LEDMode::FIXED_COLOR;
myMac = WiFiRaw::getMyMAC();
// buzzer interrupt (Pin D2)
GPIO4_INPUT_SET;
GPIO4_INPUT_PULLUP_SET;
// interrupt
//ETS_GPIO_INTR_DISABLE();
//ETS_GPIO_INTR_ATTACH(isrRoutine, this);
//gpio_pin_intr_state_set(GPIO_ID_PIN(4), GPIO_PIN_INTR_ANYEDGE);
//ETS_GPIO_INTR_ENABLE();
}
/** send a heartbeat packet */
void sendHeartbeat() {
const uint16_t vcc = ADC::getVcc();
os_printf("send: heartbeat, Vcc: %d\n", vcc);
char data[5+12+2+3];
os_memcpy(&data[0], "*PING", 5);
os_memcpy(&data[5], myMac.asPtr(), 12);
data[17] = '_';
data[18] = FIRMWARE_NR;
data[19] = '_';
data[20] = (vcc >> 8) & 0xFF;
data[21] = (vcc >> 0) & 0xFF;
udp.send(remoteIP, remotePort, data, sizeof(data));
}
/** send a buzzer packet */
void sendBuzzer() {
char data[5+12];
os_memcpy(&data[0], "*BUZZ", 5);
os_memcpy(&data[5], myMac.asPtr(), 12);
udp.send(remoteIP, remotePort, data, 5+12);
os_printf("send: buzzer\n");
}
/** incoming UDP data */
void onUDP(const char* data, uint16_t len) {
if (len < 2) {return;}
if (data[0] == '*') {
debugMod(NAME, "got command");
checkCode(&data[1]);
}
}
void update() {
static int cnt = 0; ++cnt;
// every 9 seconds
if (cnt % 9000 == 0) {
buzzer.sendHeartbeat();
}
// every 20 milliseconds
if (cnt % 20 == 0) {
updateLED();
}
// block the buzzer for some time after buzzering
static int block = 0;
if (block > 0) {
--block;
if (block == 0) {onUnBuzzer();}
}
// check buzzer-state
if (cnt % 20 == 0) {
// buzzer currently blocked
if (block > 0) {return;}
static uint8_t lastVal = 1;
const uint8_t curVal = GPIO4_IN;
if (curVal < lastVal) {
block = 1000;
onBuzzer();
}
lastVal = curVal;
}
}
// buzzer button pressed
void onBuzzer() {
sendBuzzer();
internalLED(true);
//setOff();
}
void onUnBuzzer() {
internalLED(false);
//os_printf("free\n");
//setRainbow();
//setFade(255,0,0, 0,0,255);
//setFade(180,0,16, 16,190,16);
}
/** wemos D1 mini only */
void internalLED(bool on) {
GPIO2_OUTPUT_SET;
if (on) { // LED is inverted
GPIO2_L;
} else {
GPIO2_H;
}
}
private:
/** check the command-code behind the given char-string */
void checkCode(const char* buf) {
// convert the buffer's first 4 bytes to a uint32_t for faster comparison
const uint32_t code = CODE(buf[0], buf[1], buf[2], buf[3]);
switch(code) {
case CODE('S', 'T', 'R', 'O'): setStrobo(buf[4], buf[5], buf[6]); break;
case CODE('O', 'F', 'F', ' '): setOff(); break;
case CODE('S', 'R', 'G', 'B'): setRGB(buf[4], buf[5], buf[6]); break;
case CODE('R', 'A', 'I', 'N'): setRainbow(); break;
case CODE('F', 'A', 'D', 'E'): setFade(buf[4], buf[5], buf[6], buf[7], buf[8], buf[9]); break;
case CODE('F', 'L', 'S', 'H'): setFlash(buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10]); break;
case CODE('R', 'A', 'I', 'R'): setRainbowBeatRestart(); break;
case CODE('R', 'A', 'I', 'B'): setRainbowBeatBeat(buf[4]); break;
case CODE('R', 'A', 'I', 'S'): setRainbowBeatShift(buf[4]); break;
default: break;
}
}
/** upadte the current LED output (for animations) */
void updateLED() {
// fading LED color?
if (ledMode == LEDMode::RAINBOW_COLOR) {
rainbow.update();
leds.setColor(0, rainbow.getCurrent());
leds.flush();
} else if (ledMode == LEDMode::STROBO_COLOR) {
leds.setEnabled(0, !leds.isEnabled(0));
leds.flush();
} else if (ledMode == LEDMode::FADE_BETWEEN_COLOR) {
fadeBetween.update();
leds.setColor(0, fadeBetween.getCurrent());
leds.flush();
} else if (ledMode == LEDMode::FADE_ONCE) {
fadeOnce.update();
leds.setColor(0, fadeOnce.getCurrent());
leds.flush();
} else if (ledMode == LEDMode::RAINBOW_BEAT) {
rainbowBeat.update();
leds.setColor(0, rainbowBeat.getCurrent());
leds.flush();
}
}
public:
/** disable LED */
void setOff() {
ledMode = LEDMode::OFF;
leds.getColor(0).setRGB(0,0,255); // for testing
leds.setEnabled(0, false);
leds.flush();
}
/** set a fixed RGB color */
void setRGB(const uint8_t r, const uint8_t g, const uint8_t b) {
debugMod(NAME, "setting LEDS to fixed RGB color");
ledMode = LEDMode::FIXED_COLOR;
leds.getColor(0).setRGB(r,g,b);
leds.setEnabled(0, true);
leds.flush();
}
/** set strobo mode */
void setStrobo(const uint8_t r, const uint8_t g, const uint8_t b) {
ledMode = LEDMode::STROBO_COLOR;
leds.getColor(0).setRGB(r,g,b);
leds.setEnabled(0, true);
leds.flush();
}
/** set LED rainbow fading */
void setRainbow() {
rainbow.restart();
ledMode = LEDMode::RAINBOW_COLOR;
leds.setEnabled(0, true);
leds.flush();
}
/** set LED fading between two colors */
void setFade(const uint8_t r1, const uint8_t g1, const uint8_t b1, const uint8_t r2, const uint8_t g2, const uint8_t b2) {
fadeBetween.setColor1(Color::fromRGB(r1, g1, b1));
fadeBetween.setColor2(Color::fromRGB(r2, g2, b2));
fadeBetween.restart();
ledMode = LEDMode::FADE_BETWEEN_COLOR;
leds.setEnabled(0, true);
}
/** shortly flash the led and fade back to black */
void setFlash(const uint8_t r1, const uint8_t g1, const uint8_t b1, const uint8_t r2, const uint8_t g2, const uint8_t b2, const int ms) {
fadeOnce.setColor(Color::fromRGB(r1,g1,b1), Color::fromRGB(r2,g2,b2));
fadeOnce.setFadeDuration(ms);
ledMode = LEDMode::FADE_ONCE;
leds.setEnabled(0, true);
}
/** reset the rainbow-beats HUE to 0 */
void setRainbowBeatRestart() {
rainbowBeat.restart();
ledMode = LEDMode::RAINBOW_BEAT;
leds.setEnabled(0, true);
}
/** show a beat */
void setRainbowBeatBeat(const int ms) {
rainbowBeat.flash(ms);
ledMode = LEDMode::RAINBOW_BEAT;
leds.setEnabled(0, true);
}
/** show a beat */
void setRainbowBeatShift(const int increment) {
rainbowBeat.shift(increment);
ledMode = LEDMode::RAINBOW_BEAT;
leds.setEnabled(0, true);
}
public:
/** udp callback */
static void onUDP(void*, char* data, unsigned short len) {
debugMod(NAME, "got udp data");
buzzer.onUDP(data, len);
}
};
#endif // BUZZER_H

16
user/ESP.h Executable file
View File

@@ -0,0 +1,16 @@
#ifndef ESP_H
#define ESP_H
class ESP {
public:
static inline uint32_t getCycleCount() {
uint32_t ccount;
__asm__ __volatile__("esync; rsr %0,ccount":"=a" (ccount));
return ccount;
}
};
#endif // ESP_H

44
user/FadeOnce.h Executable file
View File

@@ -0,0 +1,44 @@
#ifndef FLASHONCE_H
#define FLASHONCE_H
#include "ESP8266lib/ext/led/WS2812B.h"
/** fade between two colors */
class FadeOnce {
Color c1;
Color c2;
int fadeOut_ticks = 0;
int ticksLeft = 0;
public:
/** ctor */
FadeOnce() {
;
}
void setColor(Color c1, Color c2) {
this->c1 = c1;
this->c2 = c2;
}
void setFadeDuration(int duration_ticks) {
this->fadeOut_ticks = duration_ticks;
this->ticksLeft = duration_ticks;
}
void update() {
if (ticksLeft > 0) {--ticksLeft;} // fade-out
}
Color getCurrent() const {
const int percent = (ticksLeft * 100 / fadeOut_ticks);
return Color::mix(c1, c2, percent);
}
};
#endif // FLASHONCE_H

68
user/Fader.h Executable file
View File

@@ -0,0 +1,68 @@
#ifndef FADER_H
#define FADER_H
#include "ESP8266lib/ext/led/WS2812B.h"
/** fade between two colors */
class FadeBetween {
Color c1;
Color c2;
int pos;
int speed;
int dir;
public:
/** ctor */
FadeBetween() {
restart();
}
void setColor1(Color c1) {
this->c1 = c1;
}
void setColor2(Color c2) {
this->c2 = c2;
}
void restart() {
pos = 0;
speed = 128;
dir = 0;
}
void update() {
if (dir == 0) {
++pos;
if (pos == speed) {dir = 1;}
} else {
--pos;
if (pos == 0) {dir = 0;}
}
}
Color getCurrent() const {
const int fac0 = pos;
const int fac1 = speed - fac0;
Color c;
c.r = clamp( (c1.r * fac0 + c2.r * fac1) / speed );
c.g = clamp( (c1.g * fac0 + c2.g * fac1) / speed );
c.b = clamp( (c1.b * fac0 + c2.b * fac1) / speed );
return c;
}
private:
static inline uint8_t clamp(int val) {
if (val > 255) {return 255;}
if (val < 0) {return 0;}
return val;
}
};
#endif // FADER_H

45
user/Rainbow.h Normal file
View File

@@ -0,0 +1,45 @@
#ifndef RAINBOW_H
#define RAINBOW_H
#include "ESP8266lib/ext/led/WS2812B.h"
/**
* show rainbow colors using HUE
*/
class Rainbow {
uint8_t hue = 0;
public:
/** ctor */
Rainbow() {
;
}
/** show a beat by shifting the hue color */
void shift(const int val) {
hue += val;
}
/** set hue back to 0 */
void restart() {
hue = 0;
}
/** called from the main */
void update() {
++hue;
}
/** called from the main */
Color getCurrent() const {
Color c; c.setHSV(hue, 255, 255);
return c;
}
};
#endif // RAINBOW_H

72
user/RainbowBeat.h Executable file
View File

@@ -0,0 +1,72 @@
#ifndef RAINBOWBEAT_H
#define RAINBOWBEAT_H
#include "ESP8266lib/ext/led/WS2812B.h"
/**
* show rainbow colors using HUE
* use only 25% percent brightness
* when there is a beat, switch to 100% brightness
* and fade back to 25% again
*/
class RainbowBeat {
int p1 = 255;
int p2 = 63;
int fadeOut_ticks = 0;
int ticksLeft = 0;
uint8_t hue = 0;
public:
/** ctor */
RainbowBeat() {
;
}
/** configure the amounts for idle and beat */
void setAmounts(int p1, int p2) {
this->p1 = p1;
this->p2 = p2;
}
/** show a bight beat for x ticks */
void flash(const int duration_ticks) {
this->fadeOut_ticks = duration_ticks;
this->ticksLeft = duration_ticks;
}
/** show a beat by shifting the hue color */
void shift(const int val) {
hue += val;
}
/** shift to the given absolute hue */
void shiftTo(const int valAbs) {
hue = valAbs;
}
/** set hue back to 0 */
void restart() {
this->hue = 0;
}
/** called from the main */
void update() {
if (ticksLeft > 0) {--ticksLeft;} // fade-out
hue += 1;
}
/** called from the main */
Color getCurrent() const {
const int percent = (ticksLeft * 100 / fadeOut_ticks);
const int val = ((p1 * percent) + (p2 * (100-percent))) / 100;
Color c; c.setHSV(hue, 255, val);
return c;
}
};
#endif // RAINBOWBEAT_H

132
user/run_Buzzer.h Executable file
View File

@@ -0,0 +1,132 @@
#include "ESP8266lib/io/IO.h"
#include "ESP8266lib/ext/led/WS2812B.h"
const uint16_t localPort = 1337;
//const char* remoteIP = "192.168.22.255"; // OGWLAN
//const char* remoteIP = "192.168.24.255"; // UGWLAN
const char* remoteIP = "255.255.255.255"; // BUZZER
const uint16_t remotePort = 7331;
//char ssid[32] = "OGWLAN";
//char password[64] = "LeckereKekse!";
//char ssid[32] = "UGWLAN";
//char password[64] = "LeckereKekse!";
char ssid[32] = "Buzzer";
char password[64] = "LeckereKekse!";
#include "ADC.h"
#include "Buzzer.h"
Buzzer buzzer;
bool connected;
void onWifiEvent(System_Event_t* evt) {
os_printf("event %x\n", evt->event);
switch (evt->event) {
case EVENT_STAMODE_CONNECTED:
os_printf("connect to ssid %s, channel %d\n", evt->event_info.connected.ssid, evt->event_info.connected.channel);
buzzer.setRGB(0,0,255); // blue
break;
case EVENT_STAMODE_GOT_IP:
os_printf("got IP\n");
buzzer.setOff();
connected = true;
buzzer.sendHeartbeat();
break;
case EVENT_STAMODE_DISCONNECTED:
os_printf("disconnect from ssid %s, reason %d\n", evt->event_info.disconnected.ssid, evt->event_info.disconnected.reason);
buzzer.setRGB(255,0,0);
break;
}
}
void my_init() {
connected = false;
wifi_station_disconnect();
os_delay_us(1000*250);
os_printf("my_init\r\n");
// stty -F /dev/ttyUSB0 115200 raw -echo && cat /dev/ttyUSB0
// yellow
buzzer.setRGB(255,255,0);
// register the event handler
wifi_set_event_handler_cb(onWifiEvent);
// i am a client
wifi_set_opmode(STATION_MODE);
wifi_station_disconnect();
os_delay_us(1000*500);
// connect
struct station_config stationConf;
os_memset(&stationConf, 0, sizeof(stationConf));
os_memcpy(&stationConf.ssid, ssid, 32);
os_memcpy(&stationConf.password, password, 32);
wifi_station_set_config(&stationConf);
wifi_station_connect();
// power safe
//NONE_SLEEP_T
//LIGHT_SLEEP_T
//MODEM_SLEEP_T
//wifi_set_opmode_current(NULL_MODE);
//wifi_set_sleep_type(LIGHT_SLEEP_T);
//wifi_set_sleep_type(MODEM_SLEEP_T);
// green
buzzer.setRGB(0,255,0);
os_delay_us(1000*150);
}
void my_once() {
//buzzer.setFade();
//buzzer.setStrobo(255,255,255);
}
void my_loop() {
// 1 ms delay
os_delay_us(1000);
if (connected) {
buzzer.update();
}
}

1
user/user_config.h Executable file
View File

@@ -0,0 +1 @@
#

83
user/user_main.cpp Executable file
View File

@@ -0,0 +1,83 @@
extern "C" {
#include "ets_sys.h"
#include "c_types.h"
#include "osapi.h"
//#include "gpio.h"
//#include "os_type.h"
//#include "user_config.h"
#include "user_interface.h"
//#include "wpa2_enterprise.h"
//#include "inttypes.h"
#include "mem.h"
#include "espconn.h"
#include "ESP8266lib/c++.h"
//#include "driver/uart.h"
}
#define user_procTaskQueueLen 1
#define WEMOS_D1_MINI 1
#define NODE_MCU 2
#define PLATFORM WEMOS_D1_MINI
#define LED_PIN GPIO5
//#define PLATFORM NODE_MCU
#include "run_Buzzer.h"
static os_event_t user_procTaskQueue[user_procTaskQueueLen];
extern "C" void ICACHE_FLASH_ATTR user_init();
bool once = true;
//Main code function
void ICACHE_FLASH_ATTR user_loop(os_event_t*) {
// custome once-code
if (once) {
my_once();
once = false;
}
// custome loop code
my_loop();
// run again
system_os_post(USER_TASK_PRIO_0, 0, 0 );
}
void ICACHE_FLASH_ATTR user_init() {
// basic hardware setup
os_delay_us(1000*50);
gpio_init();
uart_div_modify(0, UART_CLK_FREQ / 115200);
os_delay_us(1000*50);
os_printf("init\r\n");
// ensure global constructors are called
do_global_ctors();
// custom one-time init code
my_init();
// start the loop-task
system_os_task(user_loop, USER_TASK_PRIO_0, user_procTaskQueue, user_procTaskQueueLen);
system_os_post(USER_TASK_PRIO_0, 0, 0 );
}