Changeset deff6b4 in mainline


Ignore:
Timestamp:
2011-11-25T23:23:50Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
485a496
Parents:
be51d73
Message:

mixerctl: Add support for volume set/get.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/mixerctl/mixerctl.c

    rbe51d73 rdeff6b4  
    3636#include <errno.h>
    3737#include <str_error.h>
     38#include <str.h>
    3839#include <devman.h>
    3940#include <audio_mixer_iface.h>
     
    9596        }
    9697}
     98/*----------------------------------------------------------------------------*/
     99static unsigned get_number(const char* str)
     100{
     101        uint16_t num;
     102        str_uint16_t(str, NULL, 10, false, &num);
     103        return num;
     104}
     105/*----------------------------------------------------------------------------*/
     106static void set_volume(async_exch_t *exch, int argc, char *argv[])
     107{
     108        assert(exch);
     109        if (argc != 5 && argc != 6) {
     110                printf("%s [device] setvolume item channel value\n", argv[0]);
     111        }
     112        unsigned params = argc == 6 ? 3 : 2;
     113        const unsigned item = get_number(argv[params++]);
     114        const unsigned channel = get_number(argv[params++]);
     115        const unsigned value = get_number(argv[params]);
     116        int ret = audio_mixer_channel_volume_set(exch, item, channel, value);
     117        if (ret != EOK) {
     118                printf("Failed to set mixer volume: %s.\n", str_error(ret));
     119                return;
     120        }
     121        printf("Channel %u-%u volume set to %u.\n", item, channel, value);
     122}
     123/*----------------------------------------------------------------------------*/
     124static void get_volume(async_exch_t *exch, int argc, char *argv[])
     125{
     126        assert(exch);
     127        if (argc != 4 && argc != 5) {
     128                printf("%s [device] getvolume item channel\n", argv[0]);
     129        }
     130        unsigned params = argc == 5 ? 3 : 2;
     131        const unsigned item = get_number(argv[params++]);
     132        const unsigned channel = get_number(argv[params++]);
     133        unsigned value = 0, max = 0;
    97134
     135        int ret = audio_mixer_channel_volume_get(
     136            exch, item, channel, &value, &max);
     137        if (ret != EOK) {
     138                printf("Failed to get mixer volume: %s.\n", str_error(ret));
     139                return;
     140        }
     141        printf("Channel %u-%u volume: %u/%u.\n", item, channel, value, max);
     142}
     143/*----------------------------------------------------------------------------*/
    98144int main(int argc, char *argv[])
    99145{
     146        const char *device = DEFAULT_DEVICE;
     147        void (*command)(async_exch_t *, int, char*[]) = NULL;
    100148
    101         const char *device = DEFAULT_DEVICE;
    102         if (argc == 2)
     149        if (argc >= 2 && str_cmp(argv[1], "setvolume") == 0) {
     150                command = set_volume;
     151                if (argc == 6)
     152                        device = argv[1];
     153        }
     154
     155        if (argc >= 2 && str_cmp(argv[1], "getvolume") == 0) {
     156                command = get_volume;
     157                if (argc == 5)
     158                        device = argv[1];
     159        }
     160
     161        if ((argc == 2 && command == NULL))
    103162                device = argv[1];
    104163
     
    108167        if (ret != EOK) {
    109168                printf("Failed to get device(%s) handle: %s.\n",
    110                     DEFAULT_DEVICE, str_error(ret));
     169                    device, str_error(ret));
    111170                return 1;
    112171        }
     
    126185        }
    127186
    128         print_levels(exch);
     187        if (command) {
     188                command(exch, argc, argv);
     189        } else {
     190                print_levels(exch);
     191        }
    129192
    130193        async_exchange_end(exch);
Note: See TracChangeset for help on using the changeset viewer.