 #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() {


  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();


#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
//
