mirror of
https://github.com/danbulant/colors
synced 2026-07-05 11:00:43 +00:00
taiko colors
This commit is contained in:
parent
fd5bc47cb7
commit
f27f15b6ca
4 changed files with 70 additions and 0 deletions
10
README.md
10
README.md
|
|
@ -6,6 +6,16 @@ It's not supposed to be easy to setup, but if you need help just contact me. For
|
||||||
|
|
||||||
Project highly depends on linux (uses sys class to control the LEDs) and requires root (non-root operations are setuid'd internally).
|
Project highly depends on linux (uses sys class to control the LEDs) and requires root (non-root operations are setuid'd internally).
|
||||||
|
|
||||||
|
## Start
|
||||||
|
|
||||||
|
To start it up, you need to run it as root and pass `--loader=ts-node/esm` to node:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo node --loader=ts-node/esm <file>
|
||||||
|
```
|
||||||
|
|
||||||
|
where `<file>` is the file to run (`index.ts` in one of the folders).
|
||||||
|
|
||||||
## Spotify colors
|
## Spotify colors
|
||||||
|
|
||||||
Uses DBUS which needs your username. For now just edit the utils function getUsername to return your username.
|
Uses DBUS which needs your username. For now just edit the utils function getUsername to return your username.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import { exec, readUTF, writeUTF } from "./utils.js";
|
import { exec, readUTF, writeUTF } from "./utils.js";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
|
import struct from "python-struct";
|
||||||
|
import chunker from "stream-chunker";
|
||||||
|
|
||||||
interface IJoyStick {
|
interface IJoyStick {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -24,6 +26,12 @@ export class JoyStick implements IJoyStick {
|
||||||
this.dev = data.dev;
|
this.dev = data.dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createEventStream() {
|
||||||
|
const stream = fs.createReadStream(this.dev);
|
||||||
|
return stream
|
||||||
|
.pipe(chunker(struct.sizeOf("LhBB")));
|
||||||
|
}
|
||||||
|
|
||||||
async getColors() {
|
async getColors() {
|
||||||
const [ red, green, blue ] = (await Promise.all([
|
const [ red, green, blue ] = (await Promise.all([
|
||||||
readUTF(`/sys/class/leds/${this.led}:red/brightness`),
|
readUTF(`/sys/class/leds/${this.led}:red/brightness`),
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node": "^16.9.1",
|
"@types/node": "^16.9.1",
|
||||||
|
"@types/python-struct": "^1.0.0",
|
||||||
"got": "^11.8.2",
|
"got": "^11.8.2",
|
||||||
"node-vibrant": "^3.2.1-alpha.1",
|
"node-vibrant": "^3.2.1-alpha.1",
|
||||||
|
"python-struct": "^1.1.3",
|
||||||
|
"stream-chunker": "^1.2.8",
|
||||||
"ts-node": "^10.2.1",
|
"ts-node": "^10.2.1",
|
||||||
"typescript": "^4.4.3"
|
"typescript": "^4.4.3"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
49
taikoColors/index.ts
Normal file
49
taikoColors/index.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
import { JoyStick } from "../joystick.js";
|
||||||
|
import struct from "python-struct";
|
||||||
|
|
||||||
|
const devices = await JoyStick.getList();
|
||||||
|
enum map {
|
||||||
|
x = 0,
|
||||||
|
circle,
|
||||||
|
triangle,
|
||||||
|
square,
|
||||||
|
L1,
|
||||||
|
R1,
|
||||||
|
L2,
|
||||||
|
R2,
|
||||||
|
share,
|
||||||
|
options,
|
||||||
|
ps,
|
||||||
|
L3,
|
||||||
|
R3
|
||||||
|
}
|
||||||
|
enum EventTypes {
|
||||||
|
button = 1,
|
||||||
|
axis = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
for(const device of devices) {
|
||||||
|
device.setColors({
|
||||||
|
red: 0,
|
||||||
|
green: 0,
|
||||||
|
blue: 0
|
||||||
|
});
|
||||||
|
let pressed = new Set<number>();
|
||||||
|
device.createEventStream().on("data", (buf) => {
|
||||||
|
const data = struct.unpack("LhBB", buf);
|
||||||
|
if(data[2] !== EventTypes.button) return;
|
||||||
|
if(data[1] === 1) {
|
||||||
|
pressed.add(Number(data[3]));
|
||||||
|
console.log("Pressed", data[3]);
|
||||||
|
} else {
|
||||||
|
pressed.delete(Number(data[3]));
|
||||||
|
console.log("Unpressed", data[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
device.setColors({
|
||||||
|
red: (pressed.has(map.R1) || pressed.has(map.R2)) ? 255 : 0,
|
||||||
|
green: 0,
|
||||||
|
blue: (pressed.has(map.L1) || pressed.has(map.L2)) ? 255 : 0
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue