fixed bug when changing numSteps

fixed bug when changing numSteps

--- Sequencer/Sequencer.ino
+++ Sequencer/Sequencer.ino
@@ -121,7 +121,7 @@
   if(playhead > stepTime){
     playhead = 0;
     curStep++;
-    if(curStep == numSteps) {curStep = 0;}
+    if(curStep > numSteps-1) {curStep = 0;}
   }
   // Gate CV output
   if(playhead < stepTime * dur[curStep] / 100.f){


Frequency interpreter working to programm the AD9833s. Old SPI interface has been updated to use the beginTransaction() method


remove text , use landscapeText to replace it

--- examples/text/text.ino
+++ examples/text/text.ino
@@ -1,34 +0,0 @@
-/*  draw text's APP
-    drawChar(INT8U ascii,INT16U poX, INT16U poY,INT16U size, INT16U fgcolor);
-    drawString(char *string,INT16U poX, INT16U poY,INT16U size,INT16U fgcolor);
-*/
-
-#include <stdint.h>
-#include <TFTv2.h>
-
-void setup()
-{
-    TFT_BL_ON;      // turn on the background light
-    Tft.TFTinit();  // init TFT library
-
-    Tft.drawChar('S',0,0,1,RED);                // draw char: 'S', (0, 0), size: 1, color: RED
-
-    Tft.drawChar('E',10,10,2,BLUE);             // draw char: 'E', (10, 10), size: 2, color: BLUE
-
-    Tft.drawChar('E',20,40,3,GREEN);            // draw char: 'E', (20, 40), size: 3, color: GREEN
-
-    Tft.drawChar('E',30,80,4,YELLOW);           // draw char: 'E', (30, 80), size: 4, color: YELLOW
-
-    Tft.drawChar('D',40,120,4,YELLOW);          // draw char: 'D', (40, 120), size: 4, color: YELLOW
-
-    Tft.drawString("Hello",0,180,3,CYAN);       // draw string: "hello", (0, 180), size: 3, color: CYAN
-
-    Tft.drawString("World!!",60,220,4,WHITE);    // draw string: "world!!", (80, 230), size: 4, color: WHITE
-
-
-}
-
-void loop()
-{
-
-}


start of wifi-planer node.

start of wifi-planer node.


Working 5V led

Working 5V led

--- bolt-arduino.ino
+++ bolt-arduino.ino
@@ -1,4 +1,4 @@
-const int P_LED_VCC = 3;
+const int P_LED_VCC = 5;
 const int P_LED_DATA = 9;
 const int P_LED_CLOCK = 10;
 const int P_LED_LATCH = 11;
@@ -28,9 +28,9 @@

   //states[0] = LED_STATE_ON;

-  analogWrite(P_LED_LATCH, LOW);
+  digitalWrite(P_LED_LATCH, LOW);
   shiftOut();
-  analogWrite(P_LED_LATCH, LED_TWO_VOLTS);
+  digitalWrite(P_LED_LATCH, HIGH);

 }

