{"size": 593, "ext": "js", "max_stars_repo_path": "examples/brightness.js", "max_stars_repo_name": "TimLuq/stream-deck-ts", "max_stars_repo_stars_event_min_datetime": "2018-12-22T15:45:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-11T14:08:35.000Z", "max_issues_repo_path": "examples/brightness.js", "max_issues_repo_name": "TimLuq/stream-deck-ts", "max_issues_repo_issues_event_min_datetime": "2019-02-07T17:59:49.000Z", "max_issues_repo_issues_event_max_datetime": "2019-02-07T17:59:49.000Z", "max_forks_repo_path": "examples/brightness.js", "max_forks_repo_name": "TimLuq/stream-deck-ts", "max_forks_repo_forks_event_min_datetime": "2020-11-29T21:00:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-29T21:00:32.000Z"}
{"max_stars_count": 7, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 25.7826086957, "max_line_length": 78, "alphanum_fraction": 0.6728499157}
"use strict";

const { selectDevice } = require("..");

exports.default = Promise.resolve(selectDevice()).then(function (streamDeck) {
	// Fill it white so we can see the brightness changes
	streamDeck.forEachKey((k, d) => {
		return d.fillColor(k, 0xFFFFFF);
	});

	streamDeck.on("down", (keyIndex) => {
		const percentage = (100 / (streamDeck.buttonLength - 1)) * keyIndex;
		console.log(`Setting brightness to ${percentage.toFixed(2)}%`);
		streamDeck.setBrightness(percentage);
	});

	streamDeck.on("error", (error) => {
		console.error("HID error:", error);
	});

	return streamDeck;
});
