From dbc9ea571a170a62c00dddf658956a15d057373d Mon Sep 17 00:00:00 2001 From: feeling Date: Fri, 12 Mar 2021 17:36:13 +0100 Subject: [PATCH] 1 --- .../ArduinoPilotNano433WindNGSoftSerial.ino | 83 ++++++++++++------- 1 file changed, 55 insertions(+), 28 deletions(-) diff --git a/AP-Remote-Software/ArduinoPilotNano433WindNGSoftSerial/ArduinoPilotNano433WindNGSoftSerial.ino b/AP-Remote-Software/ArduinoPilotNano433WindNGSoftSerial/ArduinoPilotNano433WindNGSoftSerial.ino index cc2de53..395f5c0 100644 --- a/AP-Remote-Software/ArduinoPilotNano433WindNGSoftSerial/ArduinoPilotNano433WindNGSoftSerial.ino +++ b/AP-Remote-Software/ArduinoPilotNano433WindNGSoftSerial/ArduinoPilotNano433WindNGSoftSerial.ino @@ -42,16 +42,19 @@ #define DEBUG - String inputString = ""; // a String to hold incoming data bool stringComplete = false; // whether the string is complete -const unsigned long Key_Minus_1 PROGMEM = 1111001; // Change values to individual values programmed to remote control -const unsigned long Key_Plus_1 PROGMEM = 1111002; -const unsigned long Key_Minus_10 PROGMEM = 1111003; -const unsigned long Key_Plus_10 PROGMEM = 1111004; -const unsigned long Key_Auto PROGMEM = 1111005; -const unsigned long Key_Standby PROGMEM = 1111006; +const unsigned long Key_Minus_1 PROGMEM = 13721111; // Change value_rfs to individual value_rfs programmed to remote control +const unsigned long Key_Plus_1 PROGMEM = 13722222; +const unsigned long Key_Minus_10 PROGMEM = 13723333; +const unsigned long Key_Plus_10 PROGMEM = 13724444; +const unsigned long Key_Auto PROGMEM = 13725555; +const unsigned long Key_Standby PROGMEM = 13726666; +const unsigned long Key_Lamp0 PROGMEM = 13727777; +const unsigned long Key_Lamp1 PROGMEM = 13728888; +const unsigned long Key_Lamp2 PROGMEM = 13729999; +const unsigned long Key_Lamp3 PROGMEM = 13720000; // Seatalk datagrams @@ -71,7 +74,6 @@ const PROGMEM uint16_t ST_Lamp1[] = { 0x130, 0x00, 0x04 }; const PROGMEM uint16_t ST_Lamp2[] = { 0x130, 0x00, 0x08 }; const PROGMEM uint16_t ST_Lamp3[] = { 0x130, 0x00, 0x0C }; - boolean blink = true; unsigned long wind_timer = 0; // timer for AWS display unsigned long beep_timer2 = 0; // timer to stop alarm sound @@ -81,6 +83,10 @@ unsigned long key_time = 0; // time of last key detected unsigned long beep_time = 0; // timer for beep duration bool beep_status = false; +uint32_t value_rf = 0; +char AWS[4]; + + RCSwitch mySwitch = RCSwitch(); SSD1306AsciiWire oled; @@ -136,9 +142,28 @@ boolean sendDatagram(const uint16_t data[]) { } void Display(char *s) { + size_t tsize; + char dsp[12]; oled.clear(); + oled.setFont(Cooper19); + + tsize = oled.strWidth(s); + oled.setCursor((oled.displayWidth()-tsize)/2, 0); oled.println(s); - wind_timer = millis(); + + snprintf(dsp, sizeof dsp, "AWS: %s", AWS); + tsize = oled.strWidth(dsp); + oled.setCursor((oled.displayWidth()-tsize)/2, 20); + oled.println(dsp); + + oled.setFont(X11fixed7x14); + // ultoa(value_rf, dsp, 8); + snprintf(dsp, sizeof dsp, "%" PRIu32, value_rf); + + tsize = oled.strWidth(dsp); + oled.setCursor((oled.displayWidth()-tsize)/2, 40); + oled.println(dsp); + } void printByte(unsigned int data) { @@ -218,7 +243,7 @@ void setup() { oled.clear(); oled.println("Starting"); - mySwitch.enableReceive(0); // RF Receiver on inerrupt 4 => that is pin 7 on Micro + mySwitch.enableReceive(PIN_RF_433); // RF Receiver on inerrupt 4 => that is pin 7 on Micro OR pin2 on Nano sendDatagram(ST_NMEA_BridgeID); // Send NMEA Seatakl BridgeID to make Seatalk to Seatalk NG converter happy #ifdef DEBUG SerialSoft.println(F("Setup Complete")); @@ -255,9 +280,10 @@ void BeepOff(void) { routine is run between each time loop() runs, so using delay inside loop can delay response. Multiple bytes of data may be available. */ -void serialEvent() { +void serialEvent() { // NOT WORKING IN SOFT SERIAL while (SerialSoft.available()) { // get the new byte: + SerialSoft.println("received from serial"); char inChar = (char)SerialSoft.read(); // add it to the inputString: if ((inChar != '\n') && (inChar != '\r')) inputString += inChar; @@ -271,8 +297,9 @@ void serialEvent() { void loop() { - char AWS[4] = ""; - unsigned long value = 0; + AWS[0] = '\0'; +// uint32_t value_rf = 0; + value_rf = 0; if (millis() > wind_timer + 2000 ) { // Display("No Wdata"); // Show --- after about two seconds when no wind data is received @@ -298,7 +325,7 @@ void loop() { } if (mySwitch.available()) { - value = mySwitch.getReceivedValue(); + value_rf = mySwitch.getReceivedValue(); mySwitch.resetAvailable(); } @@ -307,31 +334,31 @@ void loop() { if (stringComplete) { // Compare string received from SerialSoft - if(inputString == "-1" ) value = Key_Minus_1; - if(inputString == "+1" ) value = Key_Plus_1; - if(inputString == "-10") value = Key_Minus_10; - if(inputString == "+10") value = Key_Plus_10; - if(inputString == "A" ) value = Key_Auto; - if(inputString == "S" ) value = Key_Standby; + if(inputString == "-1" ) value_rf = Key_Minus_1; + if(inputString == "+1" ) value_rf = Key_Plus_1; + if(inputString == "-10") value_rf = Key_Minus_10; + if(inputString == "+10") value_rf = Key_Plus_10; + if(inputString == "A" ) value_rf = Key_Auto; + if(inputString == "S" ) value_rf = Key_Standby; // clear the string and reset status inputString = ""; stringComplete = false; } - if (value > 0 && millis() > key_time + KEY_DELAY) { + if (value_rf > 0 && millis() > key_time + KEY_DELAY) { #ifdef DEBUG oled.clear(); oled.println("Value : "); - oled.println(value); - SerialSoft.print(F("rf_code ")); SerialSoft.println(value); + oled.println(value_rf); + SerialSoft.print(F("rf_code ")); SerialSoft.println(value_rf); #endif key_time = millis(); // Remember time of last key received digitalWrite(PIN_LED, blink); // LED on/off blink = !blink; // Toggle LED to show received key - switch(value) { + switch(value_rf) { case Key_Minus_1: Display("min1"); sendDatagram(ST_Minus_1); @@ -366,22 +393,22 @@ void loop() { BeepOn(); } break; - case 97: + case Key_Lamp0: Display("Lamp 0"); sendDatagram(ST_Lamp0); BeepOn(); break; - case 98: + case Key_Lamp1: Display("Lamp 1"); sendDatagram(ST_Lamp1); BeepOn(); break; - case 99: + case Key_Lamp2: Display("Lamp 2"); sendDatagram(ST_Lamp2); BeepOn(); break; - case 100: + case Key_Lamp3: Display("Lamp 3"); sendDatagram(ST_Lamp3); BeepOn();