static char rcsid[] =
  "$Id: tuner.c,v 1.8 2001/10/12 13:51:17 root Exp root $";

/*
 * $Log: tuner.c,v $
 * Revision 1.8  2001/10/12 13:51:17  root
 * #
 *
 * Revision 1.7  2000/12/01 04:42:19  root
 * #
 *
 * Revision 1.6  2000/12/01 04:13:51  root
 * #
 *
 * Revision 1.5  2000/10/07 18:30:09  root
 * #
 *
 * Revision 1.4  2000/10/06 19:52:44  root
 * #
 *
 * Revision 1.3  2000/09/24 01:52:21  root
 * #
 *
 * Revision 1.2  2000/09/24 01:46:08  root
 * #
 *
 * Revision 1.1  2000/09/24 01:12:55  root
 * #
 *
 *
 */


#include "project.h"

#include <sys/ioctl.h>
#include <linux/types.h>

#include <asm/io.h>

extern void *msglib;

void
tuner_status (void)
{
  int l, r;
  Byte *buf = hifi_getbuf ();
  Byte *ptr = buf, *cptr;

  Hifi_Tuner_State s;


  ptr = hifipkt_new_brd (ptr, HIFI_CLASS_TUNER, tunerunit);

  ptr = hifipkt_est (cptr = ptr, HIFI_ST_TUNER_STATE);

  s = tuner_state ();
  printf ("%d %d %d\n", s.f.freq, s.stereo, s.lock);

  ptr = hifipkt_etuner_state (ptr, s);

  hifipkt_elen (cptr, HIFI_PTR_DIFF (ptr, cptr));

  mixer_get_tunervol (&l, &r);

  ptr = hifipkt_est (cptr = ptr, HIFI_ST_VOL);
  ptr = hifipkt_ebyte (ptr, l);
  ptr = hifipkt_ebyte (ptr, r);
  hifipkt_elen (cptr, HIFI_PTR_DIFF (ptr, cptr));

  ptr = hifipkt_eeof (ptr);

  hifi_send (msglib, buf, HIFI_PTR_DIFF (ptr, buf));
  hifi_freebuf (buf);
}

void
tuner_cmdst_message (Byte dunit, Word cmd, Byte * data, Word len)
{
  Hifi_Radio_Frequency f;
  Byte l, r;

  if ((dunit != tunerunit) && (dunit != HIFI_UNIT_ALL))
    return;


  switch (cmd)
    {
    case HIFI_CMD_VOL:
      data = hifipkt_dbyte (data, &l);
      data = hifipkt_dbyte (data, &r);

      printf ("Volm set to %d %d\n", l, r);
      mixer_set_tunervol (l, r);
      break;
    case HIFI_CMD_TUNER_SEARCH_UP:
      tuner_search_up ();
      tuner_status ();
      break;
    case HIFI_CMD_TUNER_SEARCH_DOWN:
      tuner_search_down ();
      tuner_status ();
      break;
    case HIFI_CMD_TUNER_MONO:
      tuner_mono ();
      break;
    case HIFI_CMD_TUNER_STEREO:
      tuner_stereo ();
      break;
    case HIFI_CMD_TUNER_TUNE:

      data = hifipkt_dradio_frequency (data, &f);

      printf ("Tuner tune %d %d\n", f.band, f.freq);
      tuner_tune (f);

      return;
      break;
    }

}


void
tuner_open (void)
{
  tea5757h_open ();
}
