Tuesday, September 25, 2012
Software update
I'm still playing with the SID display timing...this version seems to work pretty well, except the radio has a tendency to just shut off randomly...(?).
I tried using 0x337 SPA (Saab Park Assist) Messages to display the audio status, but that had it's own issues as well. As you can see below, I'm currently using 0x328 SID Audio Text Messages.
// ----------------------------------------------
// SECUDUINO
// http://secuduino.blogspot.com/
// By Igor Real
// 16/05/2011
//
// Saab CDC Changer Emulator
// Seth Evans
// 25 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() {
CDC();
delay(5);
if (CAN.CheckNew()){
CAN_TxMsg.data[0]++;
CAN.ReadFromDevice(&CAN_RxMsg);
//PrintBus();
if (CAN_RxMsg.id==0x3C0){
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){
iPodOn();
}
else {
iPodOff();
}
}
void CDC(){
CAN_TxMsg.id=0x3C8;
CAN_TxMsg.data[0]=0x80;
CAN_TxMsg.data[1]=0x00;
CAN_TxMsg.data[2]=0x3F;
CAN_TxMsg.data[3]=0x41;
CAN_TxMsg.data[4]=0x00;
CAN_TxMsg.data[5]=0x00;
CAN_TxMsg.data[6]=0x00;
CAN_TxMsg.data[7]=0xD0;
CAN.send(&CAN_TxMsg);
}
void iPodOn(){
CAN_TxMsg.id=0x328;
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);
}
void iPodOff(){
}
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);
}
}
Labels:
code
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment