Rename Directory
This commit is contained in:
parent
4fd8a0a761
commit
74c37e3747
63 changed files with 2 additions and 4 deletions
18
ESPMegaPRO-OS-SDK/src/.vscode/c_cpp_properties.json
vendored
Normal file
18
ESPMegaPRO-OS-SDK/src/.vscode/c_cpp_properties.json
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "windows-gcc-x64",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"compilerPath": "gcc",
|
||||
"cStandard": "${default}",
|
||||
"cppStandard": "${default}",
|
||||
"intelliSenseMode": "windows-gcc-x64",
|
||||
"compilerArgs": [
|
||||
""
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
24
ESPMegaPRO-OS-SDK/src/.vscode/launch.json
vendored
Normal file
24
ESPMegaPRO-OS-SDK/src/.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": true,
|
||||
"cwd": "d:/Git/ESPMegaPRO-v3-SDK/Template Project/src",
|
||||
"program": "d:/Git/ESPMegaPRO-v3-SDK/Template Project/src/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
58
ESPMegaPRO-OS-SDK/src/.vscode/settings.json
vendored
Normal file
58
ESPMegaPRO-OS-SDK/src/.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
{
|
||||
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||
"C_Cpp_Runner.cStandard": "",
|
||||
"C_Cpp_Runner.cppStandard": "",
|
||||
"C_Cpp_Runner.msvcBatchPath": "",
|
||||
"C_Cpp_Runner.useMsvc": false,
|
||||
"C_Cpp_Runner.warnings": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wpedantic",
|
||||
"-Wshadow",
|
||||
"-Wformat=2",
|
||||
"-Wcast-align",
|
||||
"-Wconversion",
|
||||
"-Wsign-conversion",
|
||||
"-Wnull-dereference"
|
||||
],
|
||||
"C_Cpp_Runner.msvcWarnings": [
|
||||
"/W4",
|
||||
"/permissive-",
|
||||
"/w14242",
|
||||
"/w14287",
|
||||
"/w14296",
|
||||
"/w14311",
|
||||
"/w14826",
|
||||
"/w44062",
|
||||
"/w44242",
|
||||
"/w14905",
|
||||
"/w14906",
|
||||
"/w14263",
|
||||
"/w44265",
|
||||
"/w14928"
|
||||
],
|
||||
"C_Cpp_Runner.enableWarnings": true,
|
||||
"C_Cpp_Runner.warningsAsError": false,
|
||||
"C_Cpp_Runner.compilerArgs": [],
|
||||
"C_Cpp_Runner.linkerArgs": [],
|
||||
"C_Cpp_Runner.includePaths": [],
|
||||
"C_Cpp_Runner.includeSearch": [
|
||||
"*",
|
||||
"**/*"
|
||||
],
|
||||
"C_Cpp_Runner.excludeSearch": [
|
||||
"**/build",
|
||||
"**/build/**",
|
||||
"**/.*",
|
||||
"**/.*/**",
|
||||
"**/.vscode",
|
||||
"**/.vscode/**"
|
||||
],
|
||||
"C_Cpp_Runner.useAddressSanitizer": false,
|
||||
"C_Cpp_Runner.useUndefinedSanitizer": false,
|
||||
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||
"C_Cpp_Runner.showCompilationTime": false,
|
||||
"C_Cpp_Runner.useLinkTimeOptimization": false
|
||||
}
|
26
ESPMegaPRO-OS-SDK/src/dump_fram.cpp.disabled
Normal file
26
ESPMegaPRO-OS-SDK/src/dump_fram.cpp.disabled
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <ESPMegaPRO_OOP.hpp>
|
||||
|
||||
ESPMegaPRO espmega = ESPMegaPRO();
|
||||
|
||||
void setup() {
|
||||
espmega.begin();
|
||||
//espmega.fram.write8(301, 25);
|
||||
// Dump FRAM to a prettified table
|
||||
for (int i = 0; i < 500; i++) {
|
||||
if (i % 16 == 0) {
|
||||
Serial.printf("\n%03d: ", i);
|
||||
}
|
||||
Serial.printf("%03d ", espmega.fram.read8(i));
|
||||
}
|
||||
|
||||
// Dump FRAM again but treat it as a long string
|
||||
Serial.printf("\n\n");
|
||||
for (int i = 0; i < 500; i++) {
|
||||
Serial.printf("%d: %c\n", i,espmega.fram.read8(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
espmega.loop();
|
||||
}
|
84
ESPMegaPRO-OS-SDK/src/i2c_scanner.cpp.disabled
Normal file
84
ESPMegaPRO-OS-SDK/src/i2c_scanner.cpp.disabled
Normal file
|
@ -0,0 +1,84 @@
|
|||
#include <ESPMegaPRO.h>
|
||||
// --------------------------------------
|
||||
// i2c_scanner
|
||||
//
|
||||
// Version 1
|
||||
// This program (or code that looks like it)
|
||||
// can be found in many places.
|
||||
// For example on the Arduino.cc forum.
|
||||
// The original author is not know.
|
||||
// Version 2, Juni 2012, Using Arduino 1.0.1
|
||||
// Adapted to be as simple as possible by Arduino.cc user Krodal
|
||||
// Version 3, Feb 26 2013
|
||||
// V3 by louarnold
|
||||
// Version 4, March 3, 2013, Using Arduino 1.0.3
|
||||
// by Arduino.cc user Krodal.
|
||||
// Changes by louarnold removed.
|
||||
// Scanning addresses changed from 0...127 to 1...119,
|
||||
// according to the i2c scanner by Nick Gammon
|
||||
// https://www.gammon.com.au/forum/?id=10896
|
||||
// Version 5, March 28, 2013
|
||||
// As version 4, but address scans now to 127.
|
||||
// A sensor seems to use address 120.
|
||||
// Version 6, November 27, 2015.
|
||||
// Added waiting for the Leonardo serial communication.
|
||||
//
|
||||
//
|
||||
// This sketch tests the standard 7-bit addresses
|
||||
// Devices with higher bit address might not be seen properly.
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Wire.setClock(50000);
|
||||
Wire.begin(14,33);
|
||||
|
||||
Serial.begin(115200); // Leonardo: wait for serial monitor
|
||||
Serial.println("\nI2C Scanner");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
byte error, address;
|
||||
int nDevices;
|
||||
|
||||
Serial.println("Scanning...");
|
||||
|
||||
nDevices = 0;
|
||||
for(address = 1; address < 127; address++ )
|
||||
{
|
||||
// The i2c_scanner uses the return value of
|
||||
// the Write.endTransmisstion to see if
|
||||
// a device did acknowledge to the address.
|
||||
Wire.beginTransmission(address);
|
||||
error = Wire.endTransmission();
|
||||
|
||||
if (error == 0)
|
||||
{
|
||||
Serial.print("I2C device found at address 0x");
|
||||
if (address<16)
|
||||
Serial.print("0");
|
||||
Serial.print(address,HEX);
|
||||
Serial.println(" !");
|
||||
|
||||
nDevices++;
|
||||
}
|
||||
else if (error==4)
|
||||
{
|
||||
Serial.print("Unknown error at address 0x");
|
||||
if (address<16)
|
||||
Serial.print("0");
|
||||
Serial.println(address,HEX);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
Serial.println("No I2C devices found\n");
|
||||
else
|
||||
Serial.println("done\n");
|
||||
|
||||
delay(5000); // wait 5 seconds for next scan
|
||||
}
|
505
ESPMegaPRO-OS-SDK/src/i2cmssc.cpp.disabled
Normal file
505
ESPMegaPRO-OS-SDK/src/i2cmssc.cpp.disabled
Normal file
|
@ -0,0 +1,505 @@
|
|||
//
|
||||
// FILE: MultiSpeedI2CScanner.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.17
|
||||
// PURPOSE: I2C scanner at different speeds
|
||||
// DATE: 2013-11-05
|
||||
// URL: https://github.com/RobTillaart/MultiSpeedI2CScanner
|
||||
// URL: http://forum.arduino.cc/index.php?topic=197360
|
||||
//
|
||||
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
// FOR INTERNAL I2C BUS NANO 33 BLE
|
||||
// #define WIRE_IMPLEMENT_WIRE1 1
|
||||
// extern TwoWire Wire1;
|
||||
|
||||
void I2Cscan();
|
||||
void displayHelp();
|
||||
void reset();
|
||||
void setAddress();
|
||||
void setSpeed(char sp);
|
||||
char getCommand();
|
||||
|
||||
|
||||
TwoWire *wire;
|
||||
|
||||
const char version[] = "0.1.16";
|
||||
|
||||
|
||||
// INTERFACE COUNT (TESTED TEENSY 3.5 AND ARDUINO DUE ONLY)
|
||||
int wirePortCount = 1;
|
||||
int selectedWirePort = 0;
|
||||
|
||||
|
||||
// scans devices from 50 to 800 KHz I2C speeds.
|
||||
// speed lower than 50 and above 400 can cause problems
|
||||
long speed[10] = { 100, 200, 300, 400 };
|
||||
int speeds;
|
||||
|
||||
int addressStart = 8;
|
||||
int addressEnd = 119;
|
||||
|
||||
|
||||
// DELAY BETWEEN TESTS
|
||||
// for delay between tests of found devices.
|
||||
#ifndef RESTORE_LATENCY
|
||||
#define RESTORE_LATENCY 5
|
||||
#endif
|
||||
|
||||
bool delayFlag = false;
|
||||
|
||||
|
||||
// MINIMIZE OUTPUT
|
||||
bool printAll = true;
|
||||
bool header = true;
|
||||
bool disableIRQ = false;
|
||||
|
||||
|
||||
// STATE MACHINE
|
||||
enum states {
|
||||
STOP, ONCE, CONT, HELP
|
||||
};
|
||||
states state = STOP;
|
||||
|
||||
|
||||
// TIMING
|
||||
uint32_t startScan;
|
||||
uint32_t stopScan;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// MAIN CODE
|
||||
//
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
Wire.begin(14,33);
|
||||
|
||||
#if defined WIRE_IMPLEMENT_WIRE1 || WIRE_INTERFACES_COUNT > 1
|
||||
Wire1.begin();
|
||||
wirePortCount++;
|
||||
#endif
|
||||
#if defined WIRE_IMPLEMENT_WIRE2 || WIRE_INTERFACES_COUNT > 2
|
||||
Wire2.begin();
|
||||
wirePortCount++;
|
||||
#endif
|
||||
#if defined WIRE_IMPLEMENT_WIRE3 || WIRE_INTERFACES_COUNT > 3
|
||||
Wire3.begin();
|
||||
wirePortCount++;
|
||||
#endif
|
||||
#if defined WIRE_IMPLEMENT_WIRE4 || WIRE_INTERFACES_COUNT > 4
|
||||
Wire4.begin();
|
||||
wirePortCount++;
|
||||
#endif
|
||||
#if defined WIRE_IMPLEMENT_WIRE5 || WIRE_INTERFACES_COUNT > 5
|
||||
Wire5.begin();
|
||||
wirePortCount++;
|
||||
#endif
|
||||
|
||||
wire = &Wire;
|
||||
|
||||
Serial.println();
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
yield();
|
||||
char command = getCommand();
|
||||
switch (command)
|
||||
{
|
||||
case '@':
|
||||
selectedWirePort = (selectedWirePort + 1) % wirePortCount;
|
||||
Serial.print(F("<I2C PORT=Wire"));
|
||||
Serial.print(selectedWirePort);
|
||||
Serial.println(F(">"));
|
||||
switch (selectedWirePort)
|
||||
{
|
||||
case 0:
|
||||
wire = &Wire;
|
||||
break;
|
||||
#if defined WIRE_IMPLEMENT_WIRE1 || WIRE_INTERFACES_COUNT > 1
|
||||
case 1:
|
||||
wire = &Wire1;
|
||||
break;
|
||||
#endif
|
||||
#if defined WIRE_IMPLEMENT_WIRE2 || WIRE_INTERFACES_COUNT > 2
|
||||
case 2:
|
||||
wire = &Wire2;
|
||||
break;
|
||||
#endif
|
||||
#if defined WIRE_IMPLEMENT_WIRE3 || WIRE_INTERFACES_COUNT > 3
|
||||
case 3:
|
||||
wire = &Wire3;
|
||||
break;
|
||||
#endif
|
||||
#if defined WIRE_IMPLEMENT_WIRE4 || WIRE_INTERFACES_COUNT > 4
|
||||
case 4:
|
||||
wire = &Wire4;
|
||||
break;
|
||||
#endif
|
||||
#if defined WIRE_IMPLEMENT_WIRE5 || WIRE_INTERFACES_COUNT > 5
|
||||
case 5:
|
||||
wire = &Wire5;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case 's':
|
||||
state = ONCE;
|
||||
break;
|
||||
case 'c':
|
||||
state = CONT;
|
||||
break;
|
||||
case 'd':
|
||||
delayFlag = !delayFlag;
|
||||
Serial.print(F("<delay="));
|
||||
Serial.println(delayFlag ? F("5>") : F("0>"));
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
// eeprom test TODO
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
header = !header;
|
||||
Serial.print(F("<header="));
|
||||
Serial.println(header ? F("yes>") : F("no>"));
|
||||
break;
|
||||
case 'p':
|
||||
printAll = !printAll;
|
||||
Serial.print(F("<print="));
|
||||
Serial.println(printAll ? F("all>") : F("found>"));
|
||||
break;
|
||||
case 'i':
|
||||
disableIRQ = !disableIRQ;
|
||||
Serial.print(F("<irq="));
|
||||
Serial.println(disableIRQ ? F("diabled>") : F("enabled>"));
|
||||
break;
|
||||
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '4':
|
||||
case '8':
|
||||
case '9':
|
||||
case 'M':
|
||||
case 'N':
|
||||
case 'O':
|
||||
case 'P':
|
||||
setSpeed(command);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
reset();
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
setAddress();
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
case '?':
|
||||
state = HELP;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case ONCE:
|
||||
I2Cscan();
|
||||
state = HELP;
|
||||
break;
|
||||
case CONT:
|
||||
I2Cscan();
|
||||
delay(1000);
|
||||
break;
|
||||
case HELP:
|
||||
displayHelp();
|
||||
state = STOP;
|
||||
break;
|
||||
case STOP:
|
||||
break;
|
||||
default: // ignore all non commands
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
void reset()
|
||||
{
|
||||
setSpeed('9');
|
||||
selectedWirePort = 0;
|
||||
addressStart = 8;
|
||||
addressEnd = 119;
|
||||
|
||||
delayFlag = false;
|
||||
printAll = true;
|
||||
header = true;
|
||||
disableIRQ = false;
|
||||
|
||||
state = STOP;
|
||||
|
||||
displayHelp();
|
||||
}
|
||||
|
||||
|
||||
void setAddress()
|
||||
{
|
||||
if (addressStart == 0)
|
||||
{
|
||||
addressStart = 8;
|
||||
addressEnd = 119;
|
||||
}
|
||||
else
|
||||
{
|
||||
addressStart = 0;
|
||||
addressEnd = 127;
|
||||
}
|
||||
Serial.print(F("<address Range = "));
|
||||
Serial.print(addressStart);
|
||||
Serial.print(F(".."));
|
||||
Serial.print(addressEnd);
|
||||
Serial.println(F(">"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void setSpeed(char sp)
|
||||
{
|
||||
switch (sp)
|
||||
{
|
||||
case '1':
|
||||
speed[0] = 100;
|
||||
speeds = 1;
|
||||
break;
|
||||
case '2':
|
||||
speed[0] = 200;
|
||||
speeds = 1;
|
||||
break;
|
||||
case '4':
|
||||
speed[0] = 400;
|
||||
speeds = 1;
|
||||
break;
|
||||
case '8':
|
||||
speed[0] = 800;
|
||||
speeds = 1;
|
||||
break;
|
||||
case '9': // limited to 400 KHz
|
||||
speeds = 8;
|
||||
for (int i = 1; i <= speeds; i++) speed[i - 1] = i * 50;
|
||||
break;
|
||||
case '0': // limited to 800 KHz
|
||||
speeds = 8;
|
||||
for (int i = 1; i <= speeds; i++) speed[i - 1] = i * 100;
|
||||
break;
|
||||
|
||||
// new in 0.1.10 - experimental
|
||||
case 'M':
|
||||
speed[0] = 1000;
|
||||
speeds = 1;
|
||||
break;
|
||||
case 'N':
|
||||
speed[0] = 3400;
|
||||
speeds = 1;
|
||||
break;
|
||||
case 'O':
|
||||
speed[0] = 5000;
|
||||
speeds = 1;
|
||||
break;
|
||||
case 'P':
|
||||
speed[0] = 100;
|
||||
speed[1] = 400;
|
||||
speed[2] = 1000;
|
||||
speed[3] = 3400;
|
||||
speed[4] = 5000;
|
||||
speeds = 5;
|
||||
break;
|
||||
}
|
||||
Serial.print("<speeds =");
|
||||
for (int i = 0; i < speeds; i++)
|
||||
{
|
||||
Serial.print(' ');
|
||||
Serial.print(speed[i]);
|
||||
}
|
||||
Serial.println(" >");
|
||||
}
|
||||
|
||||
|
||||
char getCommand()
|
||||
{
|
||||
char c = '\0';
|
||||
if (Serial.available())
|
||||
{
|
||||
c = Serial.read();
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
void displayHelp()
|
||||
{
|
||||
Serial.print(F("\nArduino MultiSpeed I2C Scanner - "));
|
||||
Serial.println(version);
|
||||
Serial.println();
|
||||
Serial.print(F("I2C ports: "));
|
||||
Serial.print(wirePortCount);
|
||||
Serial.print(F(" Current: Wire"));
|
||||
Serial.println(selectedWirePort);
|
||||
Serial.println(F("\t@ = toggle Wire - Wire1 .. Wire5 [e.g. TEENSY or Arduino Due]"));
|
||||
|
||||
Serial.println(F("Scan mode:"));
|
||||
Serial.println(F("\ts = single scan"));
|
||||
Serial.println(F("\tc = continuous scan - 1 second delay"));
|
||||
Serial.println(F("\tq = quit continuous scan"));
|
||||
Serial.println(F("\td = toggle latency delay between successful tests. 0 - 5 ms"));
|
||||
Serial.println(F("\ti = toggle enable/disable interrupts"));
|
||||
|
||||
Serial.println(F("Output:"));
|
||||
Serial.println(F("\tp = toggle printAll - printFound."));
|
||||
Serial.println(F("\th = toggle header - noHeader."));
|
||||
Serial.println(F("\ta = toggle address range, 0..127 - 8..119 (default)"));
|
||||
|
||||
Serial.println(F("Speeds:"));
|
||||
Serial.println(F("\t0 = 100..800 KHz - step 100 (warning - can block!!)"));
|
||||
Serial.println(F("\t1 = 100 KHz"));
|
||||
Serial.println(F("\t2 = 200 KHz"));
|
||||
Serial.println(F("\t4 = 400 KHz"));
|
||||
Serial.println(F("\t9 = 50..400 KHz - step 50 < DEFAULT >"));
|
||||
Serial.println();
|
||||
Serial.println(F("\t!! HIGH SPEEDS - WARNING - can block - not applicable for UNO"));
|
||||
Serial.println(F("\t8 = 800 KHz"));
|
||||
Serial.println(F("\tM = 1000 KHz"));
|
||||
Serial.println(F("\tN = 3400 KHz"));
|
||||
Serial.println(F("\tO = 5000 KHz"));
|
||||
Serial.println(F("\tP = 100 400 1000 3400 5000 KHz (standards)"));
|
||||
Serial.println(F("\n\tr = reset to startup defaults."));
|
||||
Serial.println(F("\t? = help - this page"));
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void I2Cscan()
|
||||
{
|
||||
startScan = millis();
|
||||
uint8_t count = 0;
|
||||
|
||||
if (disableIRQ)
|
||||
{
|
||||
noInterrupts();
|
||||
}
|
||||
|
||||
if (header)
|
||||
{
|
||||
Serial.print(F("TIME\tDEC\tHEX\t"));
|
||||
for (uint8_t s = 0; s < speeds; s++)
|
||||
{
|
||||
Serial.print(F("\t"));
|
||||
Serial.print(speed[s]);
|
||||
}
|
||||
Serial.println(F("\t[KHz]"));
|
||||
for (uint8_t s = 0; s < speeds + 5; s++)
|
||||
{
|
||||
Serial.print(F("--------"));
|
||||
}
|
||||
Serial.println();
|
||||
delay(100);
|
||||
}
|
||||
|
||||
for (uint8_t address = addressStart; address <= addressEnd; address++)
|
||||
{
|
||||
bool printLine = printAll;
|
||||
bool found[speeds];
|
||||
bool fnd = false;
|
||||
|
||||
for (uint8_t s = 0; s < speeds ; s++)
|
||||
{
|
||||
yield(); // keep ESP happy
|
||||
|
||||
#if ARDUINO < 158 && defined (TWBR)
|
||||
uint16_t PREV_TWBR = TWBR;
|
||||
TWBR = (F_CPU / (speed[s] * 1000) - 16) / 2;
|
||||
if (TWBR < 2)
|
||||
{
|
||||
Serial.println("ERROR: not supported speed");
|
||||
TWBR = PREV_TWBR;
|
||||
return;
|
||||
}
|
||||
#else
|
||||
wire->setClock(speed[s] * 1000UL);
|
||||
#endif
|
||||
wire->beginTransmission (address);
|
||||
found[s] = (wire->endTransmission () == 0);
|
||||
fnd |= found[s];
|
||||
// give device 5 millis
|
||||
if (fnd && delayFlag) delay(RESTORE_LATENCY);
|
||||
}
|
||||
|
||||
if (fnd) count++;
|
||||
printLine |= fnd;
|
||||
|
||||
if (printLine)
|
||||
{
|
||||
Serial.print(millis());
|
||||
Serial.print(F("\t"));
|
||||
Serial.print(address, DEC);
|
||||
Serial.print(F("\t0x"));
|
||||
if (address < 0x10) Serial.print(0, HEX);
|
||||
Serial.print(address, HEX);
|
||||
Serial.print(F("\t"));
|
||||
|
||||
for (uint8_t s = 0; s < speeds ; s++)
|
||||
{
|
||||
Serial.print(F("\t"));
|
||||
Serial.print(found[s] ? F("V") : F("."));
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// FOOTER
|
||||
if (header)
|
||||
{
|
||||
for (uint8_t s = 0; s < speeds + 5; s++)
|
||||
{
|
||||
Serial.print(F("--------"));
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
Serial.print(F("TIME\tDEC\tHEX\t"));
|
||||
for (uint8_t s = 0; s < speeds; s++)
|
||||
{
|
||||
Serial.print(F("\t"));
|
||||
Serial.print(speed[s]);
|
||||
}
|
||||
Serial.println(F("\t[KHz]"));
|
||||
}
|
||||
*/
|
||||
|
||||
stopScan = millis();
|
||||
if (header)
|
||||
{
|
||||
Serial.println();
|
||||
Serial.print(count);
|
||||
Serial.print(F(" devices found in "));
|
||||
Serial.print(stopScan - startScan);
|
||||
Serial.println(F(" milliseconds."));
|
||||
}
|
||||
|
||||
interrupts();
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
186
ESPMegaPRO-OS-SDK/src/main.cpp
Normal file
186
ESPMegaPRO-OS-SDK/src/main.cpp
Normal file
|
@ -0,0 +1,186 @@
|
|||
#include <ESPMegaProOS.hpp>
|
||||
#include <InternalDisplay.hpp>
|
||||
#include <ETH.h>
|
||||
#include <ClimateCard.hpp>
|
||||
|
||||
// #define FRAM_DEBUG
|
||||
// #define MQTT_DEBUG
|
||||
// #define WRITE_DEFAULT_NETCONF
|
||||
#define CLIMATE_CARD_ENABLE
|
||||
#define MQTT_CARD_REGISTER
|
||||
//#define DISPLAY_ENABLE
|
||||
#define WEB_SERVER_ENABLE
|
||||
|
||||
// Demo PLC firmware using the ESPMegaPRO OOP library
|
||||
|
||||
ESPMegaPRO espmega = ESPMegaPRO();
|
||||
|
||||
#ifdef CLIMATE_CARD_ENABLE
|
||||
// Climate Card
|
||||
const uint16_t irCode[15][4][4][1] = {0};
|
||||
const char *mode_names[] = {"off", "fan_only", "cool"};
|
||||
const char *fan_speed_names[] = {"auto", "low", "medium", "high"};
|
||||
|
||||
size_t getInfraredCode(uint8_t mode, uint8_t fan_speed, uint8_t temperature, const uint16_t **codePtr)
|
||||
{
|
||||
// Change the code pointer to point to the IR timing array
|
||||
*codePtr = &(irCode[mode][fan_speed][temperature][0]);
|
||||
return sizeof(irCode[mode][fan_speed][temperature]) / sizeof(uint16_t);
|
||||
}
|
||||
|
||||
AirConditioner ac = {
|
||||
.max_temperature = 30,
|
||||
.min_temperature = 16,
|
||||
.modes = 4,
|
||||
.mode_names = mode_names,
|
||||
.fan_speeds = 4,
|
||||
.fan_speed_names = fan_speed_names,
|
||||
.getInfraredCode = &getInfraredCode};
|
||||
|
||||
ClimateCard climateCard = ClimateCard(14, ac);
|
||||
#endif
|
||||
|
||||
void input_change_callback(uint8_t pin, uint8_t value)
|
||||
{
|
||||
Serial.print("Input change callback: ");
|
||||
Serial.print(pin);
|
||||
Serial.print(" ");
|
||||
Serial.println(value);
|
||||
}
|
||||
|
||||
void mqtt_callback(char *topic, char* payload)
|
||||
{
|
||||
Serial.print("MQTT Callback: ");
|
||||
Serial.print(topic);
|
||||
Serial.print(" ");
|
||||
Serial.println(payload);
|
||||
}
|
||||
|
||||
#ifdef WRITE_DEFAULT_NETCONF
|
||||
void setNetworkConfig()
|
||||
{
|
||||
NetworkConfig config = {
|
||||
.ip = {10, 16, 6, 213},
|
||||
.gateway = {10, 16, 6, 1},
|
||||
.subnet = {255, 255, 255, 0},
|
||||
.dns1 = {10, 192, 1, 1},
|
||||
.dns2 = {10, 192, 1, 1},
|
||||
.useStaticIp = true,
|
||||
.useWifi = false,
|
||||
.wifiUseAuth = false,
|
||||
};
|
||||
strcpy(config.ssid, "ssid");
|
||||
strcpy(config.password, "password");
|
||||
strcpy(config.hostname, "espmega");
|
||||
Serial.println("Setting network config");
|
||||
espmega.iot->setNetworkConfig(config);
|
||||
espmega.iot->saveNetworkConfig();
|
||||
}
|
||||
|
||||
void setMqttConfig()
|
||||
{
|
||||
MqttConfig config = {
|
||||
.mqtt_port = 1883,
|
||||
.mqtt_useauth = false};
|
||||
strcpy(config.mqtt_server, "192.168.0.26");
|
||||
strcpy(config.base_topic, "/espmegaoop");
|
||||
espmega.iot->setMqttConfig(config);
|
||||
espmega.iot->saveMqttConfig();
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
ESP_LOGI("Initializer", "Starting ESPMegaPRO OOP demo");
|
||||
espmega.begin();
|
||||
ESP_LOGI("Initializer", "Enabling IOT module");
|
||||
espmega.enableIotModule();
|
||||
ESP_LOGI("Initializer", "Enabling Ethernet");
|
||||
ETH.begin();
|
||||
ESP_LOGI("Initializer", "Binding Ethernet to IOT module");
|
||||
espmega.iot->bindEthernetInterface(Ð);
|
||||
#ifdef WRITE_DEFAULT_NETCONF
|
||||
setNetworkConfig();
|
||||
#else
|
||||
ESP_LOGI("Initializer", "Loading network config");
|
||||
espmega.iot->loadNetworkConfig();
|
||||
#endif
|
||||
ESP_LOGI("Initializer", "Connecting to network");
|
||||
espmega.iot->connectNetwork();
|
||||
#ifdef WRITE_DEFAULT_NETCONF
|
||||
setMqttConfig();
|
||||
#else
|
||||
ESP_LOGI("Initializer", "Loading MQTT config");
|
||||
espmega.iot->loadMqttConfig();
|
||||
#endif
|
||||
ESP_LOGI("Initializer", "Connecting to MQTT");
|
||||
espmega.iot->connectToMqtt();
|
||||
espmega.iot->registerMqttCallback(mqtt_callback);
|
||||
#ifdef MQTT_CARD_REGISTER
|
||||
ESP_LOGI("Initializer", "Registering cards 0");
|
||||
espmega.iot->registerCard(0);
|
||||
ESP_LOGI("Initializer", "Registering cards 1");
|
||||
espmega.iot->registerCard(1);
|
||||
#endif
|
||||
ESP_LOGI("Initializer", "Registering Input change callback");
|
||||
espmega.inputs.registerCallback(input_change_callback);
|
||||
#ifdef CLIMATE_CARD_ENABLE
|
||||
ESP_LOGI("Initializer", "Installing climate card");
|
||||
espmega.installCard(2, &climateCard);
|
||||
ESP_LOGI("Initializer", "Binding climate card to FRAM");
|
||||
climateCard.bindFRAM(&espmega.fram, 1001);
|
||||
ESP_LOGI("Initializer", "Loading climate card state from FRAM");
|
||||
climateCard.loadStateFromFRAM();
|
||||
ESP_LOGI("Initializer", "Enabling climate card FRAM autosave");
|
||||
climateCard.setFRAMAutoSave(true);
|
||||
ESP_LOGI("Initializer", "Registering cards 2");
|
||||
espmega.iot->registerCard(2);
|
||||
#endif
|
||||
#ifdef DISPLAY_ENABLE
|
||||
ESP_LOGI("Initializer", "Enabling internal display");
|
||||
espmega.enableInternalDisplay(&Serial);
|
||||
ESP_LOGI("Initializer", "Binding climate card to internal display");
|
||||
espmega.display->bindClimateCard(&climateCard);
|
||||
#endif
|
||||
#ifdef WEB_SERVER_ENABLE
|
||||
ESP_LOGI("Initializer", "Enabling web server");
|
||||
espmega.enableWebServer(80);
|
||||
espmega.webServer->setWebUsername("admin");
|
||||
espmega.webServer->setWebPassword("Passw0rd");
|
||||
espmega.webServer->saveCredentialsToFRAM();
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
espmega.loop();
|
||||
#ifdef FRAM_DEBUG
|
||||
// Every 20 seconds, dump FRAM 0-500 to serial
|
||||
static uint32_t last_fram_dump = 0;
|
||||
if (millis() - last_fram_dump >= 20000)
|
||||
{
|
||||
last_fram_dump = millis();
|
||||
Serial.println("Dumping FRAM");
|
||||
espmega.dumpFRAMtoSerial(0, 500);
|
||||
Serial.println("Dumping FRAM ASCII");
|
||||
espmega.dumpFRAMtoSerialASCII(0, 500);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Every 5 seconds, publish "I'm alive" to MQTT
|
||||
#ifdef MQTT_DEBUG
|
||||
static uint32_t last_mqtt_publish = 0;
|
||||
if (millis() - last_mqtt_publish >= 5000)
|
||||
{
|
||||
last_mqtt_publish = millis();
|
||||
espmega.iot->publish("/espmegai/alive", "true");
|
||||
}
|
||||
static uint32_t last_mqtt_status = 0;
|
||||
if (millis() - last_mqtt_status >= 1000)
|
||||
{
|
||||
last_mqtt_status = millis();
|
||||
Serial.print("MQTT Status: ");
|
||||
Serial.println(espmega.iot->mqttConnected() ? "Connected" : "Disconnected");
|
||||
}
|
||||
#endif
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue