Ver código fonte

new programming feature.

Wilfried Klaas 6 anos atrás
pai
commit
51a96c1ea3
4 arquivos alterados com 269 adições e 93 exclusões
  1. 24 0
      README.md
  2. 26 0
      SPS/SPS.ino
  3. 84 93
      SPS/prgmode.ino
  4. 135 0
      SPS/prgmode.ino.old

+ 24 - 0
README.md

@@ -1,6 +1,30 @@
 # ArduinoSPS
 
 A TPS Variant for the arduino with some major enhancments.
+**Version 0.10**
+  18.11.2018 WKLA
+  - new standard programming mode
+  i added a new programming mode for the default programming, because i thing the old one was a little bit clumsy.
+  the new one has a nicer interface, as you now always know where you are.
+  Starting with PRG pushed after Reset.
+  as a result, all LEDs will shortly blink
+  now you are in programming mode.
+  * the D1 LED will blink
+  * the higher nibble of the address will be shown
+  * the D2 LED will blink
+  * the lower nibble of the address will be shown
+  * the D3 LED will blink
+  * the command part (high nibble) will be shown
+  * with SEL you can step thru all commands
+  * PRG will save the command
+  * the D4 LED will blink 
+  * the data part (low nibble) will be shown
+  * with SEL you can step thru all datas
+  * PRG will save the data
+  * if the new value has been changed, all LEDs will flash as the byte will be written to the EEPROM
+  * address will be increased and now it will start with blinking of the D1 LED
+  * 
+  * To leave the programming simply push reset.
 
 **Version 0.9**
   18.11.2018 WKLA

+ 26 - 0
SPS/SPS.ino

@@ -1,5 +1,31 @@
 /*
   SPS System mit dem Arduino.
+  Version 0.10
+  18.11.2018 WKLA
+  - new standard programming mode
+  i added a new programming mode for the default programming, because i thing the old one was a little bit clumsy.
+  the new one has a nicer interface, as you now always know where you are.
+  Starting with PRG pushed after Reset.
+  as a result, all LEDs will shortly blink
+  now you are in programming mode.
+  * the D1 LED will blink
+  * the higher nibble of the address will be shown
+  * the D2 LED will blink
+  * the lower nibble of the address will be shown
+  * the D3 LED will blink
+  * the command part (high nibble) will be shown
+  * with SEL you can step thru all commands
+  * PRG will save the command
+  * the D4 LED will blink 
+  * the data part (low nibble) will be shown
+  * with SEL you can step thru all datas
+  * PRG will save the data
+  * if the new value has been changed, all LEDs will flash as the byte will be written to the EEPROM
+  * address will be increased and now it will start with blinking of the D1 LED
+  * 
+  * To leave the programming simply push reset.
+  
+
   Version 0.9
   18.11.2018 WKLA
   - BUGs entfernt. Release.

+ 84 - 93
SPS/prgmode.ino

@@ -1,6 +1,15 @@
 /*
   entering the programming mode
 */
