Add verbose echo

Add verbose echo

--- Arduino/ArduinoBluetoothMusicPlayer/ArduinoBluetoothMusicPlayer.ino
+++ Arduino/ArduinoBluetoothMusicPlayer/ArduinoBluetoothMusicPlayer.ino
@@ -6,8 +6,8 @@
 #define BOUND MAXVOL

 typedef enum {
-  MP_PLAY = 'a',
-  MP_PAUSE,
+  MP_PAUSE = 'a',
+  MP_RESUME,
   MP_BACKWARD,
   MP_FORWARD,
   MP_PREV,
@@ -38,11 +38,13 @@
   if (Serial.available()) {
     MPCommand cmd = (MPCommand)Serial.read();
     switch (cmd) {
-    case MP_PLAY:
+    case MP_PAUSE:
+      Serial.write("[Pause]\r\n");
+      player.opPause();
+      break;
+    case MP_RESUME:
+      Serial.write("[Resume]\r\n");
       player.opResume();
-      break;
-    case MP_PAUSE:
-      player.opPause();
       break;
     case MP_BACKWARD:
       player.opFastRewind();
@@ -72,15 +74,19 @@
       player.setVolume(vol);
       break;
     case MP_MODE_NORMAL:
+      Serial.write("Mode changed to Normal\r\n");
       player.setPlayMode(PM_NORMAL_PLAY);
       break;
     case MP_MODE_SHUFFLE:
+      Serial.write("Mode changed to Shuffle\r\n");
       player.setPlayMode(PM_SHUFFLE_PLAY);
       break;
     case MP_MODE_LIST:
+      Serial.write("Mode changed to RepeatList\r\n");
       player.setPlayMode(PM_REPEAT_LIST);
       break;
     case MP_MODE_SINGLE:
+      Serial.write("Mode changed to RepeatSingle\r\n");
       player.setPlayMode(PM_REPEAT_ONE);
       break;
     }


First full implementation of sync protocol

--- sync.ino
+++ sync.ino
@@ -2,9 +2,9 @@

 #define SYNC_DELIMITER      ';'

-// timeout in milliseconds. If we expect communication and don't see it for
+// timeout in seconds. If we expect communication and don't see it for
 // this long we abort sync
-#define SYNC_SERIAL_TIMEOUT (1*3000)
+#define SYNC_SERIAL_TIMEOUT (3)

 typedef struct {
   uint8_t abort;
@@ -16,18 +16,18 @@
 }

 void sync_abort(char *msg) {
-  Serial.print("SYNC aborted:");
+  Serial.print("ABORT:");
   Serial.println(msg);
 }

 int8_t sync_blocking_read() {
   int8_t c;
-  uint16_t startt = millis();
+  millis_t startt = millis();

   do {
     c = Serial.read();
-    if (millis() - startt > SYNC_SERIAL_TIMEOUT) {
-      sync_abort("communication timed out");
+    if (millis() - startt > SYNC_SERIAL_TIMEOUT*1000) {
+      sync_abort("read timed out");
       Sync.abort = 1;
       break;
     }
@@ -57,6 +57,7 @@
 int16_t sync_get_int() {
   uint8_t readpos = 0;
   uint8_t c;
+
   do {
     c = sync_blocking_read();
     if (c == SYNC_DELIMITER) break;
@@ -70,6 +71,8 @@
 /**
  * Checks serial connection for start of sync.
  *
+ * Protocol
+ * ========
  * Sync protocol uses ; as delimiter, and is as follows:
  *
  * The characters SYNC is sent, followed by ;
@@ -86,15 +89,23 @@
  *
  *    2015;05;03;0;
  *
- * Termination of sync is denoted by END
+ * Responses
+ * =========
+ * At start of SYNC the following will sent:
  *
- *    END;
+ *    SYNC
  *
- * White spaces may be inserted before/after ; and will be ignored. E.g.
+ * When sync data has been processed without error
  *
- *    2015;    05;   03;0
+ *    OK
  *
- * is valid.
+ * is sent.
+ *
+ * If sync is aborted for any reason,
+ *
+ *    ABORT: <reason>
+ *
+ * is sent.
  */

 #define CHECK_ABORT()     do { if (Sync.abort) return; } while (0);
@@ -103,11 +114,8 @@
   Sync.abort = 0;
   if (Serial.available()) {
     if (sync_get_word("SYNC;") == OK) {
-      Serial.println("SYNC START");
-    } else {
-      sync_abort("SYNC; expected");
-      return;
-    }
+      Serial.println("SYNC");
+    } else return;

     uint8_t hours = sync_get_int();
     uint8_t minutes = sync_get_int();
@@ -115,7 +123,16 @@

     CHECK_ABORT();

-    sprintf(_sbuf, "Time: %02d:%02d:%02d\n", hours, minutes, seconds);
-    Serial.print(_sbuf);
-  }
+    watch_set_time(hours, minutes, seconds);
+
+    uint16_t year = sync_get_int();
+    uint8_t month = sync_get_int();
+    uint8_t day = sync_get_int();
+    uint8_t isleapyear = sync_get_int();
+
+    CHECK_ABORT();
+
+    watch_set_date(year, month, day, isleapyear);
+    Serial.println("OK");
+  }
 }


Got the last 8 columns to work.

Got the last 8 columns to work.

Proof of concept works for 8 characters.

--- willemeen.ino
+++ willemeen.ino
@@ -8,6 +8,9 @@
 // Stood on the shoulders of:
 // http://www.openobject.org/opensourceurbanism/Bike_POV_Beta_4 // Font renderer, jay!
 // http://playground.arduino.cc/Code/BitMath // Bit manipulation hurts my brain!
+
+// Challenge: 5*7*56*50*16 = 1568000 bps to the shift registers.
+// 800 frame updates aka interrupts / second.

 #include "font.h"

@@ -58,14 +61,14 @@
 screenbuffer[activebuffer][4][0] = 0x37BD1;
 screenbuffer[activebuffer][5][0] = 0x54631;
 screenbuffer[activebuffer][6][0] = 0x97BD1;*/
-  printLetter('M',0);
-  printLetter('a',5);
-  printLetter('a',10);
-  printLetter('k',15);
-  printLetter('p',20);
-  printLetter('l',25);
-  printLetter('e',30);
-  printLetter('k',35);
+  printChar('H',0);
+  printChar('a',5);
+  printChar('a',10);
+  printChar('k',15);
+  printChar('p',20);
+  printChar('l',25);
+  printChar('e',30);
+  printChar('k',35);
 }

 void loop() {
@@ -93,14 +96,16 @@
     }
     // Flick the latch
     digitalWrite(latchPin, 1);
-    delay(1);
+  //  delay(1);
     digitalWrite(latchPin, 0);
     // Turn on next row.
     digitalWrite(i + 13, 0);
   }
 }

-void printLetter(char ch, byte pos)
+void printString();
+
+void printChar(char ch, byte pos)
 {
   // The display is 40 bits wide, the buffer only 32. Time to select the correct one.
   int bufferpos = 0;
@@ -126,10 +131,17 @@
     else {
       bufferpointer = 1;
       bufferlength = 7;
-      bufferpos = pos - 31;
+      bufferpos = pos - 8;
     }

-    // bit shift through the byte set it in the buffer
+    // 0 1 2 3 4
+    // 30
+
+    //  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
+    // 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
+    //                                                                                7  6  5  4  3  2  1  0
+
+    // bit shift through the byte, set it in the buffer
     for (int j=0; j<7; j++) {
       if (b & (1 << j)) {
         bitSet(screenbuffer[activebuffer][j][bufferpointer], 31-i-bufferpos);
@@ -142,13 +154,7 @@
 }

 void updatebuffer() {
-//  Serial.println(i);
- // if (screenbuffer[activebuffer][0][0] > 0)
- // {
- //   screenbuffer[activebuffer][0][0] = screenbuffer[activebuffer][0][0] <<1; // shift the outputpattern left by one bit
- // }
- // else {
-//    screenbuffer[activebuffer][0][0] = 2863310165;
-//  }
-
+  for (i = 0; i < sizeof(source); i++){
+    printf("%c", source[i]);
+  }
 }