Going back to Radio mode, however, seems to be intermittent. This has always kind of been an issue; if the Arduino doesn't see the Radio selection, it doesn't know to switch back to Radio mode (aka, turn off the CD Changer code/SID display). The SID will go back to Radio mode, and you'll hear the station you're on, but if the Arduino didn't see the switch, "BlueSaab" will pop up again (that 5 second) delay. I just cycle back to the CDC input and back to the radio (3 presses of the SRC button on the wheel) and it seems to clear it up (maybe after a few cycles).
Stupid bugs...
// ----------------------------------------------
// SECUDUINO
// http://secuduino.blogspot.com/
// By Igor Real
// 16/05/2011
//
// Saab CDC Changer Emulator
// Seth Evans
// 27 Sep 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() {
if (CAN.CheckNew()){
CAN_TxMsg.data[0]++;
CAN.ReadFromDevice(&CAN_RxMsg);
//PrintBus();
if (CAN_RxMsg.id==0x3C0){
CDC();
if (CAN_RxMsg.data[1]==0x24){
cdbutton = 1;
Serial.println("CDC");
}
else if (CAN_RxMsg.data[0]==0x80 && CAN_RxMsg.data[1]==0x14){
cdbutton = 0;
Serial.println("Radio");
}
}
if (cdbutton==1){
CDC();
delay(5);
iPodOn();
}
else {
//iPodOff();
}
}
}
void CDC(){
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=0x357; // enable the SID (SPA) text
CAN_TxMsg.data[0]=0x1F;
CAN_TxMsg.data[1]=0x02;
CAN_TxMsg.data[2]=0x05;
CAN_TxMsg.data[3]=0x12;
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);
CAN_TxMsg.id=0x337;
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(10);
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]=0x20; // _
CAN_TxMsg.data[7]=0x20; // _
CAN.send(&CAN_TxMsg);
delay(10);
CAN_TxMsg.data[0]=0x00;
CAN_TxMsg.data[3]=0x20; // _
CAN_TxMsg.data[4]=0x20; // _
CAN_TxMsg.data[5]=0x00; //
CAN_TxMsg.data[6]=0x00; //
CAN_TxMsg.data[7]=0x00; //
CAN.send(&CAN_TxMsg);
delay(10);
}
void iPodOff(){
CAN_TxMsg.id=0x357; // turn off the SID (SPA) text
CAN_TxMsg.data[0]=0x1F;
CAN_TxMsg.data[1]=0x00;
CAN_TxMsg.data[2]=0x05;
CAN_TxMsg.data[3]=0x08;
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==0x3C0){
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