-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbc2417
commit f42e21f
Showing
5 changed files
with
41 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,41 @@ | ||
package input | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
) | ||
|
||
func Vibrate(device io.Writer, ms int) (err error) { | ||
_, err = device.Write([]byte(strconv.Itoa(ms))) | ||
return | ||
// Vibrate vibrates the device (duh). The vibratorPath is **not** a device file, | ||
// but rather the path to the device directory. | ||
// It is probably /sys/class/leds/vibrator/, but it could depend on the device. | ||
// Also see https://stackoverflow.com/a/62678837 | ||
func Vibrate(vibratorPath string, milliseconds int) (err error) { | ||
// At first, we write the duration (as string) to the file named "duration", | ||
// then we activate it by writing "1" to the file named "activate" | ||
|
||
// I do not know who thought that it is a good idea to have the | ||
// vibration device under LEDS, but it sure as hell is confusing | ||
|
||
err = writeInt(filepath.Join(vibratorPath, "duration"), milliseconds) | ||
if err != nil { | ||
return | ||
} | ||
|
||
return writeInt(filepath.Join(vibratorPath, "activate"), 1) | ||
} | ||
|
||
func writeInt(path string, i int) (err error) { | ||
f, err := os.OpenFile(path, os.O_WRONLY, os.ModeDevice) | ||
if err != nil { | ||
return | ||
} | ||
|
||
_, err = f.Write([]byte(strconv.Itoa(i))) | ||
if err != nil { | ||
_ = f.Close() | ||
return | ||
} | ||
|
||
return f.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
id=backtap | ||
name=backtap | ||
version=v1.0 | ||
versionCode=00100 | ||
version=v2.0 | ||
versionCode=00200 | ||
author=xarantolus | ||
description=Enables several gestures when tapping the fingerprint sensor of a Xiaomi Mi Mix 2 |