global Update
This commit is contained in:
parent
76a040aab4
commit
99bd33a54e
8 changed files with 956 additions and 70 deletions
BIN
.DS_Store
vendored
Normal file
BIN
.DS_Store
vendored
Normal file
Binary file not shown.
|
|
@ -85,7 +85,6 @@ void ICACHE_RAM_ATTR ESPboyLED::ledset(uint8_t rled, uint8_t gled, uint8_t bled)
|
||||||
static uint8_t cpuFreq;
|
static uint8_t cpuFreq;
|
||||||
static const uint32_t pinMask = 1<<LEDPIN;
|
static const uint32_t pinMask = 1<<LEDPIN;
|
||||||
|
|
||||||
|
|
||||||
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask);
|
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinMask);
|
||||||
delay(1);
|
delay(1);
|
||||||
|
|
||||||
|
|
|
||||||
151
ESPboyMenuGUI.cpp
Normal file
151
ESPboyMenuGUI.cpp
Normal file
|
|
@ -0,0 +1,151 @@
|
||||||
|
/*
|
||||||
|
ESPboy_MenuGUI class
|
||||||
|
for www.ESPboy.com project by RomanS
|
||||||
|
https://hackaday.io/project/164830-espboy-games-iot-stem-for-education-fun
|
||||||
|
v1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "ESPboyMenuGUI.h"
|
||||||
|
#define SOUNDPIN D3
|
||||||
|
|
||||||
|
|
||||||
|
ESPboyMenuGUI::ESPboyMenuGUI(TFT_eSPI *tftMenuGUI, Adafruit_MCP23017 *mcpMenuGUI) {
|
||||||
|
tft = tftMenuGUI;
|
||||||
|
mcp = mcpMenuGUI;
|
||||||
|
#ifdef U8g2
|
||||||
|
u8f = new U8g2_for_TFT_eSPI;
|
||||||
|
u8f->begin(*tft);
|
||||||
|
u8f->setFontMode(1); // use u8g2 none transparent mode
|
||||||
|
u8f->setBackgroundColor(TFT_BLACK);
|
||||||
|
u8f->setFontDirection(0); // left to right
|
||||||
|
u8f->setFont(u8g2_font_4x6_t_cyrillic);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t ESPboyMenuGUI::getKeys() { return (~mcp->readGPIOAB() & 255); }
|
||||||
|
|
||||||
|
|
||||||
|
void ESPboyMenuGUI::menuDraw(){
|
||||||
|
static uint16_t scalingFactor;
|
||||||
|
static uint16_t previousRect = 0;
|
||||||
|
|
||||||
|
if(menuList.menuItemsQuantity>1){
|
||||||
|
if(menuList.menuItemsQuantity>=MENU_MAX_LINES_ONSCREEN)
|
||||||
|
scalingFactor = ((MENU_MAX_LINES_ONSCREEN*MENU_SPACE_BETWEEN_LINES-6)*1000)/(menuList.menuItemsQuantity-1);
|
||||||
|
else
|
||||||
|
scalingFactor = ((menuList.menuItemsQuantity*MENU_SPACE_BETWEEN_LINES-6)*1000)/(menuList.menuItemsQuantity-1);
|
||||||
|
}
|
||||||
|
else scalingFactor=1;
|
||||||
|
|
||||||
|
tft->drawRect(0, previousRect*MENU_SPACE_BETWEEN_LINES, 122, MENU_SPACE_BETWEEN_LINES, TFT_BLACK);
|
||||||
|
tft->fillRect(125,0, 3, 128, TFT_BLACK);
|
||||||
|
|
||||||
|
if (menuList.menuCurrent+1 > MENU_MAX_LINES_ONSCREEN + menuList.menuOffset) {
|
||||||
|
tft->fillScreen(TFT_BLACK);
|
||||||
|
menuList.menuOffset++;}
|
||||||
|
if (menuList.menuCurrent < menuList.menuOffset) {
|
||||||
|
tft->fillScreen(TFT_BLACK);
|
||||||
|
menuList.menuOffset--;}
|
||||||
|
|
||||||
|
if(menuList.menuItemsQuantity>=MENU_MAX_LINES_ONSCREEN)
|
||||||
|
tft->drawLine(126,0, 126, MENU_MAX_LINES_ONSCREEN*MENU_SPACE_BETWEEN_LINES-2, TFT_BLUE);
|
||||||
|
else
|
||||||
|
tft->drawLine(126,0, 126, menuList.menuItemsQuantity*MENU_SPACE_BETWEEN_LINES-2, TFT_BLUE);
|
||||||
|
|
||||||
|
for (uint8_t i=0;; i++){
|
||||||
|
if(i>=menuList.menuItemsQuantity || i>=MENU_MAX_LINES_ONSCREEN) break;
|
||||||
|
|
||||||
|
#ifndef U8g2
|
||||||
|
if(menuList.menuLine[i+menuList.menuOffset][0] == '-'){
|
||||||
|
tft->setTextColor(menuList.menuUnselectedLineColor);
|
||||||
|
tft->drawString(&menuList.menuLine[i+menuList.menuOffset][1], 3, i*MENU_SPACE_BETWEEN_LINES+2);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
tft->setTextColor(menuList.menuLineColor);
|
||||||
|
tft->drawString(menuList.menuLine[i+menuList.menuOffset], 3, i*MENU_SPACE_BETWEEN_LINES+2);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if(menuList.menuLine[i+menuList.menuOffset][0] == '-'){
|
||||||
|
u8f->setForegroundColor(menuList.menuUnselectedLineColor);
|
||||||
|
u8f->drawStr(3, i*MENU_SPACE_BETWEEN_LINES+1+GUI_FONT_HEIGHT, &menuList.menuLine[i+menuList.menuOffset][1]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
u8f->setForegroundColor(menuList.menuLineColor);
|
||||||
|
u8f->drawStr(3, i*MENU_SPACE_BETWEEN_LINES+1+GUI_FONT_HEIGHT, menuList.menuLine[i+menuList.menuOffset]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if((i+menuList.menuOffset) == menuList.menuCurrent){
|
||||||
|
tft->drawRect(0, i*MENU_SPACE_BETWEEN_LINES, 122, MENU_SPACE_BETWEEN_LINES, menuList.menuSelectionColor);
|
||||||
|
previousRect=i;}
|
||||||
|
}
|
||||||
|
|
||||||
|
tft->fillRect(125, (scalingFactor*menuList.menuCurrent+2)/1000, 3, 5, TFT_YELLOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t ESPboyMenuGUI::menuInit(const char** menuLinesF, uint16_t menuLineColorF, uint16_t menuUnselectedLineColorF, uint16_t menuSelectionColorF){
|
||||||
|
uint16_t count=0;
|
||||||
|
static uint8_t keyPressed;
|
||||||
|
tft->fillScreen(TFT_BLACK);
|
||||||
|
menuList.menuLine = menuLinesF;
|
||||||
|
menuList.menuLineColor = menuLineColorF;
|
||||||
|
menuList.menuUnselectedLineColor = menuUnselectedLineColorF;
|
||||||
|
menuList.menuCurrent = 0;
|
||||||
|
menuList.menuSelectionColor = menuSelectionColorF;
|
||||||
|
menuList.menuOffset=0;
|
||||||
|
while(menuLinesF[count++]);
|
||||||
|
menuList.menuItemsQuantity = count-1;
|
||||||
|
|
||||||
|
menuDraw();
|
||||||
|
|
||||||
|
while(1){
|
||||||
|
while (!getKeys())delay(50);
|
||||||
|
|
||||||
|
keyPressed = getKeys();
|
||||||
|
|
||||||
|
if (keyPressed&MenuGUI_PAD_UP && menuList.menuCurrent > 0) {
|
||||||
|
menuList.menuCurrent--;
|
||||||
|
#ifdef buttonclicks
|
||||||
|
tone(SOUNDPIN,10,10);
|
||||||
|
#endif
|
||||||
|
menuDraw();
|
||||||
|
}
|
||||||
|
if (keyPressed&MenuGUI_PAD_DOWN && menuList.menuCurrent+1 < menuList.menuItemsQuantity) {
|
||||||
|
menuList.menuCurrent++;
|
||||||
|
#ifdef buttonclicks
|
||||||
|
tone(SOUNDPIN,10,10);
|
||||||
|
#endif
|
||||||
|
menuDraw();
|
||||||
|
}
|
||||||
|
if (keyPressed&MenuGUI_PAD_ACT && menuList.menuLine[menuList.menuCurrent][0] != '-') {
|
||||||
|
#ifdef buttonclicks
|
||||||
|
tone(SOUNDPIN,100,100);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
tft->drawRect(0, (menuList.menuCurrent+menuList.menuOffset)*MENU_SPACE_BETWEEN_LINES, 122, MENU_SPACE_BETWEEN_LINES, TFT_BLACK);
|
||||||
|
delay(50);
|
||||||
|
tft->drawRect(0, (menuList.menuCurrent+menuList.menuOffset)*MENU_SPACE_BETWEEN_LINES, 122, MENU_SPACE_BETWEEN_LINES, menuList.menuSelectionColor);
|
||||||
|
delay(50);
|
||||||
|
tft->drawRect(0, (menuList.menuCurrent+menuList.menuOffset)*MENU_SPACE_BETWEEN_LINES, 122, MENU_SPACE_BETWEEN_LINES, TFT_BLACK);
|
||||||
|
delay(50);
|
||||||
|
tft->drawRect(0, (menuList.menuCurrent+menuList.menuOffset)*MENU_SPACE_BETWEEN_LINES, 122, MENU_SPACE_BETWEEN_LINES, menuList.menuSelectionColor);
|
||||||
|
delay(200);
|
||||||
|
|
||||||
|
tft->fillScreen(TFT_BLACK);
|
||||||
|
return(menuList.menuCurrent+1);
|
||||||
|
}
|
||||||
|
if (keyPressed&MenuGUI_PAD_ESC){
|
||||||
|
#ifdef buttonclicks
|
||||||
|
tone(SOUNDPIN,100,100);
|
||||||
|
#endif
|
||||||
|
tft->fillScreen(TFT_BLACK);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(120);
|
||||||
|
}
|
||||||
|
};
|
||||||
75
ESPboyMenuGUI.h
Normal file
75
ESPboyMenuGUI.h
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
ESPboy_MenuGUI class
|
||||||
|
for www.ESPboy.com project by RomanS
|
||||||
|
https://hackaday.io/project/164830-espboy-games-iot-stem-for-education-fun
|
||||||
|
v1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
//!!!!!!!!!!!!!!!!!
|
||||||
|
//#define U8g2 //if defined then using font 4x6, if commented using font 6x8
|
||||||
|
#define buttonclicks //if defined - button are clicking but it takes more than 1kb RAM, if commented - no clicks and more free RAM
|
||||||
|
////!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef ESPboy_MenuGUI
|
||||||
|
#define ESPboy_MenuGUI
|
||||||
|
|
||||||
|
#include <Adafruit_MCP23017.h>
|
||||||
|
#include <TFT_eSPI.h>
|
||||||
|
#include <FS.h>
|
||||||
|
using fs::FS;
|
||||||
|
|
||||||
|
#ifdef U8g2
|
||||||
|
#include "U8g2_for_TFT_eSPI.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef U8g2
|
||||||
|
#define GUI_FONT_WIDTH 4
|
||||||
|
#define GUI_FONT_HEIGHT 6
|
||||||
|
#else
|
||||||
|
#define GUI_FONT_WIDTH 6
|
||||||
|
#define GUI_FONT_HEIGHT 8
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MENU_SPACE_BETWEEN_LINES (GUI_FONT_HEIGHT+3)
|
||||||
|
#define MENU_MAX_LINES_ONSCREEN (128/MENU_SPACE_BETWEEN_LINES)
|
||||||
|
|
||||||
|
#define MenuGUI_PAD_LEFT 0x01
|
||||||
|
#define MenuGUI_PAD_UP 0x02
|
||||||
|
#define MenuGUI_PAD_DOWN 0x04
|
||||||
|
#define MenuGUI_PAD_RIGHT 0x08
|
||||||
|
#define MenuGUI_PAD_ACT 0x10
|
||||||
|
#define MenuGUI_PAD_ESC 0x20
|
||||||
|
#define MenuGUI_PAD_LFT 0x40
|
||||||
|
#define MenuGUI_PAD_RGT 0x80
|
||||||
|
#define MenuGUI_PAD_ANY 0xff
|
||||||
|
|
||||||
|
|
||||||
|
class ESPboyMenuGUI{
|
||||||
|
|
||||||
|
private:
|
||||||
|
Adafruit_MCP23017 *mcp;
|
||||||
|
TFT_eSPI *tft;
|
||||||
|
#ifdef U8g2
|
||||||
|
U8g2_for_TFT_eSPI *u8f;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct menuStruct{
|
||||||
|
const char **menuLine;
|
||||||
|
uint16_t menuOffset;
|
||||||
|
uint16_t menuItemsQuantity;
|
||||||
|
uint16_t menuLineColor;
|
||||||
|
uint16_t menuUnselectedLineColor;
|
||||||
|
uint16_t menuSelectionColor;
|
||||||
|
uint16_t menuCurrent;
|
||||||
|
} menuList;
|
||||||
|
|
||||||
|
uint8_t getKeys();
|
||||||
|
void menuDraw();
|
||||||
|
|
||||||
|
public:
|
||||||
|
ESPboyMenuGUI(TFT_eSPI *tftMenuGUI, Adafruit_MCP23017 *mcpMenuGUI);
|
||||||
|
uint16_t menuInit(const char** menuLinesF, uint16_t menuLineColorF, uint16_t menuUnselectedLineColorF, uint16_t menuSelectionColorF);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -156,6 +156,29 @@ String ESPboyTerminalGUI::getUserInput() {
|
||||||
return (userInput);
|
return (userInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ESPboyTerminalGUI::doScroll(){
|
||||||
|
uint8_t keyState=0;
|
||||||
|
#ifdef buttonclicks
|
||||||
|
tone(SOUNDPIN, 100, 10);
|
||||||
|
#endif
|
||||||
|
toggleDisplayMode(1);
|
||||||
|
while (!(keyState & GUI_PAD_ESC)){
|
||||||
|
delay(1);
|
||||||
|
keyState = getKeys();
|
||||||
|
if(keyState){
|
||||||
|
if (keyState&GUI_PAD_RGT && keybParam.renderLine) {
|
||||||
|
keybParam.renderLine--;}
|
||||||
|
if (keyState&GUI_PAD_LFT && keybParam.renderLine < consoleStringsVector.size() - GUI_MAX_STRINGS_ONSCREEN_SMALL) {
|
||||||
|
keybParam.renderLine++;}
|
||||||
|
drawConsole(0);
|
||||||
|
#ifdef buttonclicks
|
||||||
|
tone(SOUNDPIN, 100, 10);
|
||||||
|
#endif
|
||||||
|
delay(GUI_KEYB_CALL_DELAY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ESPboyTerminalGUI::printConsole(String bfrstr, uint16_t color, uint8_t ln, uint8_t noAddLine) {
|
void ESPboyTerminalGUI::printConsole(String bfrstr, uint16_t color, uint8_t ln, uint8_t noAddLine) {
|
||||||
String toprint;
|
String toprint;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,6 @@ v2.1
|
||||||
#ifndef ESPboy_TerminalGUI
|
#ifndef ESPboy_TerminalGUI
|
||||||
#define ESPboy_TerminalGUI
|
#define ESPboy_TerminalGUI
|
||||||
|
|
||||||
#define CSTFTPIN 8
|
|
||||||
|
|
||||||
#include <Adafruit_MCP23017.h>
|
#include <Adafruit_MCP23017.h>
|
||||||
#include <TFT_eSPI.h>
|
#include <TFT_eSPI.h>
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
|
|
@ -97,6 +95,7 @@ public:
|
||||||
uint32_t waitKeyUnpressed();
|
uint32_t waitKeyUnpressed();
|
||||||
void printConsole(String bfrstr, uint16_t color, uint8_t ln, uint8_t noAddLine);
|
void printConsole(String bfrstr, uint16_t color, uint8_t ln, uint8_t noAddLine);
|
||||||
String getUserInput();
|
String getUserInput();
|
||||||
|
void doScroll();
|
||||||
void toggleDisplayMode(uint8_t mode);
|
void toggleDisplayMode(uint8_t mode);
|
||||||
void drawOwnTypingLine(String typingLine, uint16_t colorLine);
|
void drawOwnTypingLine(String typingLine, uint16_t colorLine);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,60 @@
|
||||||
#include "ESPboyInit.h"
|
#include "ESPboyInit.h"
|
||||||
#include "ESPboyTerminalGUI.h"
|
#include "ESPboyTerminalGUI.h"
|
||||||
|
#include "ESPboyMenuGUI.h"
|
||||||
#include "ESPboyLED.h"
|
#include "ESPboyLED.h"
|
||||||
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||||
#include <RCSwitch.h>
|
#include <RCSwitch.h>
|
||||||
|
#include <ESP_EEPROM.h>
|
||||||
|
|
||||||
#define CC1101riceivePin 3
|
#define CC1101riceivePin 3
|
||||||
#define CC1101chipSelectPin D8
|
#define CC1101chipSelectPin D8
|
||||||
#define TFTchipSelectPin 8
|
#define TFTchipSelectPin 8
|
||||||
|
#define MAX_RECORDS_TO_STORE 40
|
||||||
|
|
||||||
|
|
||||||
|
const char *menuMain[] PROGMEM = {
|
||||||
|
"LISTEN",
|
||||||
|
"LISTEN & STORE",
|
||||||
|
"LIST OF STORED",
|
||||||
|
"INFO", //Number of stored, free to store
|
||||||
|
"CLEAR ALL", //clears all unprotected records
|
||||||
|
"FORMAT", //clears all records
|
||||||
|
NULL // the last element of every menu list should be NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *menuRecord[] PROGMEM = {
|
||||||
|
"SEND", //send selected record
|
||||||
|
"SHOW",
|
||||||
|
"SET REPEAT",
|
||||||
|
"RENAME",
|
||||||
|
"PROTECT",
|
||||||
|
"UNPROTECT",
|
||||||
|
"DELETE",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {listen_, listenstore_, listofstored_, info_, clearall_, format_};
|
||||||
|
enum {send_, show_, setrepeat_, rename_, protect_, unprotect_, delete_};
|
||||||
|
|
||||||
RCSwitch mySwitch;
|
RCSwitch mySwitch;
|
||||||
ESPboyInit myESPboy;
|
ESPboyInit myESPboy;
|
||||||
ESPboyTerminalGUI *terminalGUIobj = NULL;
|
ESPboyTerminalGUI *terminalGUIobj = NULL;
|
||||||
|
//ESPboyMenuGUI *menuGUIobj = NULL;
|
||||||
ESPboyLED myLED;
|
ESPboyLED myLED;
|
||||||
|
|
||||||
uint32_t counter;
|
char EEPROMmagicNo[4]={0xCC,0xCD,0xCE,0};//EEPROM marker of Sub1Ghz storage
|
||||||
|
|
||||||
|
struct recordStored{
|
||||||
|
char recordName[20];
|
||||||
|
uint8_t protectedFlag;
|
||||||
|
uint8_t repeatNo;
|
||||||
|
uint8_t protocol;
|
||||||
|
uint32_t pulseLength;
|
||||||
|
uint32_t Bitlength;
|
||||||
|
uint32_t Value;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector <recordStored> recordStoredVector;
|
||||||
|
|
||||||
String bin2tri(uint32_t dec) {
|
String bin2tri(uint32_t dec) {
|
||||||
uint8_t pos = 0;
|
uint8_t pos = 0;
|
||||||
|
|
@ -34,113 +75,127 @@ String bin2tri(uint32_t dec) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void printConsoleLocal(String str, uint32_t clr, uint8_t flag1, uint8_t flag2){
|
||||||
|
myESPboy.mcp.digitalWrite(TFTchipSelectPin, LOW);
|
||||||
|
digitalWrite(CC1101chipSelectPin, HIGH);
|
||||||
|
printConsoleLocal(str, clr, flag1, flag2);
|
||||||
|
myESPboy.mcp.digitalWrite(TFTchipSelectPin, HIGH);
|
||||||
|
digitalWrite(CC1101chipSelectPin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void output() {
|
void output() {
|
||||||
String toPrint;
|
String toPrint;
|
||||||
uint32_t *rawData;
|
uint32_t *rawData;
|
||||||
uint32_t dec, lengthval, rssi, lqi;
|
uint32_t dec, lengthval, rssi, lqi;
|
||||||
|
|
||||||
myESPboy.mcp.digitalWrite(TFTchipSelectPin, HIGH);
|
|
||||||
myESPboy.mcp.digitalWrite(CC1101chipSelectPin, LOW);
|
|
||||||
delay(10);
|
|
||||||
|
|
||||||
dec = mySwitch.getReceivedValue();
|
dec = mySwitch.getReceivedValue();
|
||||||
lengthval = mySwitch.getReceivedBitlength();
|
lengthval = mySwitch.getReceivedBitlength();
|
||||||
rssi = ELECHOUSE_cc1101.getRssi();
|
rssi = ELECHOUSE_cc1101.getRssi();
|
||||||
lqi = ELECHOUSE_cc1101.getLqi();
|
lqi = ELECHOUSE_cc1101.getLqi();
|
||||||
|
|
||||||
myESPboy.mcp.digitalWrite(TFTchipSelectPin, LOW);
|
printConsoleLocal(" ", TFT_MAGENTA, 1, 1);
|
||||||
myESPboy.mcp.digitalWrite(CC1101chipSelectPin, HIGH);
|
printConsoleLocal(" ", TFT_MAGENTA, 1, 0);
|
||||||
delay(10);
|
printConsoleLocal(F("-------------------------------"), TFT_YELLOW, 1, 0);
|
||||||
|
printConsoleLocal(F("DETECTED! DECODE:"), TFT_RED, 1, 0);
|
||||||
terminalGUIobj->printConsole(" ", TFT_MAGENTA, 1, 1);
|
printConsoleLocal(F("-------------------------------"), TFT_YELLOW, 1, 0);
|
||||||
terminalGUIobj->printConsole(" ", TFT_MAGENTA, 1, 0);
|
|
||||||
terminalGUIobj->printConsole(F("-------------------------------"), TFT_YELLOW, 1, 0);
|
|
||||||
terminalGUIobj->printConsole(F("DETECTED! DECODE:"), TFT_RED, 1, 0);
|
|
||||||
terminalGUIobj->printConsole(F("-------------------------------"), TFT_YELLOW, 1, 0);
|
|
||||||
|
|
||||||
//toPrint = "RSSI/LQI: ";
|
//toPrint = "RSSI/LQI: ";
|
||||||
//toPrint += (String)rssi;
|
//toPrint += (String)rssi;
|
||||||
//toPrint += "/";
|
//toPrint += "/";
|
||||||
//toPrint += (String)lqi;
|
//toPrint += (String)lqi;
|
||||||
//terminalGUIobj->printConsole(toPrint, TFT_YELLOW, 1, 0);
|
//printConsoleLocal(toPrint, TFT_YELLOW, 1, 0);
|
||||||
|
|
||||||
toPrint="DEC: ";
|
toPrint="DEC: ";
|
||||||
toPrint+=(String)dec;
|
toPrint+=(String)dec;
|
||||||
toPrint+=" (";
|
toPrint+=" (";
|
||||||
toPrint+= (String)lengthval;
|
toPrint+= (String)lengthval;
|
||||||
toPrint+= " Bit)";
|
toPrint+= " Bit)";
|
||||||
terminalGUIobj->printConsole(toPrint, TFT_GREEN, 1, 0);
|
printConsoleLocal(toPrint, TFT_GREEN, 1, 0);
|
||||||
|
|
||||||
toPrint="BIN: ";
|
toPrint = String (dec,BIN);
|
||||||
toPrint+= String (dec,BIN);
|
while(toPrint.length()<lengthval) toPrint = "0" + toPrint;
|
||||||
terminalGUIobj->printConsole(toPrint, TFT_GREEN, 1, 0);
|
toPrint="BIN: "+ toPrint;
|
||||||
|
|
||||||
|
printConsoleLocal(toPrint, TFT_GREEN, 1, 0);
|
||||||
|
|
||||||
toPrint="TRI: ";
|
toPrint="TRI: ";
|
||||||
toPrint+= bin2tri(dec);
|
toPrint+= bin2tri(dec);
|
||||||
terminalGUIobj->printConsole(toPrint, TFT_WHITE, 1, 0);
|
printConsoleLocal(toPrint, TFT_WHITE, 1, 0);
|
||||||
|
|
||||||
toPrint="PULSE LEN: ";
|
toPrint="PULSE LEN: ";
|
||||||
toPrint+=(String)mySwitch.getReceivedDelay();
|
toPrint+=(String)mySwitch.getReceivedDelay();
|
||||||
toPrint+=" ms";
|
toPrint+=" ms";
|
||||||
terminalGUIobj->printConsole(toPrint, TFT_WHITE, 1, 0);
|
printConsoleLocal(toPrint, TFT_WHITE, 1, 0);
|
||||||
|
|
||||||
toPrint="FIRST LEV: ";
|
toPrint="FIRST LEV: ";
|
||||||
if (mySwitch.getReceivedLevelInFirstTiming()) toPrint += "HIGH";
|
if (mySwitch.getReceivedLevelInFirstTiming()) toPrint += "HIGH";
|
||||||
else toPrint+= "LOW";
|
else toPrint+= "LOW";
|
||||||
terminalGUIobj->printConsole(toPrint, TFT_WHITE, 1, 0);
|
printConsoleLocal(toPrint, TFT_WHITE, 1, 0);
|
||||||
|
|
||||||
toPrint="PROTOCOL: ";
|
toPrint="PROTOCOL: ";
|
||||||
toPrint+=(String)mySwitch.getReceivedProtocol();
|
toPrint+=(String)mySwitch.getReceivedProtocol();
|
||||||
terminalGUIobj->printConsole(toPrint, TFT_WHITE, 1, 0);
|
printConsoleLocal(toPrint, TFT_WHITE, 1, 0);
|
||||||
|
|
||||||
toPrint="IS INV: ";
|
toPrint="IS INV: ";
|
||||||
if (mySwitch.getReceivedInverted()) toPrint+="YES";
|
if (mySwitch.getReceivedInverted()) toPrint+="YES";
|
||||||
else toPrint+="NO";
|
else toPrint+="NO";
|
||||||
terminalGUIobj->printConsole(toPrint, TFT_WHITE, 1, 0);
|
printConsoleLocal(toPrint, TFT_WHITE, 1, 0);
|
||||||
|
|
||||||
terminalGUIobj->printConsole(F("DATA: "), TFT_YELLOW, 1, 0);
|
printConsoleLocal(F("DATA: "), TFT_YELLOW, 1, 0);
|
||||||
toPrint="";
|
toPrint="";
|
||||||
rawData = mySwitch.getReceivedRawdata();
|
rawData = mySwitch.getReceivedRawdata();
|
||||||
for (unsigned int i=0; i<= lengthval*2; i++) toPrint+=((String)rawData[i]+",");
|
for (unsigned int i=0; i<= lengthval*2; i++) toPrint+=((String)rawData[i]+",");
|
||||||
toPrint = toPrint.substring(0,toPrint.length()-1);
|
toPrint = toPrint.substring(0,toPrint.length()-1);
|
||||||
terminalGUIobj->printConsole(toPrint, TFT_BLUE, 1, 0);
|
printConsoleLocal(toPrint, TFT_BLUE, 1, 0);
|
||||||
|
|
||||||
terminalGUIobj->printConsole(F("-------------------------------"), TFT_YELLOW, 1, 0);
|
printConsoleLocal(F("-------------------------------"), TFT_YELLOW, 1, 0);
|
||||||
terminalGUIobj->printConsole("", TFT_BLACK, 1, 0);
|
printConsoleLocal("", TFT_BLACK, 1, 0);
|
||||||
|
|
||||||
myESPboy.mcp.digitalWrite(TFTchipSelectPin, HIGH);
|
|
||||||
myESPboy.mcp.digitalWrite(CC1101chipSelectPin, LOW);
|
|
||||||
delay(10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void readEEPROM(){
|
||||||
|
//EEPROM.get(0, eepromVar1);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void writeEEPROM(){
|
||||||
|
//EEPROM.put(0, eepromVar1);
|
||||||
|
//EEPROM.commit();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void setup(){
|
void setup(){
|
||||||
|
EEPROM.begin(4096);
|
||||||
|
|
||||||
myESPboy.begin("ESPboy Sub1GHz module");
|
myESPboy.begin("ESPboy Sub1GHz module");
|
||||||
myLED.begin(&myESPboy.mcp);
|
myLED.begin(&myESPboy.mcp);
|
||||||
terminalGUIobj = new ESPboyTerminalGUI(&myESPboy.tft, &myESPboy.mcp);
|
terminalGUIobj = new ESPboyTerminalGUI(&myESPboy.tft, &myESPboy.mcp);
|
||||||
|
//menuGUIobj = new ESPboyMenuGUI(&myESPboy.tft, &myESPboy.mcp);
|
||||||
|
|
||||||
terminalGUIobj->printConsole(F("Sub1GHz module v1.0"), TFT_MAGENTA, 1, 0);
|
delay(500);
|
||||||
terminalGUIobj->printConsole("", TFT_BLACK, 1, 0);
|
printConsoleLocal(F("Sub1GHz module v1.0"), TFT_MAGENTA, 1, 0);
|
||||||
|
printConsoleLocal("", TFT_BLACK, 1, 0);
|
||||||
myESPboy.mcp.digitalWrite(TFTchipSelectPin, HIGH);
|
delay(5000);
|
||||||
digitalWrite(CC1101chipSelectPin, LOW);
|
|
||||||
delay(10);
|
|
||||||
|
|
||||||
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
|
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
|
||||||
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
|
ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
|
||||||
ELECHOUSE_cc1101.setMHZ(433.92); //The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ.
|
ELECHOUSE_cc1101.setMHZ(433.92); //The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ.
|
||||||
mySwitch.enableReceive(CC1101riceivePin); // Receiver on interrupt 0 => that is pin #2
|
mySwitch.enableReceive(CC1101riceivePin); // Receiver on interrupt 0 => that is pin #2
|
||||||
ELECHOUSE_cc1101.SetRx(); // set Receive on
|
ELECHOUSE_cc1101.SetRx(); // set Receive on
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void listen_f(uint8_t storeFlag){
|
||||||
void loop(){
|
|
||||||
static String str="";
|
static String str="";
|
||||||
static uint8_t ledFlag = 1;
|
static uint8_t ledFlag = 1;
|
||||||
|
static uint32_t counter;
|
||||||
|
|
||||||
|
|
||||||
|
while(!myESPboy.getKeys()){
|
||||||
|
|
||||||
if (mySwitch.available()) {
|
if (mySwitch.available()) {
|
||||||
myLED.setRGB(0,20,0);
|
myLED.setRGB(0,20,0);
|
||||||
|
|
@ -154,33 +209,50 @@ void loop(){
|
||||||
|
|
||||||
if(millis()-counter>2000){
|
if(millis()-counter>2000){
|
||||||
counter=millis();
|
counter=millis();
|
||||||
|
printConsoleLocal(str, TFT_MAGENTA, 1, 1);
|
||||||
myESPboy.mcp.digitalWrite(TFTchipSelectPin, LOW);
|
|
||||||
digitalWrite(CC1101chipSelectPin, HIGH);
|
|
||||||
delay(10);
|
|
||||||
terminalGUIobj->printConsole(str, TFT_MAGENTA, 1, 1);
|
|
||||||
myESPboy.mcp.digitalWrite(TFTchipSelectPin, HIGH);
|
|
||||||
digitalWrite(CC1101chipSelectPin, LOW);
|
|
||||||
|
|
||||||
str+=".";
|
str+=".";
|
||||||
if (str.length()>20) str="";
|
if (str.length()>20) str="";
|
||||||
|
|
||||||
delay(10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ledFlag){
|
if(ledFlag){
|
||||||
ledFlag=0;
|
ledFlag=0;
|
||||||
myLED.setRGB(0,0,0);
|
myLED.setRGB(0,0,0);
|
||||||
|
printConsoleLocal(F("Listening..."), TFT_MAGENTA, 1, 0);
|
||||||
|
printConsoleLocal(F(""), TFT_MAGENTA, 1, 0);
|
||||||
|
}
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop(){
|
||||||
|
listen_f(1);
|
||||||
|
/*uint16_t menuItem;
|
||||||
myESPboy.mcp.digitalWrite(TFTchipSelectPin, LOW);
|
myESPboy.mcp.digitalWrite(TFTchipSelectPin, LOW);
|
||||||
digitalWrite(CC1101chipSelectPin, HIGH);
|
digitalWrite(CC1101chipSelectPin, HIGH);
|
||||||
delay(10);
|
delay(10);
|
||||||
terminalGUIobj->printConsole(F("Listening..."), TFT_MAGENTA, 1, 0);
|
menuItem = menuGUIobj->menuInit(menuMain, TFT_YELLOW, TFT_BLUE, TFT_BLUE);
|
||||||
terminalGUIobj->printConsole(F(""), TFT_MAGENTA, 1, 0);
|
|
||||||
myESPboy.mcp.digitalWrite(TFTchipSelectPin, HIGH);
|
myESPboy.mcp.digitalWrite(TFTchipSelectPin, HIGH);
|
||||||
digitalWrite(CC1101chipSelectPin, LOW);
|
digitalWrite(CC1101chipSelectPin, LOW);
|
||||||
delay(10);
|
delay(10);
|
||||||
}
|
|
||||||
|
|
||||||
delay(1);
|
|
||||||
|
switch (menuItem){
|
||||||
|
case listen_:
|
||||||
|
listen_f(0);
|
||||||
|
break;
|
||||||
|
case listenstore_:
|
||||||
|
listen_f(1);
|
||||||
|
break;
|
||||||
|
case listofstored_:
|
||||||
|
break;
|
||||||
|
case info_:
|
||||||
|
break;
|
||||||
|
case clearall_:
|
||||||
|
break;
|
||||||
|
case format_:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
|
||||||
567
ESPboy_Sub1GHz2.ino
Normal file
567
ESPboy_Sub1GHz2.ino
Normal file
|
|
@ -0,0 +1,567 @@
|
||||||
|
/*
|
||||||
|
ESPboy Sub1Ghz inspector
|
||||||
|
for www.ESPboy.com project by RomanS
|
||||||
|
https://hackaday.io/project/164830-espboy-games-iot-stem-for-education-fun
|
||||||
|
v1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ESPboyInit.h"
|
||||||
|
#include "ESPboyTerminalGUI.h"
|
||||||
|
#include "ESPboyMenuGUI.h"
|
||||||
|
#include "ESPboyLED.h"
|
||||||
|
#include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||||
|
#include <RCSwitch.h>
|
||||||
|
#include <ESP_EEPROM.h>
|
||||||
|
|
||||||
|
#define CC1101riceivePin 3
|
||||||
|
#define CC1101sendPin 2
|
||||||
|
#define CC1101chipSelectPin D8
|
||||||
|
#define TFTchipSelectPin 8
|
||||||
|
|
||||||
|
#define MAX_RECORDS_TO_STORE 40
|
||||||
|
#define DEFAULT_SIGNAL_REPEAT_NUMBER 3
|
||||||
|
|
||||||
|
String protDecode[]={
|
||||||
|
"Unknown",
|
||||||
|
"350 {1,31} {1,3} {3,1} false", // protocol1
|
||||||
|
"650 {1,10} {1,2} {2,1} false", // protocol 2
|
||||||
|
"100 {30 71} {4 11} {9 6} false", // protocol 3
|
||||||
|
"380 {1 6} {1 3} {3 1} false", // protocol 4
|
||||||
|
"500 {6 14} {1 2} {2 1} false", // protocol 5
|
||||||
|
"450 {23 1} {1 2} {2 1} true"}; // protocol 6 (HT6P20B)
|
||||||
|
|
||||||
|
|
||||||
|
char *menuList[MAX_RECORDS_TO_STORE+1];
|
||||||
|
|
||||||
|
const char *menuMain[] PROGMEM = {
|
||||||
|
"LISTEN",
|
||||||
|
"LISTEN & STORE",
|
||||||
|
"LIST OF STORED",
|
||||||
|
"SAVE ALL",
|
||||||
|
"CLEAR ALL", //clears all unprotected records
|
||||||
|
NULL // the last element of every menu list should be NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *menuRecord[] PROGMEM = {
|
||||||
|
"SEND", //send selected record
|
||||||
|
"SHOW",
|
||||||
|
"SET REPEAT",
|
||||||
|
"RENAME",
|
||||||
|
"DELETE",
|
||||||
|
"CANCEL",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {listen_=1, listenstore_, listofstored_, saveall_, clearall_};
|
||||||
|
enum {send_=1, show_, setrepeat_, rename_, delete_, cancel_};
|
||||||
|
|
||||||
|
RCSwitch mySwitch;
|
||||||
|
ESPboyInit myESPboy;
|
||||||
|
ESPboyTerminalGUI *terminalGUIobj = NULL;
|
||||||
|
ESPboyMenuGUI *menuGUIobj = NULL;
|
||||||
|
ESPboyLED myLED;
|
||||||
|
|
||||||
|
char EEPROMmagicNo[4]={0xCC,0xCD,0xCE,0};//EEPROM marker of Sub1Ghz storage
|
||||||
|
|
||||||
|
struct recordStored{
|
||||||
|
char recordName[20];
|
||||||
|
uint32_t recordRepeatno;
|
||||||
|
uint32_t recordProtocol;
|
||||||
|
uint32_t recordPulselen;
|
||||||
|
uint32_t recordBits;
|
||||||
|
uint32_t recordValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector <recordStored> recordStoredVector;
|
||||||
|
|
||||||
|
String bin2tri(uint32_t dec) {
|
||||||
|
uint8_t pos = 0;
|
||||||
|
String returnVal="";
|
||||||
|
String bin;
|
||||||
|
|
||||||
|
bin = String(dec,BIN);
|
||||||
|
while (pos < (bin.length()-1)) {
|
||||||
|
if (bin[pos]=='0' && bin[pos+1]=='0') returnVal += '0';
|
||||||
|
else
|
||||||
|
if (bin[pos]=='1' && bin[pos+1]=='1') returnVal += '1';
|
||||||
|
else
|
||||||
|
if (bin[pos]=='0' && bin[pos+1]=='1') returnVal += 'F';
|
||||||
|
else return "NO";
|
||||||
|
pos += 2;
|
||||||
|
}
|
||||||
|
return returnVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void printConsoleLocal(String str, uint32_t clr, uint8_t flag1, uint8_t flag2){
|
||||||
|
myESPboy.mcp.digitalWrite(TFTchipSelectPin, LOW);
|
||||||
|
digitalWrite(CC1101chipSelectPin, HIGH);
|
||||||
|
terminalGUIobj->printConsole(str, clr, flag1, flag2);
|
||||||
|
myESPboy.mcp.digitalWrite(TFTchipSelectPin, HIGH);
|
||||||
|
digitalWrite(CC1101chipSelectPin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String getUserInputLocal(){
|
||||||
|
String inputLocal;
|
||||||
|
myESPboy.mcp.digitalWrite(TFTchipSelectPin, LOW);
|
||||||
|
digitalWrite(CC1101chipSelectPin, HIGH);
|
||||||
|
inputLocal = terminalGUIobj->getUserInput();
|
||||||
|
myESPboy.mcp.digitalWrite(TFTchipSelectPin, HIGH);
|
||||||
|
digitalWrite(CC1101chipSelectPin, LOW);
|
||||||
|
return (inputLocal);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void toggleDisplayModeLocal(uint8_t displayMode){
|
||||||
|
myESPboy.mcp.digitalWrite(TFTchipSelectPin, LOW);
|
||||||
|
digitalWrite(CC1101chipSelectPin, HIGH);
|
||||||
|
terminalGUIobj->toggleDisplayMode(displayMode);
|
||||||
|
myESPboy.mcp.digitalWrite(TFTchipSelectPin, HIGH);
|
||||||
|
digitalWrite(CC1101chipSelectPin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void doScrollLocal(){
|
||||||
|
myESPboy.mcp.digitalWrite(TFTchipSelectPin, LOW);
|
||||||
|
digitalWrite(CC1101chipSelectPin, HIGH);
|
||||||
|
terminalGUIobj->doScroll();
|
||||||
|
myESPboy.mcp.digitalWrite(TFTchipSelectPin, HIGH);
|
||||||
|
digitalWrite(CC1101chipSelectPin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t menuInitLocal(const char** menuLines, uint16_t menuLineColor, uint16_t menuUnselectedLineColor, uint16_t menuSelectionColor){
|
||||||
|
uint16_t menuItemSelected;
|
||||||
|
myESPboy.mcp.digitalWrite(TFTchipSelectPin, LOW);
|
||||||
|
digitalWrite(CC1101chipSelectPin, HIGH);
|
||||||
|
menuItemSelected = menuGUIobj->menuInit(menuLines, menuLineColor, menuUnselectedLineColor, menuSelectionColor);
|
||||||
|
myESPboy.mcp.digitalWrite(TFTchipSelectPin, HIGH);
|
||||||
|
digitalWrite(CC1101chipSelectPin, LOW);
|
||||||
|
return (menuItemSelected);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void drawDecodedSignal() {
|
||||||
|
String toPrint;
|
||||||
|
uint32_t *rawData;
|
||||||
|
uint32_t dec, lengthval, rssi, lqi;
|
||||||
|
|
||||||
|
int16_t databuffer[64]; // get a copy of the received timings before they are overwritten
|
||||||
|
int16_t numberoftimings = 2 * mySwitch.getReceivedBitlength() + 2;
|
||||||
|
if(numberoftimings > 64) numberoftimings = 64;
|
||||||
|
for (int8_t i = 0; i < numberoftimings; i++)
|
||||||
|
databuffer[i] = mySwitch.getReceivedRawdata()[i];
|
||||||
|
|
||||||
|
dec = mySwitch.getReceivedValue();
|
||||||
|
lengthval = mySwitch.getReceivedBitlength();
|
||||||
|
rssi = ELECHOUSE_cc1101.getRssi();
|
||||||
|
lqi = ELECHOUSE_cc1101.getLqi();
|
||||||
|
|
||||||
|
printConsoleLocal(" ", TFT_MAGENTA, 1, 1);
|
||||||
|
printConsoleLocal(" ", TFT_MAGENTA, 1, 0);
|
||||||
|
printConsoleLocal(F("DETECTED! DECODE:"), TFT_RED, 1, 0);
|
||||||
|
|
||||||
|
//toPrint = "RSSI/LQI: ";
|
||||||
|
//toPrint += (String)rssi;
|
||||||
|
//toPrint += "/";
|
||||||
|
//toPrint += (String)lqi;
|
||||||
|
//printConsoleLocal(toPrint, TFT_YELLOW, 1, 0);
|
||||||
|
|
||||||
|
toPrint="DEC: ";
|
||||||
|
toPrint+=(String)dec;
|
||||||
|
toPrint+=" (";
|
||||||
|
toPrint+= (String)lengthval;
|
||||||
|
toPrint+= " Bit)";
|
||||||
|
printConsoleLocal(toPrint, TFT_GREEN, 1, 0);
|
||||||
|
|
||||||
|
toPrint = String (dec,BIN);
|
||||||
|
while(toPrint.length()<lengthval) toPrint = "0" + toPrint;
|
||||||
|
toPrint="BIN: "+ toPrint;
|
||||||
|
printConsoleLocal(toPrint, TFT_GREEN, 1, 0);
|
||||||
|
|
||||||
|
toPrint="TRI: ";
|
||||||
|
toPrint+= bin2tri(dec);
|
||||||
|
printConsoleLocal(toPrint, TFT_GREEN, 1, 0);
|
||||||
|
|
||||||
|
toPrint="PROTOCOL: ";
|
||||||
|
toPrint+=(String)mySwitch.getReceivedProtocol();
|
||||||
|
printConsoleLocal(toPrint, TFT_RED, 1, 0);
|
||||||
|
printConsoleLocal(protDecode[mySwitch.getReceivedProtocol()], TFT_RED, 1, 0);
|
||||||
|
|
||||||
|
uint16_t databitsoffset = abs((int16_t)mySwitch.getReceivedLevelInFirstTiming() - (int16_t)mySwitch.getReceivedInverted());
|
||||||
|
uint32_t dataduration = 0;
|
||||||
|
for (uint16_t i = 1 + databitsoffset; i < numberoftimings - 1 + databitsoffset; i++)
|
||||||
|
dataduration += databuffer[i];
|
||||||
|
|
||||||
|
uint16_t averagebitduration = (int16_t)(0.5 + ((double)dataduration)/mySwitch.getReceivedBitlength());
|
||||||
|
uint16_t protocolratio = (uint16_t)(0.5 + ((double)(averagebitduration - mySwitch.getReceivedDelay())) / (double)mySwitch.getReceivedDelay());
|
||||||
|
|
||||||
|
toPrint = mySwitch.getReceivedDelay();
|
||||||
|
toPrint+=" {";
|
||||||
|
toPrint+= (databitsoffset==0) ?
|
||||||
|
(int16_t) (0.5 + (double)databuffer[2*mySwitch.getReceivedBitlength()+1]/(double)mySwitch.getReceivedDelay()):
|
||||||
|
(int16_t) (0.5 + (double)databuffer[0]/(double)mySwitch.getReceivedDelay());
|
||||||
|
toPrint+=" ";
|
||||||
|
toPrint+= (databitsoffset==0) ?
|
||||||
|
(int16_t) (0.5 + (double)databuffer[0]/(double)mySwitch.getReceivedDelay()):
|
||||||
|
(int16_t) (0.5 + (double)databuffer[1]/(double)mySwitch.getReceivedDelay());
|
||||||
|
toPrint+="} {";
|
||||||
|
toPrint+="1";
|
||||||
|
toPrint+=" ";
|
||||||
|
toPrint+=protocolratio;
|
||||||
|
toPrint+= "} ";
|
||||||
|
toPrint+=(mySwitch.getReceivedInverted()) ? "true" : "false";
|
||||||
|
printConsoleLocal(toPrint, TFT_RED, 1, 0);
|
||||||
|
|
||||||
|
toPrint="PULSE LEN: ";
|
||||||
|
toPrint+=(String)mySwitch.getReceivedDelay();
|
||||||
|
toPrint+=" ms";
|
||||||
|
printConsoleLocal(toPrint, TFT_WHITE, 1, 0);
|
||||||
|
|
||||||
|
toPrint="FIRST LEV: ";
|
||||||
|
if (mySwitch.getReceivedLevelInFirstTiming()) toPrint += "HIGH";
|
||||||
|
else toPrint+= "LOW";
|
||||||
|
printConsoleLocal(toPrint, TFT_WHITE, 1, 0);
|
||||||
|
|
||||||
|
toPrint="IS INV: ";
|
||||||
|
if (mySwitch.getReceivedInverted()) toPrint+="TRUE";
|
||||||
|
else toPrint+="FALSE";
|
||||||
|
printConsoleLocal(toPrint, TFT_WHITE, 1, 0);
|
||||||
|
|
||||||
|
printConsoleLocal(F("DATA: "), TFT_BLUE, 1, 0);
|
||||||
|
toPrint="";
|
||||||
|
rawData = mySwitch.getReceivedRawdata();
|
||||||
|
for (unsigned int i=0; i<= lengthval*2; i++) toPrint+=((String)rawData[i]+",");
|
||||||
|
toPrint = toPrint.substring(0,toPrint.length()-1);
|
||||||
|
printConsoleLocal(toPrint, TFT_BLUE, 1, 0);
|
||||||
|
|
||||||
|
printConsoleLocal("", TFT_BLACK, 1, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void readEEPROM(){
|
||||||
|
uint16_t quantityOfSignalsInEEPROM;
|
||||||
|
if (EEPROM.read(0) == EEPROMmagicNo[0] && EEPROM.read(1) == EEPROMmagicNo[1] && EEPROM.read(2) == EEPROMmagicNo[2]){
|
||||||
|
quantityOfSignalsInEEPROM = EEPROM.read(3);
|
||||||
|
for (uint16_t i=0; i<quantityOfSignalsInEEPROM; i++){
|
||||||
|
recordStoredVector.push_back(recordStored());
|
||||||
|
EEPROM.get(i*(sizeof(recordStored))+10, recordStoredVector.back());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
for (uint8_t i=0; i<4; i++)
|
||||||
|
EEPROM.write(i, EEPROMmagicNo[i]);
|
||||||
|
EEPROM.commit();}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void writeEEPROMall(){
|
||||||
|
uint16_t quantityOfSignalsToEEPROM;
|
||||||
|
quantityOfSignalsToEEPROM = recordStoredVector.size();
|
||||||
|
EEPROM.write(3, quantityOfSignalsToEEPROM);
|
||||||
|
for (uint16_t i=0; i<quantityOfSignalsToEEPROM; i++){
|
||||||
|
EEPROM.put(i*(sizeof(recordStored))+10, recordStoredVector[i]);}
|
||||||
|
EEPROM.commit();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void storeSignal(){
|
||||||
|
String signalName;
|
||||||
|
|
||||||
|
recordStoredVector.push_back(recordStored());
|
||||||
|
|
||||||
|
recordStoredVector.back().recordRepeatno = DEFAULT_SIGNAL_REPEAT_NUMBER;
|
||||||
|
recordStoredVector.back().recordProtocol = mySwitch.getReceivedProtocol();
|
||||||
|
recordStoredVector.back().recordPulselen = mySwitch.getReceivedDelay();
|
||||||
|
recordStoredVector.back().recordBits = mySwitch.getReceivedBitlength();
|
||||||
|
recordStoredVector.back().recordValue = mySwitch.getReceivedValue();
|
||||||
|
|
||||||
|
signalName = "(";
|
||||||
|
signalName += (String)mySwitch.getReceivedBitlength();
|
||||||
|
signalName += " bit) ";
|
||||||
|
signalName = signalName.substring(0,18);
|
||||||
|
signalName += (String)mySwitch.getReceivedValue();
|
||||||
|
memcpy(&recordStoredVector.back().recordName, signalName.c_str(), signalName.length()+1);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void setup(){
|
||||||
|
EEPROM.begin(2048);
|
||||||
|
readEEPROM();
|
||||||
|
|
||||||
|
myESPboy.begin("ESPboy Sub1GHz module");
|
||||||
|
myLED.begin(&myESPboy.mcp);
|
||||||
|
terminalGUIobj = new ESPboyTerminalGUI(&myESPboy.tft, &myESPboy.mcp);
|
||||||
|
menuGUIobj = new ESPboyMenuGUI(&myESPboy.tft, &myESPboy.mcp);
|
||||||
|
|
||||||
|
ELECHOUSE_cc1101.Init(); // must be set to initialize the cc1101!
|
||||||
|
//ELECHOUSE_cc1101.setRxBW(812.50); // Set the Receive Bandwidth in kHz. Value from 58.03 to 812.50. Default is 812.50 kHz.
|
||||||
|
ELECHOUSE_cc1101.setMHZ(433.92); //The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ.
|
||||||
|
mySwitch.enableReceive(CC1101riceivePin); // Receiver on interrupt 0 => that is pin #2
|
||||||
|
ELECHOUSE_cc1101.SetRx(); // set Receive on
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void listen_f(uint8_t storeFlag){
|
||||||
|
String str="";
|
||||||
|
uint8_t ledFlag = 1;
|
||||||
|
uint32_t counter;
|
||||||
|
|
||||||
|
mySwitch.resetAvailable();
|
||||||
|
toggleDisplayModeLocal(1);
|
||||||
|
|
||||||
|
while(!(myESPboy.getKeys()&PAD_ESC)){
|
||||||
|
|
||||||
|
if(myESPboy.getKeys()){
|
||||||
|
printConsoleLocal(F("Stop"), TFT_MAGENTA, 1, 1);
|
||||||
|
printConsoleLocal(F("LGT/RGT-scroll. B-exit"), TFT_MAGENTA, 1, 0);
|
||||||
|
doScrollLocal();
|
||||||
|
ledFlag = 1;
|
||||||
|
str="";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mySwitch.available()) {
|
||||||
|
myLED.setRGB(0,20,0);
|
||||||
|
ledFlag = 1;
|
||||||
|
counter=millis();
|
||||||
|
str="";
|
||||||
|
myESPboy.playTone(100,100);
|
||||||
|
drawDecodedSignal();
|
||||||
|
|
||||||
|
if (storeFlag){
|
||||||
|
if (!mySwitch.getReceivedProtocol()){
|
||||||
|
printConsoleLocal(F("Can't store UNKNOWN PROTOCOL"), TFT_RED, 1, 0);}
|
||||||
|
else
|
||||||
|
if(recordStoredVector.size()<MAX_RECORDS_TO_STORE){
|
||||||
|
storeSignal();
|
||||||
|
String toPrint = F("Signal stored. TOTAL: ");
|
||||||
|
toPrint += String (recordStoredVector.size());
|
||||||
|
toPrint +=F(" of ");
|
||||||
|
toPrint += (String)MAX_RECORDS_TO_STORE;
|
||||||
|
printConsoleLocal(toPrint, TFT_MAGENTA, 1, 0);}
|
||||||
|
else{
|
||||||
|
String toPrint = F("Can't store. Max reached ");
|
||||||
|
toPrint += (String)MAX_RECORDS_TO_STORE;
|
||||||
|
printConsoleLocal(toPrint, TFT_MAGENTA, 1, 0);}
|
||||||
|
}
|
||||||
|
mySwitch.resetAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(millis()-counter>2000){
|
||||||
|
myLED.setRGB(0,20,0);
|
||||||
|
counter=millis();
|
||||||
|
printConsoleLocal(str, TFT_MAGENTA, 1, 1);
|
||||||
|
str+=".";
|
||||||
|
if (str.length()>20) str="";
|
||||||
|
myLED.setRGB(0,0,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ledFlag){
|
||||||
|
ledFlag=0;
|
||||||
|
myLED.setRGB(0,0,0);
|
||||||
|
printConsoleLocal(F("Listening..."), TFT_MAGENTA, 1, 0);
|
||||||
|
printConsoleLocal(F(""), TFT_MAGENTA, 1, 0);
|
||||||
|
}
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
printConsoleLocal(F("Stop. Exit"), TFT_MAGENTA, 1, 1);
|
||||||
|
printConsoleLocal("", TFT_MAGENTA, 1, 0);
|
||||||
|
while(myESPboy.getKeys()) delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void send_f(uint16_t selectedSignal){
|
||||||
|
myLED.setRGB(20,0,0);
|
||||||
|
selectedSignal--;
|
||||||
|
toggleDisplayModeLocal(1);
|
||||||
|
String toPrint = F("Sending ");
|
||||||
|
toPrint += recordStoredVector[selectedSignal].recordName;
|
||||||
|
printConsoleLocal(toPrint, TFT_MAGENTA, 1, 0);
|
||||||
|
toPrint = (String)recordStoredVector[selectedSignal].recordRepeatno;
|
||||||
|
toPrint += " times";
|
||||||
|
printConsoleLocal(toPrint, TFT_MAGENTA, 1, 0);
|
||||||
|
|
||||||
|
ELECHOUSE_cc1101.SetTx(); // set Transmit on
|
||||||
|
mySwitch.disableReceive(); // Receiver off
|
||||||
|
mySwitch.enableTransmit(CC1101sendPin); // Transmit on
|
||||||
|
mySwitch.setRepeatTransmit(recordStoredVector[selectedSignal].recordRepeatno); // transmission repetitions.
|
||||||
|
mySwitch.setProtocol(recordStoredVector[selectedSignal].recordProtocol); // send Received Protocol
|
||||||
|
mySwitch.setPulseLength(recordStoredVector[selectedSignal].recordPulselen); // send Received Delay
|
||||||
|
mySwitch.send(recordStoredVector[selectedSignal].recordValue,recordStoredVector[selectedSignal].recordBits); // send Received value/bits
|
||||||
|
ELECHOUSE_cc1101.SetRx(); // set Receive on
|
||||||
|
mySwitch.disableTransmit(); // set Transmit off
|
||||||
|
mySwitch.enableReceive(CC1101riceivePin); // Receiver on
|
||||||
|
|
||||||
|
printConsoleLocal(F("DONE"), TFT_MAGENTA, 1, 0);
|
||||||
|
printConsoleLocal("", TFT_MAGENTA, 1, 0);
|
||||||
|
|
||||||
|
myLED.setRGB(0,0,0);
|
||||||
|
|
||||||
|
while (!myESPboy.getKeys())delay(10);
|
||||||
|
while (myESPboy.getKeys())delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void show_f(uint16_t selectedSignal) {
|
||||||
|
String toPrint;
|
||||||
|
|
||||||
|
selectedSignal--;
|
||||||
|
|
||||||
|
toPrint = F("Signal: ");
|
||||||
|
toPrint+=recordStoredVector[selectedSignal].recordName;
|
||||||
|
printConsoleLocal(toPrint, TFT_GREEN, 1, 0);
|
||||||
|
|
||||||
|
toPrint = F("Value: ");
|
||||||
|
toPrint += (String)recordStoredVector[selectedSignal].recordValue;
|
||||||
|
toPrint += (" (");
|
||||||
|
toPrint += (String)recordStoredVector[selectedSignal].recordBits;
|
||||||
|
toPrint += (" Bit)");
|
||||||
|
printConsoleLocal(toPrint, TFT_GREEN, 1, 0);
|
||||||
|
|
||||||
|
toPrint = F("Repeat No: ");
|
||||||
|
toPrint += (String)recordStoredVector[selectedSignal].recordRepeatno;
|
||||||
|
printConsoleLocal(toPrint, TFT_YELLOW, 1, 0);
|
||||||
|
|
||||||
|
toPrint = F("Pulse length: ");
|
||||||
|
toPrint += (String)recordStoredVector[selectedSignal].recordPulselen;
|
||||||
|
printConsoleLocal(toPrint, TFT_YELLOW, 1, 0);
|
||||||
|
|
||||||
|
toPrint = F("Protocol: ");
|
||||||
|
toPrint += (String)recordStoredVector[selectedSignal].recordProtocol;
|
||||||
|
printConsoleLocal(toPrint, TFT_YELLOW, 1, 0);
|
||||||
|
printConsoleLocal(protDecode[recordStoredVector[selectedSignal].recordProtocol], TFT_WHITE, 1, 0);
|
||||||
|
|
||||||
|
printConsoleLocal(F("DONE"), TFT_MAGENTA, 1, 0);
|
||||||
|
while (!myESPboy.getKeys())delay(10);
|
||||||
|
while (myESPboy.getKeys())delay(10);
|
||||||
|
printConsoleLocal("", TFT_MAGENTA, 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void listofstored_f(){
|
||||||
|
uint16_t selectedSignal;
|
||||||
|
uint8_t exitFlag;
|
||||||
|
uint8_t userInput;
|
||||||
|
String userInputName;
|
||||||
|
String toPrint;
|
||||||
|
|
||||||
|
gotolabel:
|
||||||
|
|
||||||
|
selectedSignal=0;
|
||||||
|
exitFlag=0;
|
||||||
|
userInput=0;
|
||||||
|
userInputName="";
|
||||||
|
|
||||||
|
for (uint16_t i=0; i<recordStoredVector.size(); i++){
|
||||||
|
menuList[i]=recordStoredVector[i].recordName;}
|
||||||
|
menuList[recordStoredVector.size()] = NULL;
|
||||||
|
|
||||||
|
selectedSignal = (menuInitLocal((const char **)menuList, TFT_YELLOW, TFT_BLUE, TFT_BLUE));
|
||||||
|
|
||||||
|
if(selectedSignal){
|
||||||
|
while(!exitFlag)
|
||||||
|
switch (menuInitLocal(menuRecord, TFT_YELLOW, TFT_BLUE, TFT_BLUE)){
|
||||||
|
case send_:
|
||||||
|
send_f(selectedSignal);
|
||||||
|
break;
|
||||||
|
case show_:
|
||||||
|
show_f(selectedSignal);
|
||||||
|
break;
|
||||||
|
case setrepeat_:
|
||||||
|
printConsoleLocal(F("Enter signal send repeat No"), TFT_MAGENTA, 1, 0);
|
||||||
|
toPrint = F("for ");
|
||||||
|
toPrint+=recordStoredVector[selectedSignal-1].recordName;
|
||||||
|
printConsoleLocal(toPrint, TFT_MAGENTA, 1, 0);
|
||||||
|
while (!userInput) userInput = getUserInputLocal().toInt();
|
||||||
|
if (userInput > DEFAULT_SIGNAL_REPEAT_NUMBER*10) userInput = DEFAULT_SIGNAL_REPEAT_NUMBER;
|
||||||
|
recordStoredVector[selectedSignal-1].recordRepeatno = userInput;
|
||||||
|
printConsoleLocal(F("DONE"), TFT_MAGENTA, 1, 0);
|
||||||
|
while (!myESPboy.getKeys())delay(10);
|
||||||
|
while (myESPboy.getKeys())delay(10);
|
||||||
|
printConsoleLocal("", TFT_MAGENTA, 1, 0);
|
||||||
|
break;
|
||||||
|
case rename_:
|
||||||
|
printConsoleLocal(F("Enter new name"), TFT_MAGENTA, 1, 0);
|
||||||
|
toPrint = F("for ");
|
||||||
|
toPrint+=recordStoredVector[selectedSignal-1].recordName;
|
||||||
|
printConsoleLocal(toPrint, TFT_MAGENTA, 1, 0);
|
||||||
|
while (!userInputName.length()) userInputName = getUserInputLocal();
|
||||||
|
userInputName = userInputName.substring(0,18);
|
||||||
|
memcpy(&recordStoredVector[selectedSignal-1].recordName, userInputName.c_str(), userInputName.length()+1);
|
||||||
|
printConsoleLocal(F("DONE"), TFT_MAGENTA, 1, 0);
|
||||||
|
while (!myESPboy.getKeys())delay(10);
|
||||||
|
while (myESPboy.getKeys())delay(10);
|
||||||
|
printConsoleLocal("", TFT_MAGENTA, 1, 0);
|
||||||
|
break;
|
||||||
|
case delete_:
|
||||||
|
recordStoredVector.erase(recordStoredVector.begin()+(selectedSignal-1));
|
||||||
|
while(myESPboy.getKeys()) delay(100);
|
||||||
|
if(!recordStoredVector.empty())goto gotolabel;
|
||||||
|
exitFlag=1;
|
||||||
|
break;
|
||||||
|
case cancel_:
|
||||||
|
while(myESPboy.getKeys()) delay(100);
|
||||||
|
goto gotolabel;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
while(myESPboy.getKeys()) delay(100);
|
||||||
|
goto gotolabel;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else while(myESPboy.getKeys()) delay(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop(){
|
||||||
|
switch (menuInitLocal(menuMain, TFT_YELLOW, TFT_BLUE, TFT_BLUE)){
|
||||||
|
case listen_:
|
||||||
|
listen_f(0);
|
||||||
|
break;
|
||||||
|
case listenstore_:
|
||||||
|
listen_f(1);
|
||||||
|
break;
|
||||||
|
case listofstored_:
|
||||||
|
if(!recordStoredVector.empty())
|
||||||
|
listofstored_f();
|
||||||
|
else{
|
||||||
|
toggleDisplayModeLocal(1);
|
||||||
|
printConsoleLocal(F("Records not found"), TFT_MAGENTA, 1, 0);
|
||||||
|
while (!myESPboy.getKeys())delay(10);
|
||||||
|
while (myESPboy.getKeys())delay(10);
|
||||||
|
printConsoleLocal("", TFT_MAGENTA, 1, 0);}
|
||||||
|
break;
|
||||||
|
case saveall_:
|
||||||
|
toggleDisplayModeLocal(1);
|
||||||
|
printConsoleLocal(F("Save to EEPROM..."), TFT_MAGENTA, 1, 0);
|
||||||
|
writeEEPROMall();
|
||||||
|
printConsoleLocal(F("DONE"), TFT_MAGENTA, 1, 0);
|
||||||
|
while (!myESPboy.getKeys())delay(10);
|
||||||
|
while (myESPboy.getKeys())delay(10);
|
||||||
|
printConsoleLocal("", TFT_MAGENTA, 1, 0);
|
||||||
|
break;
|
||||||
|
case clearall_:
|
||||||
|
toggleDisplayModeLocal(1);
|
||||||
|
printConsoleLocal(F("Clearing memory..."), TFT_MAGENTA, 1, 0);
|
||||||
|
recordStoredVector.clear();
|
||||||
|
printConsoleLocal(F("DONE"), TFT_MAGENTA, 1, 0);
|
||||||
|
while (!myESPboy.getKeys())delay(10);
|
||||||
|
while (myESPboy.getKeys())delay(10);
|
||||||
|
printConsoleLocal("", TFT_MAGENTA, 1, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
delay(150);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue