Esempio n. 1
0
int mixer_ctl_set(struct mixer_ctl *ctl, unsigned percent)
{
    struct snd_ctl_elem_value ev;
    unsigned n;

    memset(&ev, 0, sizeof(ev));
    ev.id.numid = ctl->info->id.numid;
    switch (ctl->info->type) {
    case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
        for (n = 0; n < ctl->info->count; n++)
            ev.value.integer.value[n] = !!percent;
        break;
    case SNDRV_CTL_ELEM_TYPE_INTEGER: {
        long value = scale_int(ctl->info, percent);
        for (n = 0; n < ctl->info->count; n++)
            ev.value.integer.value[n] = value;
        break;
    }
    case SNDRV_CTL_ELEM_TYPE_INTEGER64: {
        long long value = scale_int64(ctl->info, percent);
        for (n = 0; n < ctl->info->count; n++)
            ev.value.integer64.value[n] = value;
        break;
    }
    default:
        errno = EINVAL;
        return -1;
    }

    return ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev);
}
Esempio n. 2
0
int mixer_ctl_set(struct mixer_ctl *ctl, unsigned percent)
{
    struct snd_ctl_elem_value ev;
    unsigned n;
    long min, max;
    unsigned int *tlv = NULL;
    enum ctl_type type;
    int volume = 0;
    unsigned int tlv_type;

    if (!ctl) {
        ALOGV("can't find control\n");
        return -1;
    }

    if (is_volume(ctl->info->id.name, &type)) {
        ALOGV("capability: volume\n");
        tlv = calloc(1, DEFAULT_TLV_SIZE);
        if (tlv == NULL) {
            ALOGE("failed to allocate memory\n");
        } else if (!mixer_ctl_read_tlv(ctl, tlv, &min, &max, &tlv_type)) {
            switch(tlv_type) {
            case SNDRV_CTL_TLVT_DB_LINEAR:
            case SNDRV_CTL_TLVT_DB_MINMAX:
                ALOGV("tlv db linear/db minmax: b4 %d\n", percent);

		if (min < 0) {
			max = max - min;
			min = 0;
		}
                percent = check_range(percent, min, max);
                ALOGV("tlv db linear: %d %d %d\n", percent, min, max);
                volume = 1;
                break;
            default:
                percent = (long)percent_to_index(percent, min, max);
                percent = check_range(percent, min, max);
                volume = 1;
                break;
            }
        } else
            ALOGV("mixer_ctl_read_tlv failed\n");
        free(tlv);
    }
    memset(&ev, 0, sizeof(ev));
    ev.id.numid = ctl->info->id.numid;
    switch (ctl->info->type) {
    case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
        for (n = 0; n < ctl->info->count; n++)
            ev.value.integer.value[n] = !!percent;
        break;
    case SNDRV_CTL_ELEM_TYPE_INTEGER: {
        int value;
        if (!volume)
             value = scale_int(ctl->info, percent);
        else
             value = (int) percent;
        for (n = 0; n < ctl->info->count; n++)
            ev.value.integer.value[n] = value;
        break;
    }
    case SNDRV_CTL_ELEM_TYPE_INTEGER64: {
        long long value;
        if (!volume)
             value = scale_int64(ctl->info, percent);
        else
             value = (long long)percent;
        for (n = 0; n < ctl->info->count; n++)
            ev.value.integer64.value[n] = value;
        break;
    }
    case SNDRV_CTL_ELEM_TYPE_IEC958: {
        struct snd_aes_iec958 *iec958;
        iec958 = (struct snd_aes_iec958 *)percent;
        memcpy(ev.value.iec958.status,iec958->status,SPDIF_CHANNEL_STATUS_SIZE);
        break;
    }
    case SNDRV_CTL_ELEM_TYPE_ENUMERATED: {
        for (n = 0; n < ctl->info->count; n++) {
            ev.value.enumerated.item[n] = (unsigned int)percent;
        }
        break;
    }
    default:
        errno = EINVAL;
        return errno;
    }

    return ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev);
}
Esempio n. 3
0
bool  vrpn_IDEA::send_move_request(vrpn_float64 location_in_steps, double scale)
{
  char  cmd[512];

  //-----------------------------------------------------------------------
  // Configure input interrupts.  We want a falling-edge trigger for the
  // inputs, calling the appropriate subroutine.  We only enable the
  // high limit switch when moving forward and only the low one when moving
  // backwards.  If neither limit switch is set, we don't ever need to
  // send anything.
  if ( (d_high_limit_index > 0) || (d_low_limit_index > 0) ) {
    int edge_masks[4] = { 0, 0, 0, 0 };
    int address_masks[4] = { 0, 0, 0, 0 };
    int priority_masks[4] = { 0, 0, 0, 0 };

    // If we're moving forward and there is a high limit switch, set
    // up to use it.
    if ( (location_in_steps > channel[0]) && (d_high_limit_index > 0) ) {
      edge_masks[d_high_limit_index - 1] = 2;       // Falling edge
      address_masks[d_high_limit_index - 1] = 40;   // Address of program
    }

    // If we're moving backwards and there is a low limit switch, set
    // up to use it.
    if ( (location_in_steps > channel[0]) && (d_low_limit_index > 0) ) {
      edge_masks[d_low_limit_index - 1] = 2;        // Falling edge
      address_masks[d_low_limit_index - 1] = 80;    // Address of program
    }

    if (sprintf(cmd, "i,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
      edge_masks[0], edge_masks[1], edge_masks[2], edge_masks[3],
      address_masks[0], address_masks[1], address_masks[2], address_masks[3],
      priority_masks[0], priority_masks[1], priority_masks[2], priority_masks[3]
    ) <= 0) {
      IDEA_ERROR("vrpn_IDEA::send_move_request(): Could not configure interrupt command");
      status = STATUS_RESETTING;
      return false;
    }
    if (!send_command(cmd)) {
      IDEA_ERROR("vrpn_IDEA::send_move_request(): Could not configure interrupts");
      status = STATUS_RESETTING;
      return false;
    }        
  }

  long steps_64th = static_cast<long>(location_in_steps*64);
  sprintf(cmd, "M%ld,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
    steps_64th,
    d_run_speed_tics_sec,
    scale_int(d_start_speed_tics_sec,scale),
    scale_int(d_end_speed_tics_sec, scale),
    scale_int(d_accel_rate_tics_sec_sec, scale),
    scale_int(d_decel_rate_tics_sec_sec, scale),
    scale_int(d_run_current, scale),
    scale_int(d_hold_current, scale),
    scale_int(d_accel_current, scale),
    scale_int(d_decel_current, scale),
    d_delay,
    d_step);
  return send_command(cmd);
}