Tuesday, October 2, 2012

Smooth display

I think I finally got the SID to display "BlueSaab" without flickering now. I don't know why, but I'm using the 348 ID to say "1102FF1900000000" after I send the "BlueSaab" text...I thought that 348 command would turn the text off, but I guess it turned off the "CD1 PLAY" text!

I still have 2 issues...
1, the Arduino has problems where it will miss my button press to go to the CDC or Radio, thereby still displaying "BlueSaab" (or not, depending on your intended source). Several cycles through the sources (easiest with the SRC button on the steering wheel) will usually catch whatever source you need, and match the SID to it.
2, If playing BlueSaab and you turn the radio off, the SID still displays "BlueSaab". This is remedied by turning the head unit back on, switching to Radio, and turning the radio off. The sound turns off, but the SID does not. It's still something with the Arduino not catching button clicks. I may have to add an "If/Then" or "switch" to catch the power down mode & turn off the SID.

New code!



// ----------------------------------------------
// SECUDUINO
// http://secuduino.blogspot.com/
// By Igor Real
// 16/05/2011
//
// Saab CDC Changer Emulator
// Seth Evans
// 2 Oct 2012
// ----------------------------------------------

#include <CAN.h>

int cdbutton;

void setup() {
  // set up CAN
  CAN.begin(47);  // Saab I-Bus is 47.619kbps
  Serial.begin(115200);
  cdbutton = 0;
  CAN_TxMsg.header.rtr=0;     // this value never changes
  CAN_TxMsg.header.length=8;  // this value never changes
}

void loop() {
  CDC();
  delay(5);
  if (CAN.CheckNew()) {
    CAN_TxMsg.data[0]++;
    CAN.ReadFromDevice(&CAN_RxMsg);
    //PrintBus();
    if (CAN_RxMsg.id==0x3C0) {
      //CDC();
      //delay(5);
      if (CAN_RxMsg.data[0]==0x80) {
        switch (CAN_RxMsg.data[1]) {
        case 0x24:
          cdbutton = 1;
          Serial.println("CDC");
          break;
        case 0x14:
          cdbutton = 0;  
          Serial.println("Radio");
          break;
          //case default:
        } // end of switch case
        //else if (CAN_RxMsg.data[0]==0x80 && CAN_RxMsg.data[1]==0x14)
      }
    }
  }
  if (cdbutton==1) {
    //CDC();
    //delay(5);
    iPodOn();
  }
  else {
    iPodOff();
  }
}

void CDC() {
  CAN_TxMsg.id=0x6A2;     //
  CAN_TxMsg.data[0]=0x32;
  CAN_TxMsg.data[1]=0x00;
  CAN_TxMsg.data[2]=0x00;
  CAN_TxMsg.data[3]=0x16; //
  CAN_TxMsg.data[4]=0x01;
  CAN_TxMsg.data[5]=0x02;
  CAN_TxMsg.data[6]=0x00;
  CAN_TxMsg.data[7]=0x00; //
  CAN.send(&CAN_TxMsg);
  delay(5);

  CAN_TxMsg.id=0x3C8;     // CD Changer
  CAN_TxMsg.data[0]=0xE0;
  CAN_TxMsg.data[1]=0x00;
  CAN_TxMsg.data[2]=0x3F;
  CAN_TxMsg.data[3]=0x31; // playing disc 1
  CAN_TxMsg.data[4]=0xFF;
  CAN_TxMsg.data[5]=0xFF;
  CAN_TxMsg.data[6]=0xFF;
  CAN_TxMsg.data[7]=0xD0; // married "OK" code
  CAN.send(&CAN_TxMsg);
}

void iPodOn() {
  CAN_TxMsg.id=0x328;     // SID audio text
  CAN_TxMsg.data[0]=0x42;
  CAN_TxMsg.data[1]=0x96;
  CAN_TxMsg.data[2]=0x02;
  CAN_TxMsg.data[3]=0x42; // B
  CAN_TxMsg.data[4]=0x6C; // l
  CAN_TxMsg.data[5]=0x75; // u
  CAN_TxMsg.data[6]=0x65; // e
  CAN_TxMsg.data[7]=0x53; // S
  CAN.send(&CAN_TxMsg);
  delay(5);

  CAN_TxMsg.data[0]=0x01;
  CAN_TxMsg.data[3]=0x61; // a
  CAN_TxMsg.data[4]=0x61; // a
  CAN_TxMsg.data[5]=0x62; // b
  CAN_TxMsg.data[6]=0x00; // _
  CAN_TxMsg.data[7]=0x00; // _
  CAN.send(&CAN_TxMsg);
  delay(5);

  CAN_TxMsg.data[0]=0x00;
  CAN_TxMsg.data[3]=0x00; // _
  CAN_TxMsg.data[4]=0x00; // _
  CAN_TxMsg.data[5]=0x00; //
  CAN_TxMsg.data[6]=0x00; //
  CAN_TxMsg.data[7]=0x00; //
  CAN.send(&CAN_TxMsg);
  delay(5);

  CAN_TxMsg.id=0x348;     // enable the SID (audio) text?
  CAN_TxMsg.data[0]=0x11;
  CAN_TxMsg.data[1]=0x02;
  CAN_TxMsg.data[2]=0xFF;
  CAN_TxMsg.data[3]=0x19;
  CAN_TxMsg.data[4]=0x00;
  CAN_TxMsg.data[5]=0x00;
  CAN_TxMsg.data[6]=0x00;
  CAN_TxMsg.data[7]=0x00;
  CAN.send(&CAN_TxMsg);
  delay(5);
}

void iPodOff() {
  CAN_TxMsg.id=0x368;     // turn off the SID (SPA) text
  CAN_TxMsg.data[0]=0x02;
  CAN_TxMsg.data[1]=0x19;
  CAN_TxMsg.data[2]=0x00;
  CAN_TxMsg.data[3]=0x00;
  CAN_TxMsg.data[4]=0x00;
  CAN_TxMsg.data[5]=0x00;
  CAN_TxMsg.data[6]=0x00;
  CAN_TxMsg.data[7]=0x00;
  CAN.send(&CAN_TxMsg);
  delay(10);
}

void PrintBus() {
  if (CAN_RxMsg.id==0x290) {
    Serial.print(CAN_RxMsg.id,HEX);
    Serial.print(";");
    Serial.print(CAN_RxMsg.data[0],HEX);
    Serial.print(";");
    Serial.print(CAN_RxMsg.data[1],HEX);
    Serial.print(";");
    Serial.print(CAN_RxMsg.data[2],HEX);
    Serial.print(";");
    Serial.print(CAN_RxMsg.data[3],HEX);
    Serial.print(";");
    Serial.print(CAN_RxMsg.data[4],HEX);
    Serial.print(";");
    Serial.print(CAN_RxMsg.data[5],HEX);
    Serial.print(";");
    Serial.print(CAN_RxMsg.data[6],HEX);
    Serial.print(";");
    Serial.println(CAN_RxMsg.data[7],HEX);
  }
}

No comments:

Post a Comment