This commit is contained in:
2021-03-12 17:36:13 +01:00
parent 515acb426f
commit dbc9ea571a

View File

@@ -42,16 +42,19 @@
#define DEBUG #define DEBUG
String inputString = ""; // a String to hold incoming data String inputString = ""; // a String to hold incoming data
bool stringComplete = false; // whether the string is complete 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_Minus_1 PROGMEM = 13721111; // Change value_rfs to individual value_rfs programmed to remote control
const unsigned long Key_Plus_1 PROGMEM = 1111002; const unsigned long Key_Plus_1 PROGMEM = 13722222;
const unsigned long Key_Minus_10 PROGMEM = 1111003; const unsigned long Key_Minus_10 PROGMEM = 13723333;
const unsigned long Key_Plus_10 PROGMEM = 1111004; const unsigned long Key_Plus_10 PROGMEM = 13724444;
const unsigned long Key_Auto PROGMEM = 1111005; const unsigned long Key_Auto PROGMEM = 13725555;
const unsigned long Key_Standby PROGMEM = 1111006; 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 // 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_Lamp2[] = { 0x130, 0x00, 0x08 };
const PROGMEM uint16_t ST_Lamp3[] = { 0x130, 0x00, 0x0C }; const PROGMEM uint16_t ST_Lamp3[] = { 0x130, 0x00, 0x0C };
boolean blink = true; boolean blink = true;
unsigned long wind_timer = 0; // timer for AWS display unsigned long wind_timer = 0; // timer for AWS display
unsigned long beep_timer2 = 0; // timer to stop alarm sound 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 unsigned long beep_time = 0; // timer for beep duration
bool beep_status = false; bool beep_status = false;
uint32_t value_rf = 0;
char AWS[4];
RCSwitch mySwitch = RCSwitch(); RCSwitch mySwitch = RCSwitch();
SSD1306AsciiWire oled; SSD1306AsciiWire oled;
@@ -136,9 +142,28 @@ boolean sendDatagram(const uint16_t data[]) {
} }
void Display(char *s) { void Display(char *s) {
size_t tsize;
char dsp[12];
oled.clear(); oled.clear();
oled.setFont(Cooper19);
tsize = oled.strWidth(s);
oled.setCursor((oled.displayWidth()-tsize)/2, 0);
oled.println(s); 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) { void printByte(unsigned int data) {
@@ -218,7 +243,7 @@ void setup() {
oled.clear(); oled.clear();
oled.println("Starting"); 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 sendDatagram(ST_NMEA_BridgeID); // Send NMEA Seatakl BridgeID to make Seatalk to Seatalk NG converter happy
#ifdef DEBUG #ifdef DEBUG
SerialSoft.println(F("Setup Complete")); 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 routine is run between each time loop() runs, so using delay inside loop can
delay response. Multiple bytes of data may be available. delay response. Multiple bytes of data may be available.
*/ */
void serialEvent() { void serialEvent() { // NOT WORKING IN SOFT SERIAL
while (SerialSoft.available()) { while (SerialSoft.available()) {
// get the new byte: // get the new byte:
SerialSoft.println("received from serial");
char inChar = (char)SerialSoft.read(); char inChar = (char)SerialSoft.read();
// add it to the inputString: // add it to the inputString:
if ((inChar != '\n') && (inChar != '\r')) inputString += inChar; if ((inChar != '\n') && (inChar != '\r')) inputString += inChar;
@@ -271,8 +297,9 @@ void serialEvent() {
void loop() { void loop() {
char AWS[4] = ""; AWS[0] = '\0';
unsigned long value = 0; // uint32_t value_rf = 0;
value_rf = 0;
if (millis() > wind_timer + 2000 ) { if (millis() > wind_timer + 2000 ) {
// Display("No Wdata"); // Show --- after about two seconds when no wind data is received // Display("No Wdata"); // Show --- after about two seconds when no wind data is received
@@ -298,7 +325,7 @@ void loop() {
} }
if (mySwitch.available()) { if (mySwitch.available()) {
value = mySwitch.getReceivedValue(); value_rf = mySwitch.getReceivedValue();
mySwitch.resetAvailable(); mySwitch.resetAvailable();
} }
@@ -307,31 +334,31 @@ void loop() {
if (stringComplete) { if (stringComplete) {
// Compare string received from SerialSoft // Compare string received from SerialSoft
if(inputString == "-1" ) value = Key_Minus_1; if(inputString == "-1" ) value_rf = Key_Minus_1;
if(inputString == "+1" ) value = Key_Plus_1; if(inputString == "+1" ) value_rf = Key_Plus_1;
if(inputString == "-10") value = Key_Minus_10; if(inputString == "-10") value_rf = Key_Minus_10;
if(inputString == "+10") value = Key_Plus_10; if(inputString == "+10") value_rf = Key_Plus_10;
if(inputString == "A" ) value = Key_Auto; if(inputString == "A" ) value_rf = Key_Auto;
if(inputString == "S" ) value = Key_Standby; if(inputString == "S" ) value_rf = Key_Standby;
// clear the string and reset status // clear the string and reset status
inputString = ""; inputString = "";
stringComplete = false; stringComplete = false;
} }
if (value > 0 && millis() > key_time + KEY_DELAY) { if (value_rf > 0 && millis() > key_time + KEY_DELAY) {
#ifdef DEBUG #ifdef DEBUG
oled.clear(); oled.clear();
oled.println("Value : "); oled.println("Value : ");
oled.println(value); oled.println(value_rf);
SerialSoft.print(F("rf_code ")); SerialSoft.println(value); SerialSoft.print(F("rf_code ")); SerialSoft.println(value_rf);
#endif #endif
key_time = millis(); // Remember time of last key received key_time = millis(); // Remember time of last key received
digitalWrite(PIN_LED, blink); // LED on/off digitalWrite(PIN_LED, blink); // LED on/off
blink = !blink; // Toggle LED to show received key blink = !blink; // Toggle LED to show received key
switch(value) { switch(value_rf) {
case Key_Minus_1: case Key_Minus_1:
Display("min1"); Display("min1");
sendDatagram(ST_Minus_1); sendDatagram(ST_Minus_1);
@@ -366,22 +393,22 @@ void loop() {
BeepOn(); BeepOn();
} }
break; break;
case 97: case Key_Lamp0:
Display("Lamp 0"); Display("Lamp 0");
sendDatagram(ST_Lamp0); sendDatagram(ST_Lamp0);
BeepOn(); BeepOn();
break; break;
case 98: case Key_Lamp1:
Display("Lamp 1"); Display("Lamp 1");
sendDatagram(ST_Lamp1); sendDatagram(ST_Lamp1);
BeepOn(); BeepOn();
break; break;
case 99: case Key_Lamp2:
Display("Lamp 2"); Display("Lamp 2");
sendDatagram(ST_Lamp2); sendDatagram(ST_Lamp2);
BeepOn(); BeepOn();
break; break;
case 100: case Key_Lamp3:
Display("Lamp 3"); Display("Lamp 3");
sendDatagram(ST_Lamp3); sendDatagram(ST_Lamp3);
BeepOn(); BeepOn();