-
Notifications
You must be signed in to change notification settings - Fork 11
/
xonard.h
163 lines (138 loc) · 4.16 KB
/
xonard.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* Xonard
*
* Copyright 2012-2013 Alessandro Pignotti
*
* 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, either version 3 of the License, or
* (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file xonard.h
* \brief Xonard daemon
*/
#ifndef XONARD_H
#define XONARD_H
#include <linux/input.h>
#include <linux/uinput.h>
#include <linux/hidraw.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <assert.h>
#include <syslog.h>
#include <signal.h>
#include <errno.h>
#include "xonar.h"
#if ENABLE_CTL == 1
/**
* \brief Initialize Inter-Process communication, create a unix socket.
* \return A file descriptor to a socket on success or a negative number on
* error.
*/
int initIPC();
/**
* \brief Stop Inter-Process communication.
* \param[in] sockfd A file descriptor to the unix socket.
*/
void destroyIPC(int sockfd);
/**
* \brief Get message from the socket.
* \param[in] sockfd A file descriptor to the unix socket.
* \return The bytes received from the unix socket.
*/
char *getMsg(int sockfd);
/**
* \brief Wait for an incoming message.
* \param[in] sockfd A file descriptor to the unix socket.
*/
void waitMsg(int sockfd);
/**
* \brief Wait for an event from both file descriptor.
* \param[in] sockfd A file descriptor to the socket.
* \param[in] hidfd A file descriptor to the hidraw interface.
* \return The file descriptor referring to the event.
*/
int waitForEvent(int sockfd, int hidfd);
/**
* \brief Check if data is available on the socket.
* \param[in] sockfd A file descriptor to the socket.
*/
int dataReady(int sockfd);
/**
* \brief Process data packet received from the socket.
* \param[in] hidfd A file descriptor to the hidraw interface.
* \param[in] payload The bytes received from the socket.
*/
void processPacket(int hidfd, char *payload);
#endif
/**
* \brief Print message to syslog.
* \param[in] msg Message to print.
*/
void logMsg(char *msg);
/**
* \brief Print error message with the translated errno string to syslog.
* \param[in] msg Message to print.
*/
void logErrorMsg(char *msg);
/**
* \brief Print raw error message to syslog.
* \param[in] msg Message to print.
*/
void logErrorMsgRaw(char *msg);
/**
* \brief Change global configuration.
* \param[in] hidfd File descriptor to the hidraw interface.
* \param[in] conf Configuration bytes to send.
* \return 0 on success.
*/
int sendGlobalConfPacket(int hidfd, uint8_t conf);
/**
* \brief Change blinking configuration.
* \param[in] hidfd File descriptor to the hidraw interface.
* \param[in] ledIndex Can be ASUS_XONAR_U1_BLUE_LED or ASUS_XONAR_U1_RED_LED.
* \param[in] dutyCycleA (in 20ms increment)Time spent OFF for the blue led or time spent ON for
* the red led.
* \param[in] dutyCycleTotal (in 20ms increment) Total time of a blinking cycle.
* \return 0 on success.
*/
int sendBlinkConfPacket(int hidfd, uint8_t ledIndex, uint8_t dutyCycleA, uint8_t dutyCycleTotal);
/**
* \brief Exit the program showing the error message from ioctl.
*/
void bailoutUinputConfig();
/**
* \brief Hook all the key events we want to send.
*/
void hookKeyEvents(int uinputfd);
/**
* \brief Send a keypress to an uinput file descriptor.
* \param[in] uinputfd uinput file descriptor.
* \param[in] keyCode Keycode to send.
*/
void sendKeyPress(int uinputfd, int keyCode);
/**
* \brief Send a KEY_VOLUMEDOWN to uinput.
* \param[in] uinputfd File descriptor to uinput.
*/
void handleVolumeDown(int uinputfd);
/**
* \brief Send a KEY_VOLUMEUP to uinput.
* \param[in] uinputfd File descriptor to uinput.
*/
void handleVolumeUp(int uinputfd);
/**
* \brief Send a KEY_MUTE to uinput.
* \param[in] uinputfd File descriptor to uinput.
*/
void handleMute(int uinputfd);
#endif