first
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
7
.vscode/extensions.json
vendored
Normal file
7
.vscode/extensions.json
vendored
Normal 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
39
include/README
Normal 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
46
lib/README
Normal 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
|
||||
19
platformio.ini
Normal file
19
platformio.ini
Normal file
@@ -0,0 +1,19 @@
|
||||
; 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
|
||||
|
||||
[env:uno]
|
||||
platform = atmelavr
|
||||
board = uno
|
||||
framework = arduino
|
||||
; lib_extra_dirs = ~/Documents/Arduino/libraries
|
||||
|
||||
lib_extra_dirs = C:\PrivateLADE/code/Arduino/libraries
|
||||
|
||||
lib_deps = adafruit/Adafruit SSD1306@^2.4.0, adafruit/Adafruit BusIO@^1.6.0
|
||||
274
src/SeatalkApRemote.ino
Normal file
274
src/SeatalkApRemote.ino
Normal file
@@ -0,0 +1,274 @@
|
||||
/* Seatalk AutoPilot Remote Control
|
||||
*
|
||||
* Berreizeta 05-10-2016 18:14
|
||||
*
|
||||
The code for the RCSwitch is from http://dzrmo.wordpress.com/2012/07/08/remote-control-pt2272-for-android/
|
||||
The code for the Main Program is from http://www.vermontficks.org/pic.htm
|
||||
The authoritive Website is located here http://www.thomasknauf.de/seatalk.htm
|
||||
All code has been modified to work in this project.
|
||||
REMEMBER, USE AT YOUR OWN RISK!
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <RCSwitch.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
|
||||
// #include <Adafruit_I2CDevice.h>
|
||||
|
||||
#define DEBUG
|
||||
|
||||
/* General Definitions */
|
||||
#define SCREEN_WIDTH 128 // OLED display width, in pixels
|
||||
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
|
||||
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
|
||||
#define NO 0
|
||||
#define YES 1
|
||||
|
||||
/* Seatalk Definitions */
|
||||
#define LAMP_OFF 0x00
|
||||
#define LAMP_ON 0x0C
|
||||
#define PLUS_ONE 0x07
|
||||
#define MINUS_ONE 0x05
|
||||
#define PLUS_TEN 0x08
|
||||
#define MINUS_TEN 0x06
|
||||
#define STANDBY 0x02
|
||||
#define AUTO 0x01
|
||||
#define TRACK 0x03
|
||||
#define DISP 0x04
|
||||
#define TACK_MINUS 0x21
|
||||
#define TACK_PLUS 0x22
|
||||
#define WATCH 0x33
|
||||
|
||||
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||
|
||||
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
int RF433_GPIO = 1;
|
||||
int LED_GPIO = 6;
|
||||
int BUZZER_GPIO = 7;
|
||||
int SEATALK_TX_GPIO = 10;
|
||||
int SEATALK_RX_GPIO = 11;
|
||||
int cLampState;
|
||||
int HIGHH = 1;
|
||||
int LOWL = 0;
|
||||
unsigned int cX;
|
||||
unsigned long value;
|
||||
unsigned int x;
|
||||
|
||||
|
||||
// String autor = "Berreizeta";
|
||||
|
||||
|
||||
void displayWelcome() {
|
||||
#ifdef DEBUG
|
||||
Serial.println(F("DisplayWelcome"));
|
||||
#endif
|
||||
display.clearDisplay();
|
||||
display.setTextSize(2); // Normal 1:1 pixel scale
|
||||
display.setTextColor(SSD1306_WHITE); // Draw white text
|
||||
display.cp437(true); // Use full 256 char 'Code Page 437' font
|
||||
display.setCursor(15, 0);
|
||||
display.write("Starting");
|
||||
display.setCursor(20, 22);
|
||||
display.write("Seatalk");
|
||||
display.setCursor(10, 44);
|
||||
display.write("AP Remote");
|
||||
display.display();
|
||||
}
|
||||
|
||||
void displayNotice(String &displayMsg) {
|
||||
#ifdef DEBUG
|
||||
Serial.println(F("DisplayNotice"));
|
||||
#endif
|
||||
display.clearDisplay();
|
||||
|
||||
display.setTextSize(2); // Normal 1:1 pixel scale
|
||||
display.setTextColor(SSD1306_WHITE); // Draw white text
|
||||
display.cp437(true); // Use full 256 char 'Code Page 437' font
|
||||
|
||||
display.setCursor(20, 0);
|
||||
display.write("COMMAND: ");
|
||||
display.setCursor(20, 22);
|
||||
Serial.println("The string is : ["+displayMsg+"]");
|
||||
display.print(displayMsg);
|
||||
display.display();
|
||||
}
|
||||
|
||||
|
||||
void advertSetupComplete() {
|
||||
// Flash LED and BUZZER 3 times
|
||||
for ( cX = 0; cX < 3; cX++ ) {
|
||||
digitalWrite(LED_GPIO, HIGH);
|
||||
digitalWrite(BUZZER_GPIO, HIGH);
|
||||
delay(200);
|
||||
digitalWrite(LED_GPIO, LOW);
|
||||
digitalWrite(BUZZER_GPIO, LOW);
|
||||
delay(300);
|
||||
}
|
||||
}
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.println(F("Starting SETUP"));
|
||||
#endif
|
||||
|
||||
// Configure GPIO's
|
||||
pinMode(SEATALK_TX_GPIO, OUTPUT); // Seatalk Transmit
|
||||
pinMode(SEATALK_RX_GPIO, INPUT ); // Seatalk Receive
|
||||
pinMode(LED_GPIO, OUTPUT); // Status LED
|
||||
pinMode(BUZZER_GPIO, OUTPUT); // Status Buzzer
|
||||
|
||||
// Configure receiver
|
||||
mySwitch.enableReceive(RF433_GPIO);
|
||||
|
||||
|
||||
// Configure display
|
||||
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32 ; 0x3D for 128x64
|
||||
Serial.println(F("SSD1306 allocation failed"));
|
||||
for(;;); // Don't proceed, loop forever
|
||||
}
|
||||
|
||||
displayWelcome();
|
||||
delay(2000);
|
||||
advertSetupComplete();
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.println("Setup Finished");
|
||||
#endif
|
||||
}
|
||||
|
||||
void handleAction(byte operation, String &message, unsigned long value, short unsigned repeat=1) {
|
||||
digitalWrite(LED_GPIO, HIGH);
|
||||
digitalWrite(BUZZER_GPIO, HIGH);
|
||||
Serial.print( value );
|
||||
Serial.print(F(" - op:"));
|
||||
Serial.print( operation );
|
||||
Serial.print(F(" - "));
|
||||
Serial.println(message);
|
||||
|
||||
displayNotice(message);
|
||||
for(cX=0;cX<repeat;cX++) {
|
||||
SendKeystrokeMsg(operation);
|
||||
}
|
||||
|
||||
// DISPLAY ON SCREEN
|
||||
delay(1000);
|
||||
digitalWrite(LED_GPIO, LOW);
|
||||
digitalWrite(BUZZER_GPIO, LOW);
|
||||
}
|
||||
|
||||
void loop () {
|
||||
|
||||
delay(500); // programming delay
|
||||
digitalWrite(SEATALK_TX_GPIO, LOWL); // allow output to float
|
||||
|
||||
#ifdef DEBUG
|
||||
/*
|
||||
Serial.print(F("nop "));
|
||||
Serial.println(millis());
|
||||
*/
|
||||
#endif
|
||||
|
||||
if (mySwitch.available()) {
|
||||
value = mySwitch.getReceivedValue(); // get key fob value when key pressed
|
||||
#ifdef DEBUG
|
||||
unsigned int prt = mySwitch.getReceivedProtocol();
|
||||
unsigned int len = mySwitch.getReceivedBitlength();
|
||||
Serial.print(F("Received : "));
|
||||
Serial.print( value );
|
||||
Serial.print(F(" --- "));
|
||||
Serial.print( len );
|
||||
Serial.print(F(" bit, protocol : "));
|
||||
Serial.println(prt);
|
||||
#endif
|
||||
|
||||
String displayMsg;
|
||||
|
||||
switch (value) {
|
||||
case 21033: displayMsg="WATCH"; handleAction(WATCH, displayMsg, value); break; // WATCH
|
||||
case 21964: displayMsg="STANDBY"; handleAction(STANDBY, displayMsg, value); break; // STANDBY
|
||||
case 21000: displayMsg="TRACK"; handleAction(TRACK, displayMsg, value); break; // TRACK
|
||||
case 21001: displayMsg="AUTO"; handleAction(AUTO, displayMsg, value); break; // AUTO
|
||||
case 21811: displayMsg="MINUS_TEN"; handleAction(MINUS_TEN, displayMsg, value); // -10 DEGREE
|
||||
case 21965: displayMsg="PLUS_TEN"; handleAction(PLUS_TEN, displayMsg, value); break; // +10 DEGREE
|
||||
case 21763: displayMsg="MINUS_ONE"; handleAction(MINUS_ONE, displayMsg, value,5); break; // -5 DEGREE
|
||||
case 21772: displayMsg="PLUS_ONE"; handleAction(PLUS_ONE, displayMsg, value,5); break; // +5 DEGREE
|
||||
}
|
||||
|
||||
mySwitch.resetAvailable();
|
||||
}
|
||||
}
|
||||
|
||||
void SendKeystrokeMsg ( int cData ){
|
||||
int cError;
|
||||
#ifdef DEBUG
|
||||
Serial.print(F("Send Keystroke "));
|
||||
#endif
|
||||
do {
|
||||
#ifdef DEBUG
|
||||
Serial.print(F("."));
|
||||
#endif
|
||||
CheckBus(); // wait for bus to be idle
|
||||
digitalWrite(LED_GPIO, HIGH); // turn the LED on (HIGH is the voltage level)
|
||||
cError = SendByte ( NO, YES, 0x86 ); // command: keystroke
|
||||
cError = SendByte ( cError, NO, 0x21 ); // data: remote control, 1 extra byte (4 total)
|
||||
cError = SendByte ( cError, NO, cData ); // data:
|
||||
cError = SendByte ( cError, NO,~cData ); // data: inverted data
|
||||
delay(10); // LED visible delay
|
||||
digitalWrite(LED_GPIO, LOW); // turn the LED off (LOW is the voltage level)
|
||||
} while ( cError == YES ); // repeat if message was corrupted
|
||||
#ifdef DEBUG
|
||||
Serial.println("OK");
|
||||
#endif
|
||||
}
|
||||
|
||||
int SendByte ( int cError, int cCommand, int cData ){
|
||||
if ( cError != YES ) // if no error from previous
|
||||
{
|
||||
cError = SendBit ( cError, HIGHH ); // start bit (0V)
|
||||
for ( cX = 0; cX < 8; cX++ )
|
||||
{
|
||||
cError = SendBit ( cError, ~cData & 0x01 ); // LSB data bit
|
||||
cData >>= 1; // shift right
|
||||
}
|
||||
cError = SendBit ( cError, cCommand ? LOWL : HIGHH ); // set if command byte, clear if data byte
|
||||
cError = SendBit ( cError, LOWL ); // stop bit (+12V)
|
||||
}
|
||||
return ( cError );
|
||||
}
|
||||
|
||||
int SendBit ( int cError, int cBit ) {
|
||||
int cX; // No quitar int cX !!!
|
||||
// this is bit-banged code, it must be adjusted to give 208uS bit times (4800 baud)
|
||||
|
||||
if ( cError != YES ) { // if no error from previous
|
||||
digitalWrite(SEATALK_TX_GPIO, cBit); // send bit to output
|
||||
for ( cX = 0; cX < 7; cX++ ) { // check output bit periodically
|
||||
delayMicroseconds(24); // pauses for xx microseconds adjust
|
||||
if ( digitalRead(SEATALK_RX_GPIO) == !cBit ) { // check if output bit is corrupted by another talker
|
||||
return ( HIGHH ); // return collision error
|
||||
}
|
||||
}
|
||||
return ( LOWL ); // return no error, bit sucessfully sent
|
||||
}
|
||||
else {
|
||||
return ( HIGHH ); // simply return collision error from before
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CheckBus ( void ){
|
||||
// assumes output is floating to +12V for ~5mS
|
||||
for ( cX = 0; cX < 255; cX++ ) {
|
||||
// check if output bit is corrupted by another talker
|
||||
if ( digitalRead(SEATALK_RX_GPIO) == HIGHH ) {
|
||||
cX = 0; // reset count to zero
|
||||
}
|
||||
delayMicroseconds(7); // pauses for 7 microseconds
|
||||
}
|
||||
} // end loop
|
||||
11
test/README
Normal file
11
test/README
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
This directory is intended for PlatformIO 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 PlatformIO Unit Testing:
|
||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
||||
Reference in New Issue
Block a user