From a8a0e107817386733e023f7657301e0d64917a33 Mon Sep 17 00:00:00 2001 From: feeling Date: Mon, 15 Feb 2021 09:56:57 +0100 Subject: [PATCH] first --- .gitignore | 5 + .vscode/extensions.json | 7 + include/README | 39 ++++++ lib/README | 46 +++++++ platformio.ini | 19 +++ src/SeatalkApRemote.ino | 274 ++++++++++++++++++++++++++++++++++++++++ test/README | 11 ++ 7 files changed, 401 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 include/README create mode 100644 lib/README create mode 100644 platformio.ini create mode 100644 src/SeatalkApRemote.ino create mode 100644 test/README diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..e80666b --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} diff --git a/include/README b/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/include/README @@ -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 diff --git a/lib/README b/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/lib/README @@ -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 +#include + +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 diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..6cdb29a --- /dev/null +++ b/platformio.ini @@ -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 \ No newline at end of file diff --git a/src/SeatalkApRemote.ino b/src/SeatalkApRemote.ino new file mode 100644 index 0000000..0d3b84a --- /dev/null +++ b/src/SeatalkApRemote.ino @@ -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 +#include +#include +#include +#include + +// #include + +#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>= 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 diff --git a/test/README b/test/README new file mode 100644 index 0000000..b94d089 --- /dev/null +++ b/test/README @@ -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