Autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et dolore feugait.
# amixer controls
numid=4,iface=MIXER,name='ADC ALC Left Volume'
numid=5,iface=MIXER,name='ADC ALC Right Volume'
numid=6,iface=MIXER,name='ADC Digital Left Volume'
numid=7,iface=MIXER,name='ADC Digital Right Volume'
numid=8,iface=MIXER,name='ADC HPF Cut-off'
numid=2,iface=MIXER,name='ADC MIC Left Gain'
numid=22,iface=MIXER,name='ADC MIC Left Switch'
numid=3,iface=MIXER,name='ADC MIC Right Gain'
numid=23,iface=MIXER,name='ADC MIC Right Switch'
numid=20,iface=MIXER,name='ADC MICBIAS Voltage'
numid=21,iface=MIXER,name='ADC Main MICBIAS'
numid=19,iface=MIXER,name='ADC Mode'
numid=1,iface=MIXER,name='I2STDM Digital Loopback Mode'
numid=17,iface=MIXER,name='AGC Left Approximate Sample Rate'
numid=18,iface=MIXER,name='AGC Right Approximate Sample Rate'
numid=11,iface=MIXER,name='ALC AGC Left Max Volume'
numid=13,iface=MIXER,name='ALC AGC Left Min Volume'
numid=15,iface=MIXER,name='ALC AGC Left Switch'
numid=9,iface=MIXER,name='ALC AGC Left Volume'
numid=12,iface=MIXER,name='ALC AGC Right Max Volume'
numid=14,iface=MIXER,name='ALC AGC Right Min Volume'
numid=16,iface=MIXER,name='ALC AGC Right Switch'
numid=10,iface=MIXER,name='ALC AGC Right Volume'
numid=26,iface=MIXER,name='DAC Control Manually'
numid=25,iface=MIXER,name='DAC HPMIX Volume'
numid=24,iface=MIXER,name='DAC LINEOUT Volume'
# arecord -D plughw:0,0 -f cd -t wav -d 10 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
# aplay test.wav
Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Instead, adding a single line to /etc/systemd/logind.conf was enough to do the trick:
#HandlePowerKey=poweroff
HandlePowerKey=suspend
Now, pressing the power button causes instant suspend.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <linux/input.h>
struct input_event event;
int main(int argc, char **argv)
{
char name[64]; /* RATS: Use ok, but could be better */
char buf[256] = { 0, }; /* RATS: Use ok */
unsigned char mask[EV_MAX/8 + 1]; /* RATS: Use ok */
int version;
int fd = 0;
int rc;
int i, j;
char *tmp;
#define test_bit(bit) (mask[(bit)/8] & (1 << ((bit)%8)))
for (i = 0; i < 32; i++) {
sprintf(name, "/dev/input/event%d", i);
if ((fd = open(name, O_RDONLY, 0)) >= 0) {
ioctl(fd, EVIOCGVERSION, &version);
ioctl(fd, EVIOCGNAME(sizeof(buf)), buf);
ioctl(fd, EVIOCGBIT(0, sizeof(mask)), mask);
printf("%s\n", name);
printf(" evdev version: %d.%d.%d\n",
version >> 16, (version >> 8) & 0xff, version & 0xff);
printf(" name: %s\n", buf);
printf(" features:");
for (j = 0; j < EV_MAX; j++) {
if (test_bit(j)) {
const char *type = "unknown";
switch(j) {
case EV_KEY: type = "keys/buttons"; break;
case EV_REL: type = "relative"; break;
case EV_ABS: type = "absolute"; break;
case EV_MSC: type = "reserved"; break;
case EV_LED: type = "leds"; break;
case EV_SND: type = "sound"; break;
case EV_REP: type = "repeat"; break;
case EV_FF: type = "feedback"; break;
}
printf(" %s", type);
}
}
printf("\n");
close(fd);
}
}
if (argc > 1) {
sprintf(name, "/dev/input/event%d", atoi(argv[1]));
if ((fd = open(name, O_RDWR, 0)) >= 0) {
printf("%s: open, fd = %d\n", name, fd);
for (i = 0; i < LED_MAX; i++) {
event.time.tv_sec = time(0);
event.time.tv_usec = 0;
event.type = EV_LED;
event.code = i;
event.value = 0;
write(fd, &event, sizeof(event));
}
while ((rc = read(fd, &event, sizeof(event))) > 0) {
printf("%-24.24s.%06lu type 0x%04x; code 0x%04x;"
" value 0x%08x; ",
ctime(&event.time.tv_sec),
event.time.tv_usec,
event.type, event.code, event.value);
switch (event.type) {
case EV_KEY:
if (event.code > BTN_MISC) {
printf("Button %d %s",
event.code & 0xff,
event.value ? "press" : "release");
} else {
printf("Key %d (0x%x) %s",
event.code & 0xff,
event.code & 0xff,
event.value ? "press" : "release");
}
break;
case EV_REL:
switch (event.code) {
case REL_X: tmp = "X"; break;
case REL_Y: tmp = "Y"; break;
case REL_HWHEEL: tmp = "HWHEEL"; break;
case REL_DIAL: tmp = "DIAL"; break;
case REL_WHEEL: tmp = "WHEEL"; break;
case REL_MISC: tmp = "MISC"; break;
default: tmp = "UNKNOWN"; break;
}
printf("Relative %s %d", tmp, event.value);
break;
case EV_ABS:
switch (event.code) {
case ABS_X: tmp = "X"; break;
case ABS_Y: tmp = "Y"; break;
case ABS_Z: tmp = "Z"; break;
case ABS_RX: tmp = "RX"; break;
case ABS_RY: tmp = "RY"; break;
case ABS_RZ: tmp = "RZ"; break;
case ABS_THROTTLE: tmp = "THROTTLE"; break;
case ABS_RUDDER: tmp = "RUDDER"; break;
case ABS_WHEEL: tmp = "WHEEL"; break;
case ABS_GAS: tmp = "GAS"; break;
case ABS_BRAKE: tmp = "BRAKE"; break;
case ABS_HAT0X: tmp = "HAT0X"; break;
case ABS_HAT0Y: tmp = "HAT0Y"; break;
case ABS_HAT1X: tmp = "HAT1X"; break;
case ABS_HAT1Y: tmp = "HAT1Y"; break;
case ABS_HAT2X: tmp = "HAT2X"; break;
case ABS_HAT2Y: tmp = "HAT2Y"; break;
case ABS_HAT3X: tmp = "HAT3X"; break;
case ABS_HAT3Y: tmp = "HAT3Y"; break;
case ABS_PRESSURE: tmp = "PRESSURE"; break;
case ABS_DISTANCE: tmp = "DISTANCE"; break;
case ABS_TILT_X: tmp = "TILT_X"; break;
case ABS_TILT_Y: tmp = "TILT_Y"; break;
case ABS_MISC: tmp = "MISC"; break;
default: tmp = "UNKNOWN"; break;
}
printf("Absolute %s %d", tmp, event.value);
break;
case EV_MSC: printf("Misc"); break;
case EV_LED: printf("Led"); break;
case EV_SND: printf("Snd"); break;
case EV_REP: printf("Rep"); break;
case EV_FF: printf("FF"); break;
break;
}
printf("\n");
}
printf("rc = %d, (%s)\n", rc, strerror(errno));
close(fd);
}
}
return 0;
}
按下电源按键之后,最终实践发现是event2,可以监听到key code以及按键的动作;
...
/dev/input/event2: open, fd = 3
Thu Mar 21 21:38:28 2019.801129 type 0x0001; code 0x0074; value 0x00000001; Key 116 (0x74) press
Thu Mar 21 21:38:28 2019.801129 type 0x0000; code 0x0000; value 0x00000000;
Thu Mar 21 21:38:28 2019.801159 type 0x0001; code 0x0074; value 0x00000000; Key 116 (0x74) release
Thu Mar 21 21:38:28 2019.801159 type 0x0000; code 0x0000; value 0x00000000;
Thu Mar 21 21:38:35 2019.038000 type 0x0001; code 0x0074; value 0x00000001; Key 116 (0x74) press
Thu Mar 21 21:38:35 2019.038000 type 0x0000; code 0x0000; value 0x00000000;
Thu Mar 21 21:38:35 2019.038028 type 0x0001; code 0x0074; value 0x00000000; Key 116 (0x74) release
Thu Mar 21 21:38:35 2019.038028 type 0x0000; code 0x0000; value 0x00000000;
将 Listen 修改为 0.0.0.0:631
将 Browsing 修改为 Yes
对应位置加上 Allow all
# Only listen for connections from the local machine.
Listen localhost:631 // [!code --]
Listen 0.0.0.0:631 // [!code ++]
Listen /run/cups/cups.sock
# Show shared printers on the local network.
Browsing Off // [!code --]
Browsing Yes // [!code ++]
BrowseLocalProtocols dnssd
# Restrict access to the server...
Order allow,deny
Allow all // [!code ++]
# Restrict access to the admin pages...
Order allow,deny
Allow all // [!code ++]
# Restrict access to configuration files...
AuthType Default
Require user @SYSTEM
Order allow,deny
Allow all // [!code ++]
# Restrict access to log files...
AuthType Default
Require user @SYSTEM
Order allow,deny
Allow all // [!code ++]
xiaobao@armbian:~/software/shareprint$ hp-setup -i
HP Linux Imaging and Printing System (ver. 3.23.12)
Printer/Fax Setup Utility ver. 9.0
Copyright (c) 2001-18 HP Development Company, LP
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to distribute it
under certain conditions. See COPYING file for more details.
(Note: Defaults for each question are maked with a '*'. Press <enter> to accept the default.)
--------------------------------
| SELECT CONNECTION (I/O) TYPE |
--------------------------------
Num Connection Description
Type
-------- ---------- ----------------------------------------------------------
0* usb Universal Serial Bus (USB)
1 net Network/Ethernet/Wireless (direct connection or JetDirect)
Enter number 0...1 for connection type (q=quit, enter=usb*) ? 0
Using connection type: usb
Setting up device: hp:/usb/DeskJet_1110_series?serial=CN75J28090069Z
---------------------
| PRINT QUEUE SETUP |
---------------------
Please enter a name for this print queue (m=use model name:'DeskJet_1110'*, q=quit) ?
Using queue name: DeskJet_1110
Locating PPD file... Please wait.
Found PPD file: hplip:0/ppd/hplip/HP/hp-deskjet_1110_series.ppd
Description:
Note: The model number may vary slightly from the actual model number on the device.
Does this PPD file appear to be the correct one (y=yes*, n=no, q=quit) ?
Enter a location description for this printer (q=quit) ?
Enter additonal information or notes for this printer (q=quit) ?
Adding print queue to CUPS:
Device URI: hp:/usb/DeskJet_1110_series?serial=CN75J28090069Z
Queue name: DeskJet_1110
PPD file: hplip:0/ppd/hplip/HP/hp-deskjet_1110_series.ppd
Location:
Information:
You do not have permission to add a printer. You need authentication.
Username: root
Password:
---------------------
| PRINTER TEST PAGE |
---------------------
Would you like to print a test page (y=yes*, n=no, q=quit) ? y
HP Linux Imaging and Printing System (ver. 3.23.12)
Testpage Print Utility ver. 6.0
Copyright (c) 2001-18 HP Development Company, LP
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to distribute it
under certain conditions. See COPYING file for more details.
HP Linux Imaging and Printing System (ver. 3.23.12)
System Tray Status Service ver. 2.0
Copyright (c) 2001-18 HP Development Company, LP
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to distribute it
under certain conditions. See COPYING file for more details.
warning: No display found.
error: hp-systray requires Qt4 GUI and DBus support. Exiting.
warning: Unable to connect to dbus. Is hp-systray running?
Printing test page to printer DeskJet_1110...
请求 ID 为 DeskJet_1110-1 (1 个文件)
Test page has been sent to printer.
note: If an error occured, or the test page failed to print, refer to the HPLIP website
note: at: http://hplip.sourceforge.net for troubleshooting and support.
Done.
Done.