+
+#define BLINK_DELAY 250
+#define SHOW_DELAY 500
+#define KEY_DELAY 250
+
+enum PROGRAMMING_MODE {ADDRESS, COMMAND, DATA};
+
+PROGRAMMING_MODE prgMode;
+
 void programMode() {
   // checking if advance programmer board connected?
 #ifdef SPS_ENHANCEMENT
@@ -10,118 +19,65 @@ void programMode() {
   else {
 #endif
     dbgOutLn("PrgMode");
+    blinkAll();
+    prgMode = ADDRESS;
     addr = 0;
     do {
+      blinkD1();
       dbgOut("Adr:");
       dbgOutLn(addr);
       // LoNibble Adresse anzeigen
       doPort(addr);
-      delay(300);
-      lighting();
+      delay(SHOW_DELAY);
+
+      blinkD2();
       // HiNibble Adresse anzeigen
       data = (addr & 0xf0) >> 4;                                  //Adresse anzeigen
       doPort(data);
-      delay(300);
-      lighting();
+      delay(SHOW_DELAY);
 
       byte Eebyte = EEPROM.read(addr);
       data = Eebyte & 15;
       com = Eebyte >> 4;
-      dbgOutLn('commando eingeben');
-      doPort(com); //Befehl anzeigen
-      digitalWrite(PWM_1, HIGH);
+
+      blinkD3();
+      prgMode = COMMAND;
+      dbgOutLn("com");
+      doPort(com); //show command
+
       do {
+        if (digitalRead(SW_SEL) == 0) {
+          delay(KEY_DELAY);
+          com += 1;
+          com = com & 0x0F;
+          doPort(com);
+        }
       }
-      while (digitalRead(SW_SEL) == 1); // S2 = 1
+      while (digitalRead(SW_PRG) == 1);
       delay(DEBOUNCE);
 
-      prog = 1;                                            //Phase 1: Befehl anzeigen
-      do {
-        dbgOut("C:");
-        dbgOut(com);
-        dbgOut(", D:");
-        dbgOut(data);
-        dbgOut(", P:");
-        dbgOutLn(prog);
-
-        if (digitalRead(SW_PRG) == 0) {
-          if (prog == 1) {
-            prog = 2;
-            com = 15;
-          }
-          if (prog == 2) {                                   //Phase 2: Befehl verändert
-            com = com + 1;
-            com = com & 15;
-            doPort(com);
-            digitalWrite(PWM_1, HIGH);
-          }
-          if (prog == 3) {                                   //Phase 3: Befehl unverändert, Daten ändern
-            prog = 5;
-            data = 15;
-          }
-          if (prog == 4) {                                   //Phase 4: Befehl und Daten geändert
-            prog = 5;
-            data = 15;
-          }
-          if (prog == 5) {                                   //Phase 5: Daten verändert
-            data += 1;
-            data = data & 15;
-            doPort(data);
-            digitalWrite(PWM_1, LOW);
-          }
-          delay(DEBOUNCE);
-          do {
-          }
-          while (digitalRead(SW_PRG) == 1);
-          delay(DEBOUNCE);
-        }
+      blinkD4();
+      prgMode = DATA;
+      dbgOutLn("dat");
+      doPort(data); //show data
 
+      do {
         if (digitalRead(SW_SEL) == 0) {
-          if (prog == 3) {
-            prog = 7;          //nur angezeigt, nicht verändert
-          }
-          if (prog == 4) {
-            doPort(255 - data);
-            digitalWrite(PWM_1, LOW);
-            prog = 6;
-          }
-          if (prog == 2) {
-            doPort(data);             // Portd = Dat Or &HF0
-            digitalWrite(PWM_1, LOW);
-            prog = 4;
-          }
-          if (prog == 6) {                                    //nur Kommando wurde verändert
-            data = data & 15;
-            Eebyte = com * 16;
-            Eebyte = Eebyte + data;
-            EEPROM.write(addr, Eebyte); //           Writeeeprom Eebyte , Addr
-            doPort(0x0F);
-            delay(600);
-            addr += 1;
-            prog = 0;
-          }
-          if (prog == 5) {                                     //Daten wurden verändert
-            data = data & 15;
-            Eebyte = com * 16;
-            Eebyte = Eebyte + data;
-            EEPROM.write(addr, Eebyte); //           Writeeeprom Eebyte , Addr
-            doPort(0xF0);
-            delay(600);
-            addr += 1;
-            prog = 0;
-          }
-          if (prog == 7) {
-            addr += 1;
-            prog = 0;
-          }
-          delay(DEBOUNCE);
-          do {
-          }
-          while (digitalRead(SW_SEL) == 0);
-          delay(DEBOUNCE);
+          delay(KEY_DELAY);
+          data += 1;
+          data = data & 0x0F;
+          doPort(data);
         }
       }
-      while (prog != 0);
+      while (digitalRead(SW_PRG) == 1); // S2 = 1
+      delay(DEBOUNCE);
+      
+      byte newValue = (com << 4) + data;
+      if (newValue != Eebyte) {
+        EEPROM.write(addr, newValue); //           Writeeeprom Eebyte , Addr
+        blinkAll();
+      }
+      addr += 1;
     }
     while (true);
 #ifdef SPS_ENHANCEMENT
@@ -129,7 +85,42 @@ void programMode() {
 #endif
 }
 
-void lighting() {
+void blinkAll() {
+  blinkNull();
   doPort(0x0F);
-  delay(200);
+  delay(BLINK_DELAY);
+}
+
+void blinkD1() {
+  blinkNull();
+  doPort(0x01);
+  delay(BLINK_DELAY);
+  blinkNull();
+}
+
+void blinkD2() {
+  blinkNull();
+  doPort(0x02);
+  delay(BLINK_DELAY);
+  blinkNull();
+}
+
+void blinkD3() {
+  blinkNull();
+  doPort(0x04);
+  delay(BLINK_DELAY);
+  blinkNull();
+}
+
+void blinkD4() {
+  blinkNull();
+  doPort(0x08);
+  delay(BLINK_DELAY);
+  blinkNull();
 }
+
+void blinkNull() {
+  doPort(0x00);
+  delay(BLINK_DELAY);
+}
+

+ 135 - 0
SPS/prgmode.ino.old

@@ -0,0 +1,135 @@
+/*
+  entering the programming mode
+*/
+void programMode() {
+  // checking if advance programmer board connected?
+#ifdef SPS_ENHANCEMENT
+  if (digitalRead(SW_SEL) == 0) {
+    advancePrg();
+  }
+  else {
+#endif
+    dbgOutLn("PrgMode");
+    addr = 0;
+    do {
+      dbgOut("Adr:");
+      dbgOutLn(addr);
+      // LoNibble Adresse anzeigen
+      doPort(addr);
+      delay(300);
+      lighting();
+      // HiNibble Adresse anzeigen
+      data = (addr & 0xf0) >> 4;                                  //Adresse anzeigen
+      doPort(data);
+      delay(300);
+      lighting();
+
+      byte Eebyte = EEPROM.read(addr);
+      data = Eebyte & 15;
+      com = Eebyte >> 4;
+      dbgOutLn('commando eingeben');
+      doPort(com); //Befehl anzeigen
+      digitalWrite(PWM_1, HIGH);
+      do {
+      }
+      while (digitalRead(SW_SEL) == 1); // S2 = 1
+      delay(DEBOUNCE);
+
+      prog = 1;                                            //Phase 1: Befehl anzeigen
+      do {
+        dbgOut("C:");
+        dbgOut(com);
+        dbgOut(", D:");
+        dbgOut(data);
+        dbgOut(", P:");
+        dbgOutLn(prog);
+
+        if (digitalRead(SW_PRG) == 0) {
+          if (prog == 1) {
+            prog = 2;
+            com = 15;
+          }
+          if (prog == 2) {                                   //Phase 2: Befehl verändert
+            com = com + 1;
+            com = com & 15;
+            doPort(com);
+            digitalWrite(PWM_1, HIGH);
+          }
+          if (prog == 3) {                                   //Phase 3: Befehl unverändert, Daten ändern
+            prog = 5;
+            data = 15;
+          }
+          if (prog == 4) {                                   //Phase 4: Befehl und Daten geändert
+            prog = 5;
+            data = 15;
+          }
+          if (prog == 5) {                                   //Phase 5: Daten verändert
+            data += 1;
+            data = data & 15;
+            doPort(data);
+            digitalWrite(PWM_1, LOW);
+          }
+          delay(DEBOUNCE);
+          do {
+          }
+          while (digitalRead(SW_PRG) == 1);
+          delay(DEBOUNCE);
+        }
+
+        if (digitalRead(SW_SEL) == 0) {
+          if (prog == 3) {
+            prog = 7;          //nur angezeigt, nicht verändert
+          }
+          if (prog == 4) {
+            doPort(255 - data);
+            digitalWrite(PWM_1, LOW);
+            prog = 6;
+          }
+          if (prog == 2) {
+            doPort(data);             // Portd = Dat Or &HF0
+            digitalWrite(PWM_1, LOW);
+            prog = 4;
+          }
+          if (prog == 6) {                                    //nur Kommando wurde verändert
+            data = data & 15;
+            Eebyte = com * 16;
+            Eebyte = Eebyte + data;
+            EEPROM.write(addr, Eebyte); //           Writeeeprom Eebyte , Addr
+            doPort(0x0F);
+            delay(600);
+            addr += 1;
+            prog = 0;
+          }
+          if (prog == 5) {                                     //Daten wurden verändert
+            data = data & 15;
+            Eebyte = com * 16;
+            Eebyte = Eebyte + data;
+            EEPROM.write(addr, Eebyte); //           Writeeeprom Eebyte , Addr
+            doPort(0xF0);
+            delay(600);
+            addr += 1;
+            prog = 0;
+          }
+          if (prog == 7) {
+            addr += 1;
+            prog = 0;
+          }
+          delay(DEBOUNCE);
+          do {
+          }
+          while (digitalRead(SW_SEL) == 0);
+          delay(DEBOUNCE);
+        }
+      }
+      while (prog != 0);
+    }
+    while (true);
+#ifdef SPS_ENHANCEMENT
+  }
+#endif
+}
+
+void lighting() {
+  doPort(0x0F);
+  delay(200);
+}