Add files via upload
This commit is contained in:
parent
24234025e4
commit
89bee96906
105
SOFTWARE/A64-TERES/teres1-audioselect/teres1-audioselect.c
Normal file
105
SOFTWARE/A64-TERES/teres1-audioselect/teres1-audioselect.c
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
/* teres1-audiocontrol.c - audio input/output manager
|
||||||
|
|
||||||
|
Copyright (C) 2017 Chris Boudacoff
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, version 2 of the License.
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <linux/input.h>
|
||||||
|
|
||||||
|
|
||||||
|
void usage(void)
|
||||||
|
{
|
||||||
|
extern char *program_invocation_short_name;
|
||||||
|
printf("USAGE:\n");
|
||||||
|
printf(" %s /dev/input/eventX\n", program_invocation_short_name);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
const char *device = NULL;
|
||||||
|
int fd;
|
||||||
|
struct input_event ie;
|
||||||
|
|
||||||
|
if (!argv[1])
|
||||||
|
{
|
||||||
|
usage();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
device = argv[1];
|
||||||
|
|
||||||
|
if((fd = open(device, O_RDONLY)) == -1)
|
||||||
|
{
|
||||||
|
perror("Could not open input device");
|
||||||
|
exit(255);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
while(read(fd, &ie, sizeof(struct input_event)))
|
||||||
|
{
|
||||||
|
printf("type %d\tcode %d\tvalue %d\n", ie.type, ie.code, ie.value);
|
||||||
|
switch (ie.type)
|
||||||
|
{
|
||||||
|
|
||||||
|
case 5: // pluged
|
||||||
|
switch (ie.code) {
|
||||||
|
|
||||||
|
case 2: // headphones
|
||||||
|
printf("Headphones: %d\n", ie.value);
|
||||||
|
if (ie.value == 0)
|
||||||
|
{
|
||||||
|
system("amixer -c 0 set \"External Speaker\" on > /dev/null");
|
||||||
|
system("amixer -c 0 set \"Headphone\" off > /dev/null");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
system("amixer -c 0 set \"External Speaker\" off > /dev/null");
|
||||||
|
system("amixer -c 0 set \"Headphone\" on > /dev/null");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4: // mice
|
||||||
|
printf("Microphone: %d\n", ie.value);
|
||||||
|
if (ie.value == 0)
|
||||||
|
{
|
||||||
|
system("amixer -c 0 sset \"RADC input Mixer MIC1 boost\" unmute > /dev/null" );
|
||||||
|
system("amixer -c 0 sset \"LADC input Mixer MIC1 boost\" unmute > /dev/null");
|
||||||
|
system("amixer -c 0 sset \"RADC input Mixer MIC2 boost\" mute > /dev/null");
|
||||||
|
system("amixer -c 0 sset \"LADC input Mixer MIC2 boost\" mute > /dev/null");
|
||||||
|
system("amixer -c 0 sset \"ADCL Mux\" ADC > /dev/null");
|
||||||
|
system("amixer -c 0 sset \"ADCR Mux\" ADC > /dev/null");
|
||||||
|
system("amixer -c 0 sset \"AIF1 AD0L Mixer ADCL\" ADC > /dev/null");
|
||||||
|
system("amixer -c 0 sset \"AIF1 AD0R Mixer ADCR\" ADC > /dev/null");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
system("amixer -c 0 sset \"RADC input Mixer MIC2 boost\" unmute > /dev/null");
|
||||||
|
system("amixer -c 0 sset \"LADC input Mixer MIC2 boost\" unmute > /dev/null");
|
||||||
|
system("amixer -c 0 sset \"RADC input Mixer MIC1 boost\" mute > /dev/null");
|
||||||
|
system("amixer -c 0 sset \"LADC input Mixer MIC1 boost\" mute > /dev/null");
|
||||||
|
system("amixer -c 0 sset \"ADCL Mux\" ADC > /dev/null");
|
||||||
|
system("amixer -c 0 sset \"ADCR Mux\" ADC > /dev/null");
|
||||||
|
system("amixer -c 0 sset \"AIF1 AD0L Mixer ADCL\" ADC > /dev/null");
|
||||||
|
system("amixer -c 0 sset \"AIF1 AD0R Mixer ADCR\" ADC > /dev/null");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=teres1-audioselect
|
||||||
|
After=basic.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/usr/bin/teres1-audioselect /dev/input/by-path/platform-sound.6-event
|
||||||
|
TimeoutStopSec=1
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
|
StartLimitInterval=0
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=basic.target
|
Loading…
Reference in New Issue
Block a user