Browse Source

small changes for auto programming

Willie 3 years ago
parent
commit
341ab2615e
2 changed files with 34 additions and 26 deletions
  1. 16 18
      SPS/SPS.ino
  2. 18 8
      SPS/serialprg.ino

+ 16 - 18
SPS/SPS.ino

@@ -1,5 +1,9 @@
 /*
   SPS System mit dem Arduino.
+  Version 0.12.3
+  10.06.2021
+  - adding auto programming feature for the SPS Emulator
+  
   Version 0.12.2
   07.06.2021
   - bug with servo in 4-bit mode, evaluate the full 8 bit.
@@ -93,10 +97,10 @@
 #ifdef __AVR_ATmega328P__
 //#define SPS_USE_DISPLAY
 //#define SPS_RECEIVER
-#define SPS_ENHANCEMENT
-#define SPS_SERIAL_PRG
-#define SPS_SERVO
-#define SPS_TONE
+//#define SPS_ENHANCEMENT
+//#define SPS_SERIAL_PRG
+//#define SPS_SERVO
+//#define SPS_TONE
 #endif
 
 #ifdef __AVR_ATtiny84__
@@ -279,13 +283,9 @@ void readProgram() {
     byte value = readbyte(addr);
 
 #ifdef debug
-    dbgOut2(value, HEX);
-    if (((addr + 1) % 16) == 0) {
-      dbgOutLn();
-    }
-    else {
-      dbgOut(",");
-    }
+    dbgOutLn();
+    dbgOut2(addr, HEX);
+    dbgOut(": ");
 #endif
 
     if (value == 0xFF) {
@@ -295,10 +295,8 @@ void readProgram() {
     byte cmd = (value & 0xF0);
     byte data = (value & 0x0F);
 
-    dbgOut("(");
-    dbgOut2(cmd, HEX);
+    dbgOut2(cmd>>4, HEX);
     dbgOut2(data, HEX);
-    dbgOut(")");
 
     if (cmd == CALL_SUB) {
       if (data >= 8) {
@@ -309,22 +307,22 @@ void readProgram() {
 #ifdef SPS_SERVO
     if ((cmd == IS_A) && (data == 0x0B)) {
       if (!servo1.attached()) {
-        dbgOutLn("attach Srv1");
+        dbgOutLn(": attach Srv1");
         servo1.attach(SERVO_1);
       }
     } else if ((cmd == CMD_BYTE) && (data == 0x06)) {
       if (!servo1.attached()) {
-        dbgOutLn("attach Srv1");
+        dbgOutLn(": attach Srv1");
         servo1.attach(SERVO_1);
       }
     } else if ((cmd == IS_A) && (data == 0x0C)) {
       if (!servo2.attached()) {
-        dbgOutLn("attach Srv2");
+        dbgOutLn(": attach Srv2");
         servo2.attach(SERVO_2);
       }
     } else if ((cmd == CMD_BYTE) && (data == 0x07)) {
       if (!servo2.attached()) {
-        dbgOutLn("attach Srv2");
+        dbgOutLn(": attach Srv2");
         servo2.attach(SERVO_2);
       }
     }

+ 18 - 8
SPS/serialprg.ino

@@ -17,6 +17,20 @@ void initSerialPrg() {
   Serial.println();
 }
 
+void sendHeader() {
+#ifdef __AVR_ATtiny84__
+  Serial.println("TinySPS");
+#endif
+#ifdef __AVR_ATmega328P__
+  Serial.println("ArduinoSPS");
+#endif
+  Serial.print("max prg size:");
+  Serial.print(STORESIZE, HEX);
+  Serial.println();
+  Serial.println("waiting for command:");
+  Serial.println("w: write HEX file, r: read EPPROM, e: end");  
+}
+
 void serialPrg() {
   byte value;
   bool endOfPrg = false;
@@ -28,14 +42,7 @@ void serialPrg() {
   byte type;
 
   addr = 0;
-#ifdef __AVR_ATtiny84__
-  Serial.println("TinySPS");
-#endif
-#ifdef __AVR_ATmega328P__
-  Serial.println("ArduinoSPS");
-#endif
-  Serial.println("waiting for command:");
-  Serial.println("w: write HEX file, r: read EPPROM, e: end");
+  sendHeader();
   while (!endOfPrg) {
     while (Serial.available() > 0) {
       // look for the next valid integer in the incoming serial stream:
@@ -184,6 +191,9 @@ void serialPrg() {
         // end of programm
         endOfPrg = true;
       }
+      if (myChar == 'h') {
+        sendHeader();
+      }
     }
   }
   Serial.println("end");