@@ -40,14 +40,14 @@
 void shiftOut() {
   for (uint8_t i = 0; i < 8; i++)  {
     if (!!(val & (1 << i))){
-      analogWrite(P_LED_DATA, LED_TWO_VOLTS);
+      digitalWrite(P_LED_DATA, HIGH);
     } else {
-      analogWrite(P_LED_DATA, LOW);
+      digitalWrite(P_LED_DATA, LOW);
     }

-    analogWrite(P_LED_CLOCK, LED_TWO_VOLTS);
-    analogWrite(P_LED_CLOCK, LOW);
+    digitalWrite(P_LED_CLOCK, HIGH);
+    digitalWrite(P_LED_CLOCK, LOW);
   }

   /*analogWrite(P_LED_CLOCK, LOW);


Detect ignition key off

Detect ignition key off

--- volvo_hid.ino
+++ volvo_hid.ino
@@ -14,12 +14,14 @@
 #define CS_PIN 15
 #define RX_LED 17

+#define HEARTBEAT_TIMEOUT 2000
 #define KEY_TIMEOUT 100
 #define MOUSE_BASE_SPEED 8
 #define MOUSE_SPEEDUP 3

 #define SYN_FIELD 0x55
 #define SWM_ID 0x20
+#define HEARTBEAT_ID 0xCF

 // Volvo V50 2007 SWM key codes
 //
@@ -45,7 +47,7 @@
 byte b, i, n;
 LinFrame frame;

-unsigned long lastBackDown, lastEnterDown, lastMouseDown;
+unsigned long lastHeartbeat, lastBackDown, lastEnterDown, lastMouseDown;
 int mouseSpeed = MOUSE_BASE_SPEED;

 void setup() {
@@ -55,7 +57,7 @@
   digitalWrite(CS_PIN, HIGH);

   // Open serial communications to host (PC) and wait for port to open:
-//  Serial.begin(9600);
+  Serial.begin(9600);
 //  Serial.println("LIN Debugging begins");

   Serial1.begin(9600);
@@ -85,10 +87,16 @@
   }

   release_keys();
+  check_ignition_key();
 }

 void handle_frame() {
-  if (frame.get_byte(0) != SWM_ID)
+  byte id = frame.get_byte(0);
+
+  if (id == HEARTBEAT_ID)
+    lastHeartbeat = millis();
+
+  if (id != SWM_ID)
     return;

   // skip zero values 20 0 0 0 0 FF
@@ -165,3 +173,15 @@
     mouseSpeed = MOUSE_BASE_SPEED;
   }
 }
+
+void check_ignition_key() {
+   if (lastHeartbeat && millis() - lastHeartbeat > HEARTBEAT_TIMEOUT) {
+     lastHeartbeat = 0;
+     turn_off();
+   }
+}
+
+void turn_off() {
+  Serial.println("TURN OFF");
+}
+


Add mobile & rti on / off

Add mobile & rti on / off

--- volvo_hid.ino
+++ volvo_hid.ino
@@ -7,21 +7,31 @@

 #include "Mouse.h"
 #include "Keyboard.h"
+#include "SoftwareSerial.h"

 // https://github.com/zapta/linbus/tree/master/analyzer/arduino
 #include "lin_frame.h"

 #define CS_PIN 15
 #define RX_LED 17
+#define MOBILE_CHARGER_PIN A3
+#define RTI_RX_PIN 8
+#define RTI_TX_PIN 9

 #define HEARTBEAT_TIMEOUT 2000
 #define CLICK_TIMEOUT 100

+#define RTI_INTERVAL 100
+#define MOBILE_CHARGER_TRIGGER_TIME 2500
+
 #define MOUSE_BASE_SPEED 8
 #define MOUSE_SPEEDUP 3

 #define SYN_FIELD 0x55
 #define SWM_ID 0x20
+
+#define STATE_OFF 0
+#define STATE_ON 1

 // Volvo V50 2007 SWM key codes
 //
@@ -44,32 +54,42 @@
 #define BUTTON_BACK 1
 #define BUTTON_ENTER 8

+short rtiStep;
+
+SoftwareSerial rtiSerial(RTI_RX_PIN, RTI_TX_PIN);
+
 LinFrame frame = LinFrame();

-unsigned long currentMillis, lastHeartbeat, lastBackDown, lastEnterDown, lastMouseDown;
+unsigned long currentMillis, lastHeartbeat, lastBackDown, lastEnterDown, lastMouseDown, lastRtiWrite;
 int mouseSpeed = MOUSE_BASE_SPEED;
+short state = STATE_OFF;

 void setup() {
   pinMode(RX_LED, OUTPUT);
-
+
   pinMode(CS_PIN, OUTPUT);
   digitalWrite(CS_PIN, HIGH);

-  Serial.begin(9600);
+//  Serial.begin(9600);
   Serial1.begin(9600);
+  rtiSerial.begin(2400);

   Mouse.begin();
   Keyboard.begin();
+
+  pinMode(MOBILE_CHARGER_PIN, OUTPUT);
+  analogWrite(MOBILE_CHARGER_PIN, 0);
 }

 void loop() {
   currentMillis = millis();
-
+
   if (Serial1.available())
     read_lin_bus();

   release_keys();
   check_ignition_key();
+  rti();
 }

 void read_lin_bus() {
@@ -78,11 +98,11 @@

   if (b == SYN_FIELD && n > 2 && frame.get_byte(n - 1) == 0) {
     digitalWrite(RX_LED, LOW);
-
+
     frame.pop_byte();
     handle_swm_frame();
     frame.reset();
-
+
     digitalWrite(RX_LED, HIGH);
   } else if (n == LinFrame::kMaxBytes) {
     frame.reset();
@@ -96,7 +116,7 @@
     return;

   lastHeartbeat = currentMillis;
-
+
   // skip zero values 20 0 0 0 0 FF
   if (frame.get_byte(5) == 0xFF)
     return;
@@ -104,9 +124,9 @@
   if (!frame.isValid())
     return;

-//  dump_frame();
+  //  dump_frame();
   handle_joystick();
-  handle_buttons();
+  handle_buttons();
 }

 void handle_joystick() {
@@ -123,59 +143,106 @@
     case JOYSTICK_RIGHT:
       move_mouse(1, 0);
       break;
-  }
+  }
 }

 void handle_buttons() {
   switch (frame.get_byte(2)) {
     case BUTTON_BACK:
-      if (!lastBackDown)
-        Keyboard.press(KEY_ESC);
-
+      if (!lastBackDown)
+        Keyboard.press(KEY_ESC);
+
       lastBackDown = currentMillis;
       break;
-
+
     case BUTTON_ENTER:
-      if (!lastEnterDown)
-        Mouse.press();
-
+      if (!lastEnterDown && state == STATE_ON)
+        Mouse.press();
+
       lastEnterDown = currentMillis;
       break;
   }
 }

 void move_mouse(int dx, int dy) {
-  Mouse.move(dx * mouseSpeed, dy * mouseSpeed, 0);
+  Mouse.move(dx * mouseSpeed, dy * mouseSpeed, 0);
   lastMouseDown = currentMillis;
   mouseSpeed += MOUSE_SPEEDUP;
 }

 void release_keys() {
   if (lastEnterDown && currentMillis - lastEnterDown > CLICK_TIMEOUT) {
-    Mouse.release();
+    if (state == STATE_ON)
+      Mouse.release();
+    else
+      turn_on();
+
     lastEnterDown = 0;
   }
-
+
   if (lastBackDown && currentMillis - lastBackDown > CLICK_TIMEOUT) {
     Keyboard.release(KEY_ESC);
     lastBackDown = 0;
   }

-  if (lastMouseDown && currentMillis - lastMouseDown > CLICK_TIMEOUT) {
+  if (lastMouseDown && currentMillis - lastMouseDown > CLICK_TIMEOUT) {
     lastMouseDown = 0;
     mouseSpeed = MOUSE_BASE_SPEED;
   }
 }

 void check_ignition_key() {
-   if (lastHeartbeat && currentMillis - lastHeartbeat > HEARTBEAT_TIMEOUT) {
-     lastHeartbeat = 0;
-     turn_off();
-   }
+  if (lastHeartbeat && currentMillis - lastHeartbeat > HEARTBEAT_TIMEOUT) {
+    lastHeartbeat = 0;
+    turn_off();
+  }
+}
+
+void turn_on() {
+  state = STATE_ON;
+  turn_on_phone();
+}
+
+void turn_on_phone() {
+  analogWrite(MOBILE_CHARGER_PIN, 255);
+  delay(MOBILE_CHARGER_TRIGGER_TIME);
+  analogWrite(MOBILE_CHARGER_PIN, 0);
 }

 void turn_off() {
-  Serial.println("TURN OFF");
+  state = STATE_OFF;
+}
+
+// send serial data to Volvo RTI screen mechanism
+void rti() {
+  if (currentMillis - lastRtiWrite < RTI_INTERVAL) return;
+
+  switch (rtiStep) {
+    case 0: // mode
+      if (state == STATE_OFF)
+        rti_print(0x46);
+      else
+        rti_print(0x40);
+
+      rtiStep++;
+      break;
+
+    case 1: // brightness
+      rti_print(0x20);
+      rtiStep++;
+      break;
+
+    case 2: // sync
+      rti_print(0x83);
+      rtiStep = 0;
+      break;
+  }
+
+  lastRtiWrite = currentMillis;
+}
+
+void rti_print(char byte) {
+  rtiSerial.print(byte);
 }

 // -- debugging


fix: pass char array to update_display function

The Alarm callback are a function pointer that do not seem to get
the global buffer. we change update_display to fill in a buffer
passed from outside.

--- code/arduino/main/aws_sketch/aws_sketch.ino
+++ code/arduino/main/aws_sketch/aws_sketch.ino
@@ -58,7 +58,6 @@

 // return codes
 DHT22_ERROR_t dht22_code ;
-char* buffer ;

 void setup() {

@@ -66,8 +65,6 @@
     Serial.begin(9600);
 #endif

-    char tmp[1] = {'0' } ;
-    buffer = tmp ;
     // watchdog enabled
     wdt_enable(WDTO_8S);

@@ -139,9 +136,9 @@
     }
 }

-void update_display() {
-
-    char output[33] ;
+void update_display(char* output) {
+
+    // char output[33] ;
     output[0] = 'T' ;
     // DHT22 pin needs 2 seconds
     micro_delay(250);
@@ -171,7 +168,7 @@
     output[16] = 'P' ;
     pressure = bmp.readPressure();
     pressure = round(pressure/100.0) ;
-    sprintf(output+17,"%-5d",pressure);
+    sprintf(output+17,"%-5lu",pressure);
     output[22] = ' ';
     output[23] = 'R';

@@ -181,24 +178,14 @@
     for(int i = 29 ; i < 32; i++){ output[i] = ' ' ; }
     // null
     output[32] = '\0' ;
-
-    buffer = output ;
-
-
-
-#if !defined(AWS_NO_SERIAL)
-    serial_output();
-#endif
-
-#if !defined(AWS_NO_LCD)
-    lcd_output();
-#endif
-
 }

 void send_bulletin() {

 #if !defined(AWS_NO_GSM)
+    char buffer[33] ;
+    update_display(buffer);
+
     gsmSerial.print("\r");
     micro_delay(20);
     gsmSerial.print("AT+CMGF=1\r");
@@ -208,9 +195,11 @@
     micro_delay(20);
     // pat watchdog
     wdt_reset();
-    for(int i = 0 ; i < 32 ;i++) { gsmSerial.print(buffer[i]); }
-
+
+    gsmSerial.print(buffer);
+    gsmSerial.println();
     gsmSerial.write(0x1A);
+
     micro_delay(100);
     // pat watchdog
     wdt_reset();
@@ -235,7 +224,7 @@
 }

 #if !defined(AWS_NO_SERIAL)
-void serial_output() {
+void serial_output(char* buffer) {
     int hh = hour();
     int mm = minute();
     int ss = second();
@@ -252,7 +241,7 @@
 #endif

 #if !defined(AWS_NO_LCD)
-void lcd_output() {
+void lcd_output(char* buffer) {

     pinMode(lcd_pin, OUTPUT);
     digitalWrite(lcd_pin, HIGH);
@@ -265,14 +254,14 @@
     for(int i = 16 ; i < 32; i++){ lcd.print(buffer[i]); }
 }

-void lcd_one_liner(char* str) {
+void lcd_one_liner(char* buffer) {
     pinMode(lcd_pin, OUTPUT);
     digitalWrite(lcd_pin, HIGH);
     lcd.begin(16,2);
     lcd.clear();
     // line1
     lcd.setCursor(0,0);
-    lcd.print(str);
+    lcd.print(buffer);

 }

@@ -280,7 +269,15 @@

 void loop() {

-    update_display();
+    char buffer[33];
+    update_display(buffer);
+#if !defined(AWS_NO_SERIAL)
+    serial_output(buffer);
+#endif
+
+#if !defined(AWS_NO_LCD)
+    lcd_output(buffer);
+#endif
     wdt_reset();
     // refresh in 30 seconds
     micro_delay(2750);