init repo

This commit is contained in:
Niklas 2018-11-25 01:51:50 +01:00
commit 855b08e329
8 changed files with 485 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
.pio
.pioenvs
.piolibdeps
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json

67
.travis.yml Normal file
View File

@ -0,0 +1,67 @@
# Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline
# several times a day < https://docs.platformio.org/page/ci/index.html >
#
# Documentation:
#
# * Travis CI Embedded Builds with PlatformIO
# < https://docs.travis-ci.com/user/integration/platformio/ >
#
# * PlatformIO integration with Travis CI
# < https://docs.platformio.org/page/ci/travis.html >
#
# * User Guide for `platformio ci` command
# < https://docs.platformio.org/page/userguide/cmd_ci.html >
#
#
# Please choose one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above).
#
#
# Template #1: General project. Test it using existing `platformio.ini`.
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio run
#
# Template #2: The project is intended to be used as a library with examples.
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# env:
# - PLATFORMIO_CI_SRC=path/to/test/file.c
# - PLATFORMIO_CI_SRC=examples/file.ino
# - PLATFORMIO_CI_SRC=path/to/test/directory
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N

7
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

39
include/README Normal file
View File

@ -0,0 +1,39 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

46
lib/README Normal file
View File

@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

28
platformio.ini Normal file
View File

@ -0,0 +1,28 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[common]
env_default = nodemcuv2
upload_port = COM4
monitor_speed = 115200
lib_deps =
SPI
https://github.com/bartoszbielawski/LEDMatrixDriver
https://github.com/tzapu/WiFiManager
https://github.com/JoaoLopesF/RemoteDebug
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
monitor_speed = ${common.monitor_speed}
upload_port = ${common.upload_port}
lib_deps =
${common.lib_deps}

281
src/main.cpp Normal file
View File

