libpng:update and moved to /usr/lib
[nyanlinux.git] / files / rival3
blob82ce75f2f37bd3d99cb0abc16ef20cf7fbb927cb
1 #!/bin/sh
2 # hiddev != hidraw, hiddev does parsing and more, not hidraw
3 effects='rainbow-shift|breath-fast|breath|breath-slow|steady|rainbow-breath|disco'
4 effect_to_hex()
6 case $effect in
7 rainbow-shift) effect=00;;
8 breath-fast) effect=01;;
9 breath) effect=02;;
10 breath-slow) effect=03;;
11 steady) effect=04;;
12 rainbow-breath) effect=05;;
13 disco) effect=06;;
15 printf "\nERROR:invalid effect ($effects)\n"
16 exit 1
18 esac
21 # not implemented, because factory default value is ok
22 # set polling rate in Hz:
23 # command=04 00
24 # suffix=00 00 00 00 00 00
25 # values=
26 # 125 Hz=04
27 # 250 Hz=03
28 # 500 Hz=02
29 # 1000 Hz=01 (factory default)
30 USAGE="Usage: $0 -z1 color(hex 3 bytes rrggbb) -z2 color(hex 3 bytes rrggbb) -z3 color(hex 3 bytes rrggbb) -logo color(hex 3 bytes rrggbb) -s dpi1,dpi2,dpi3,dpi4,dpi5(40-8500/40 increment) -e effect($effects) -save"
31 if test $# -eq 0; then
32 echo $USAGE
33 exit 0
36 # vendor_id=0x1038
37 # product_id=0x1824
38 # product_id=0x182c, firmware v0.37.0.0
39 # endpoint index 3 (there are 4 endpoints)
40 endpoint=0
41 for l in /sys/class/hidraw/*; do
42 if readlink -f $l | egrep '1038:1824' >/dev/null 2>&1; then
43 if test $endpoint -eq 3; then
44 rival3=/dev/$(basename $l)
45 break
46 fi
47 endpoint=$(($endpoint + 1))
48 elif readlink -f $l | egrep -i '1038:182c' >/dev/null 2>&1; then
49 if test $endpoint -eq 3; then
50 rival3=/dev/$(basename $l)
51 break
52 fi
53 endpoint=$(($endpoint + 1))
55 done
57 if test "${rival3-unset}" = unset; then
58 echo ERROR:unable to locate a rival3
59 exit 1
60 else
61 echo $rival3
64 while test $# -ne 0; do
65 case $1 in
66 -z1)
67 if test "$2" = ""; then
68 echo missing rgb_hex
69 exit 1
71 rgb_hex_z1=$2
72 shift 2
74 -z2)
75 if test "$2" = ""; then
76 echo missing rgb_hex
77 exit 1
79 rgb_hex_z2=$2
80 shift 2
82 -z3)
83 if test "$2" = ""; then
84 echo missing rgb_hex
85 exit 1
87 rgb_hex_z3=$2
88 shift 2
90 -logo)
91 if test "$2" = ""; then
92 echo missing rgb_hex
93 exit 1
95 rgb_hex_logo=$2
96 shift 2
98 -s)
99 if test "$2" = ""; then
100 echo missing sensitivities
101 exit 1
103 sensitivities=$2
104 shift 2
107 if test "$2" = ""; then
108 echo missing effect
109 exit 1
111 effect=$2
112 shift 2
114 -save)
115 save=yes
116 shift
119 echo ignoring $1
120 shift
122 esac
123 done
125 # each command is padded to 9 bytes
126 if test "${rgb_hex_z1-unset}" != unset; then
127 echo "rgb_hex_z1=$rgb_hex_z1";
128 cmd_hex=050001${rgb_hex_z1}64
130 if test "${rgb_hex_z2-unset}" != unset; then
131 echo "rgb_hex_z2=$rgb_hex_z2";
132 cmd_hex=050002${rgb_hex_z2}64
134 if test "${rgb_hex_z3-unset}" != unset; then
135 echo "rgb_hex_z3=$rgb_hex_z3";
136 cmd_hex=050003${rgb_hex_z3}64
138 if test "${rgb_hex_logo-unset}" != unset; then
139 echo "rgb_hex_logo=$rgb_hex_logo";
140 cmd_hex=0500004${rgb_hex_logo}64
142 if test "${sensitivities-unset}" != unset; then
143 printf "sensitivities = $sensitivities"
144 IFS_SAVED="$IFS"
145 IFS=','
146 dpi_n=0
147 sensitivities_rounded="/rounded_to ="
148 for dpi in $sensitivities
150 dpi_step=$(printf "$dpi/40" | bc)
151 dpi_rounded=$(printf "$dpi_step * 40" | bc)
152 sensitivities_rounded="${sensitivities_rounded} ${dpi_rounded}"
153 if test $dpi_rounded -lt 40; then
154 printf "\n$dpi_rounded from $dpi is below 40\n"
155 exit
157 if test $dpi_rounded -gt 8500; then
158 printf "\n$dpi_rounded from $dpi is above 8500\n"
159 exit
161 output=$(($dpi_step - 1))
162 output_hex=$(printf "%02x" $output)
163 sensitivities_hex="${sensitivities_hex}$output_hex"
164 dpi_n=$(printf "%02x" $(($dpi_n + 1)))
165 done
166 IFS="$IFS_SAVED"
167 printf "$sensitivities_rounded"
168 if test $dpi_n -gt 5; then
169 printf "\ndpi preset count is above 5\n"
170 exit
172 echo "/hexcode = ${dpi_n}${sensitivities_hex}"
173 cmd_hex=${cmd_hex}0b00${dpi_n}01${sensitivities_hex}
175 if test "${effect-unset}" != unset; then
176 printf "effect=$effect"
177 effect_to_hex
178 echo "/hexcode=$effect"
179 cmd_hex=${cmd_hex}0600${effect}
181 # must be last for an obvious reason
182 if test "${save-unset}" != unset; then
183 echo "****will save settings in mouse persistent memory****"
184 cmd_hex=${cmd_hex}0900
186 printf "00:$cmd_hex\n" | xxd -r >$rival3