tomaskovacik / vwcdavr

AVR alternative to vwcdpic HW+SW

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: Receiving media keys/ multi stearing commands and pass to CDC emulator

istals opened this issue · comments

Hey!

I have a question,

Is there a possibility to get prev/next commands from the head unit and multi steering next/prev track signals pass to CDC emulators?

these?

#define Do_PLAY 0x03 // mix button held down (RCD300 head unit only)

Yes

case Do_UP:
case Do_UP_MK3:
if (playing == TRUE) // skip track lead-in if not in play mode
{
SetStateTrackLeadIn();
}
ResetTime();
#ifndef DISC_TRACK_NUMBER_FROM_MPD
track++;
decimal_adjust_u8 = track & 0x0F; // skip past hexidecimal codes
if (decimal_adjust_u8 == 0x0A) // are with at xA?
{
track += 6; // yes, add 6 and we'll be at x0 instead
}
if (track == 0xA0) // have we gone beyond Track 99?
{ // yes, rollover to Track 01 so that jog wheels
track = 1; // can continue rolling (Audi Concert II)
}
#endif
EnqueueString(sNEXT);
break;
case Do_DOWN:
case Do_DOWN_MK3:
if (playing == TRUE) // skip track lead-in if not in play mode
{
SetStateTrackLeadIn();
}
ResetTime();
#ifndef DISC_TRACK_NUMBER_FROM_MPD
decimal_adjust_u8 = track & 0x0F; // skip past hexidecimal codes
if (decimal_adjust_u8 == 0) // are we at x0?
{
track -= 6; // yes, subtract 6 and we'll be at x9 instead
}
track--;
if (track == 0) // have we gone below Track 1?
{ // yes, rollover to Track 99 so that jog wheels
track = 0x99; // can continue rolling (Audi Concert II)
}
#endif
EnqueueString(sPREVIOUS);

But also I needed to add SetStateIdleThenPlay(); after init Init_VWCDC(); to get radio playing, I feel that I'm missing something

what exactly do you need to do with them? if you press button on MFSW or on radio then emulator will change track

Ok, then that is not happening, I'm using Arduino Uno (AVR_ATmega328P)
defs and things I changed in code

// #define DUMPMODE
// #define DUMPMODE2
//#define DISC_TRACK_NUMBER_FROM_MPD
// #define BLUETOOTH

#define RADIO_COMMAND      PB0 //ICP
#define RADIO_COMMAND_DDR  DDRB
#define RADIO_COMMAND_PORT  PORTB
#define RADIO_COMMAND_PIN PINB
//standard pinout 8,11,13
#define RADIO_CLOCK       PB5
#define RADIO_CLOCK_DDR    DDRB
#define RADIO_CLOCK_PORT  PORTB
#if defined(__AVR_ATmega328PB__) //cannot use pb3 with serial1
#define RADIO_DATA        PB2
#else
#define RADIO_DATA        PB3
#endif
#define RADIO_DATA_DDR    DDRB
#define RADIO_DATA_PORT  PORTB
//my pinout, 8,6,A0
//#define RADIO_CLOCK        PD4
//#define RADIO_CLOCK_DDR    DDRD
//#define RADIO_CLOCK_PORT  PORTD
//#define RADIO_DATA         PC3
//#define RADIO_DATA_DDR     DDRC
//#define RADIO_DATA_PORT  PORTC
//#define RADIO_ACC 3 // PD3 = INT1

int main()
{
  Serial.begin(9600);
  
  pinMode(D_CTRL_PREV_PIN, OUTPUT);
  pinMode(D_CTRL_NEXT_PIN, OUTPUT);
  pinMode(D_CTRL_LED_PIN, OUTPUT);
  digitalWrite(D_CTRL_PREV_PIN, LOW);
  digitalWrite(D_CTRL_NEXT_PIN, LOW);
  digitalWrite(D_CTRL_LED_PIN, LOW);
#ifdef BLUETOOTH
#if defined(__AVR_ATmega324__) || defined(__AVR_ATmega324A__) || defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega324PB__) || defined(__AVR_ATmega324PB__) || defined(__AVR_ATmega328PB__)
  Serial1.begin(9600);
#else
  Serial.begin(9600);
//
#endif
#endif

#ifdef DISC_TRACK_NUMBER_FROM_MPD
#if defined(__AVR_ATmega324__) || defined(__AVR_ATmega324A__) || defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega324PB__) || defined(__AVR_ATmega324PB__)
  Serial1.begin(115200);
#else
  Serial.begin(115200);
#endif
#endif
  //Serial.println("COM+SNAME+VWCDPIC1");

  unsigned long delay_time = 0;
  int next_high = 0;
  int prev_high = 0;

  Init_VWCDC();
  // starts playing Bluetooth stream
  // SetStateIdleThenPlay();
//#if defined(__AVR_ATmega328P__)
//  Serial.println("__AVR_ATmega328P__ board");
//#endif

// my board __AVR_ATmega328P__
#ifdef DISC_TRACK_NUMBER_FROM_MPD
  //start in idle mode
  SetStateIdle();
#endif
  //Serial.println("COM+TONEOFF");
  while (1)
  {
    CDC_Protocol();

    if (D_CTRL_LED_STATE == 1) {
      digitalWrite(D_CTRL_LED_PIN, HIGH);
    } else {
      digitalWrite(D_CTRL_LED_PIN, LOW);
    }

    if (D_CTRL_NEXT > 0) {
      Serial.println("D_CTRL_NEXT press");
      if (delay_time == 0) {
        delay_time = millis();
        digitalWrite(D_CTRL_NEXT_PIN, HIGH);
        next_high = 1;
      } else if (delay_time + 200 <= millis()) {
        digitalWrite(D_CTRL_NEXT_PIN, LOW);
        next_high = 0;
        delay_time = 0;
        D_CTRL_NEXT = 0;
      }
    } else if (next_high == 1) {
      digitalWrite(D_CTRL_NEXT_PIN, LOW);
      next_high = 0;
    }

    if (D_CTRL_PREV > 0) {
      Serial.println("D_CTRL_PREV press");
      int delay_plus = 150;
      if(D_CTRL_PREV == 1) delay_plus = 250;

      if (delay_time == 0) {
        delay_time = millis();
        digitalWrite(D_CTRL_PREV_PIN, HIGH);
        prev_high = 1;
      } else if (delay_time + delay_plus <= millis()) {
        digitalWrite(D_CTRL_PREV_PIN, LOW);
        prev_high = 0;
        delay_time = 0;
        if (D_CTRL_PREV == 2) {
          D_CTRL_PREV = 0;
        } else {
          D_CTRL_PREV = 2;
        }
      }
    } else if (prev_high == 1) {
      digitalWrite(D_CTRL_NEXT_PIN, LOW);
      prev_high = 0;
    }
  }
}

is it working without your changes ?

Regarding this, how could I test that these buttons are working and I'm receiving those bytes?
DUMPMODE and DUMPMODE2 must be enabled?

No, not working no data from head unit

arduino pin 8 is connected to dataout on the radio?

RADIO PIN -> arduino pin
DataOut -> digital 8 (ICP1)
DataIn -> digital 11(PB3) (10 for atmega328PB)
Clock -> digital 13(PB5)

Yes, Double checked

you should see some commands on serial at startup of radio, mainly disable and enable, depends on state in which radio started

Looks like my head unit is not providing any data, closing