@ -0,0 +1,281 @@
#include <Arduino.h>
#include <LEDMatrixDriver.hpp>
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <RemoteDebug.h>
extern "C"
{
#include "user_interface.h"
}
// This sketch draw marquee text on your LED matrix using the hardware SPI driver Library by Bartosz Bielawski.
// https://github.com/bartoszbielawski/LEDMatrixDriver
// Example written 16.06.2017 by Marko Oette, www.oette.info
// Define the ChipSelect pin for the led matrix (Dont use the SS or MISO pin of your Arduino/ESP!)
const uint8_t LEDMATRIX_CS_PIN = D1;
// Define LED Matrix dimensions (0-n) - eg: 32x8 = 31x7
const int LEDMATRIX_WIDTH = 63;
const int LEDMATRIX_HEIGHT = 7;
const int LEDMATRIX_SEGMENTS = 8;
// The LEDMatrixDriver class instance
LEDMatrixDriver lmd(LEDMATRIX_SEGMENTS, LEDMATRIX_CS_PIN);
signed int x = LEDMATRIX_WIDTH; // start top left
// This is the font definition. You can use http://gurgleapps.com/tools/matrix to create your own font or sprites.
// If you like the font feel free to use it. I created it myself and donate it to the public domain.
// 2018-11-10 - Adlerweb: Added &
byte font[95][8] = {
{0, 0, 0, 0, 0, 0, 0, 0}, // SPACE
{0x10, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18}, // EXCL !
{0x28, 0x28, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00}, // QUOT "
{0x00, 0x0a, 0x7f, 0x14, 0x28, 0xfe, 0x50, 0x00}, // #
{0x10, 0x38, 0x54, 0x70, 0x1c, 0x54, 0x38, 0x10}, // $
{0x00, 0x60, 0x66, 0x08, 0x10, 0x66, 0x06, 0x00}, // %
{0x00, 0x30, 0x48, 0x48, 0x48, 0x34, 0x48, 0x34}, // &
{0x00, 0x10, 0x18, 0x18, 0x08, 0x00, 0x00, 0x00}, // '
{0x02, 0x04, 0x08, 0x08, 0x08, 0x08, 0x08, 0x04}, // (
{0x40, 0x20, 0x10, 0x10, 0x10, 0x10, 0x10, 0x20}, // )
{0x00, 0x10, 0x54, 0x38, 0x10, 0x38, 0x54, 0x10}, // *
{0x00, 0x08, 0x08, 0x08, 0x7f, 0x08, 0x08, 0x08}, // +
{0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x08}, // COMMA ,
{0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00}, // -
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06}, // DOT .
{0x00, 0x04, 0x04, 0x08, 0x10, 0x20, 0x40, 0x40}, // /
{0x00, 0x38, 0x44, 0x4c, 0x54, 0x64, 0x44, 0x38}, // 0
{0x04, 0x0c, 0x14, 0x24, 0x04, 0x04, 0x04, 0x04}, // 1
{0x00, 0x30, 0x48, 0x04, 0x04, 0x38, 0x40, 0x7c}, // 2
{0x00, 0x38, 0x04, 0x04, 0x18, 0x04, 0x44, 0x38}, // 3
{0x00, 0x04, 0x0c, 0x14, 0x24, 0x7e, 0x04, 0x04}, // 4
{0x00, 0x7c, 0x40, 0x40, 0x78, 0x04, 0x04, 0x38}, // 5
{0x00, 0x38, 0x40, 0x40, 0x78, 0x44, 0x44, 0x38}, // 6
{0x00, 0x7c, 0x04, 0x04, 0x08, 0x08, 0x10, 0x10}, // 7
{0x00, 0x3c, 0x44, 0x44, 0x38, 0x44, 0x44, 0x78}, // 8
{0x00, 0x38, 0x44, 0x44, 0x3c, 0x04, 0x04, 0x78}, // 9
{0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00}, // :
{0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x08}, // ;
{0x00, 0x10, 0x20, 0x40, 0x80, 0x40, 0x20, 0x10}, // <
{0x00, 0x00, 0x7e, 0x00, 0x00, 0xfc, 0x00, 0x00}, // =
{0x00, 0x08, 0x04, 0x02, 0x01, 0x02, 0x04, 0x08}, // >
{0x00, 0x38, 0x44, 0x04, 0x08, 0x10, 0x00, 0x10}, // ?
{0x00, 0x30, 0x48, 0xba, 0xba, 0x84, 0x78, 0x00}, // @
{0x00, 0x1c, 0x22, 0x42, 0x42, 0x7e, 0x42, 0x42}, // A
{0x00, 0x78, 0x44, 0x44, 0x78, 0x44, 0x44, 0x7c}, // B
{0x00, 0x3c, 0x44, 0x40, 0x40, 0x40, 0x44, 0x7c}, // C
{0x00, 0x7c, 0x42, 0x42, 0x42, 0x42, 0x44, 0x78}, // D
{0x00, 0x78, 0x40, 0x40, 0x70, 0x40, 0x40, 0x7c}, // E
{0x00, 0x7c, 0x40, 0x40, 0x78, 0x40, 0x40, 0x40}, // F
{0x00, 0x3c, 0x40, 0x40, 0x5c, 0x44, 0x44, 0x78}, // G
{0x00, 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42}, // H
{0x00, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x7e}, // I
{0x00, 0x7e, 0x02, 0x02, 0x02, 0x02, 0x04, 0x38}, // J
{0x00, 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44}, // K
{0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7c}, // L
{0x00, 0x82, 0xc6, 0xaa, 0x92, 0x82, 0x82, 0x82}, // M
{0x00, 0x42, 0x42, 0x62, 0x52, 0x4a, 0x46, 0x42}, // N
{0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x44, 0x38}, // O
{0x00, 0x78, 0x44, 0x44, 0x48, 0x70, 0x40, 0x40}, // P
{0x00, 0x3c, 0x42, 0x42, 0x52, 0x4a, 0x44, 0x3a}, // Q
{0x00, 0x78, 0x44, 0x44, 0x78, 0x50, 0x48, 0x44}, // R
{0x00, 0x38, 0x40, 0x40, 0x38, 0x04, 0x04, 0x78}, // S
{0x00, 0x7e, 0x90, 0x10, 0x10, 0x10, 0x10, 0x10}, // T
{0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3e}, // U
{0x00, 0x42, 0x42, 0x42, 0x42, 0x44, 0x28, 0x10}, // V
{0x80, 0x82, 0x82, 0x92, 0x92, 0x92, 0x94, 0x78}, // W
{0x00, 0x42, 0x42, 0x24, 0x18, 0x24, 0x42, 0x42}, // X
{0x00, 0x44, 0x44, 0x28, 0x10, 0x10, 0x10, 0x10}, // Y
{0x00, 0x7c, 0x04, 0x08, 0x7c, 0x20, 0x40, 0xfe}, // Z
// (the font does not contain any lower case letters. you can add your own.)
}; // {}, //
// Marquee text
String text = "** MC8051.DE ** SENSORMODULE **";
// Marquee speed
signed int animDelay = 50;
os_timer_t animTimer;
bool animate = false;
RemoteDebug Debug;
LOCAL void animateCallback(void *arg)
{
animate = true;
}
/**
* This draws a sprite to the given position using the width and height supplied (usually 8x8)
*/
void drawSprite(byte *sprite, int x, int y, int width, int height)
{
// The mask is used to get the column bit from the sprite row
byte mask = B10000000;
for (int iy = 0; iy < height; iy++)
{
for (int ix = 0; ix < width; ix++)
{
lmd.setPixel(x + ix, y + iy, (bool)(sprite[iy] & mask));
// shift the mask by one pixel to the right
mask = mask >> 1;
}
// reset column mask
mask = B10000000;
}
}
/**
* This function draws a string of the given length to the given position.
*/
void drawString(char *text, int len, int x, int y)
{
for (int idx = 0; idx < len; idx++)
{
int c = text[idx] - 32;
// stop if char is outside visible area
if (x + idx * 8 > LEDMATRIX_WIDTH)
return;
// only draw if char is visible
if (8 + x + idx * 8 > 0)
drawSprite(font[c], x + idx * 8, y, 8, 8);
}
}
void draw(void)
{
signed int len = text.length(); //We later use it for negative stuff
char char_array[len + 1];
strcpy(char_array, text.c_str());
drawString(char_array, len, x, 0);
lmd.display();
x--;
Serial.print("X: ");
Serial.print(x);
Serial.print("L: ");
Serial.print(len);
Serial.print("C: ");
Serial.println((len * -8));
if (x < (len * -8))
x = LEDMATRIX_WIDTH;
}
void comm()
{
String lastCmd = Debug.getLastCommand();
char in = lastCmd.charAt(0);
switch (in)
{
case 's':
lastCmd.remove(0, 1);
text = lastCmd;
text.toUpperCase();
lmd.clear();
lmd.display();
x = LEDMATRIX_WIDTH;
if (animDelay <= 0)
x = 0;
draw();
Debug.printf("\nText changed to: %s\n", text.c_str());
Serial.print(F("\nText changed to: "));
Serial.println(text);
break;
case 'b':
lastCmd.remove(0, 1);
in = lastCmd.toInt();
in = constrain(in, 0, 10);
lmd.setIntensity(in);
Debug.printf("\nIntensity changed to: %d\n", in);
Serial.print(F("\nIntensity changed to: "));
Serial.println(in);
break;
case 'd':
lastCmd.remove(0, 1);
animDelay = lastCmd.toInt();
Debug.printf("\nAnimation delay changed to: %d\n", animDelay);
Serial.print(F("\nAnimation delay changed to: "));
Serial.println(animDelay);
os_timer_disarm(&animTimer);
os_timer_arm(&animTimer, animDelay, true);
break;
case 'f':
os_timer_disarm(&animTimer);
if (animDelay > 0)
animDelay *= -1;
Debug.printf("\nFreeze\n");
Serial.println(F("\nFreeze"));
break;
case 'm':
if (animDelay < 0)
animDelay *= -1;
os_timer_disarm(&animTimer);
os_timer_arm(&animTimer, animDelay, true);
Debug.printf("\nMove\n");
Serial.println(F("\nMove"));
break;
}
}
void setup()
{
// init the display
lmd.setEnabled(true);
lmd.setIntensity(0); // 0 = low, 10 = high
Serial.begin(115200);
Serial.println(F("\n\nLEDMatrix boot"));
WiFiManager wifiManager;
wifiManager.setConnectTimeout(60);
if (!wifiManager.autoConnect("Matrix-Control"))
{
Serial.println("failed to connect, we should reset as see if it connects");
delay(3000);
ESP.reset();
delay(5000);
}
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
Serial.println("local ip");
Serial.println(WiFi.localIP());
Debug.begin("matrixcontrol");
Debug.setResetCmdEnabled(true);
Debug.setHelpProjectsCmds("\nb<1-10>: Brightness | d<0-128>: Scroll delay | s<text>: Change Text | f: freeze | m: move\n");
Debug.setCallBackProjectCmds(&comm);
os_timer_setfn(&animTimer, (os_timer_func_t *)animateCallback, NULL);
os_timer_arm(&animTimer, animDelay, true);
animate = true;
}
void loop()
{
if (animate)
{
animate = false;
Serial.print('.');
draw();
}
Debug.handle();
}

11
test/README Normal file
View File

@ -0,0 +1,11 @@
This directory is intended for PIO Unit Testing and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PIO Unit Testing:
- https://docs.platformio.org/page/plus/unit-testing.html