Changeset deff6b4 in mainline
- Timestamp:
- 2011-11-25T23:23:50Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 485a496
- Parents:
- be51d73
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/mixerctl/mixerctl.c
rbe51d73 rdeff6b4 36 36 #include <errno.h> 37 37 #include <str_error.h> 38 #include <str.h> 38 39 #include <devman.h> 39 40 #include <audio_mixer_iface.h> … … 95 96 } 96 97 } 98 /*----------------------------------------------------------------------------*/ 99 static 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 /*----------------------------------------------------------------------------*/ 106 static 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 /*----------------------------------------------------------------------------*/ 124 static 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; 97 134 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 /*----------------------------------------------------------------------------*/ 98 144 int main(int argc, char *argv[]) 99 145 { 146 const char *device = DEFAULT_DEVICE; 147 void (*command)(async_exch_t *, int, char*[]) = NULL; 100 148 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)) 103 162 device = argv[1]; 104 163 … … 108 167 if (ret != EOK) { 109 168 printf("Failed to get device(%s) handle: %s.\n", 110 DEFAULT_DEVICE, str_error(ret));169 device, str_error(ret)); 111 170 return 1; 112 171 } … … 126 185 } 127 186 128 print_levels(exch); 187 if (command) { 188 command(exch, argc, argv); 189 } else { 190 print_levels(exch); 191 } 129 192 130 193 async_exchange_end(exch);
Note:
See TracChangeset
for help on using the changeset viewer.