'use strict';
var fs = require('fs');
var path = require('path');

module.exports.get = function (cb) {
	var dir = '/sys/class/backlight';

	if (process.platform !== 'linux') {
		throw new Error('Only Linux systems are supported');
	}

	fs.readdir(dir, function (err, dirs) {
		if (err) {
			cb(err);
			return;
		}

		if (!dirs.length) {
			cb(new Error('No backlight device found'));
			return;
		}

		fs.readFile(path.join(dir, dirs[0], 'max_brightness'), 'utf8', function (err, max) {
			if (err) {
				cb(err);
				return;
			}

			fs.readFile(path.join(dir, dirs[0], 'brightness'), 'utf8', function (err, data) {
				if (err) {
					cb(err);
					return;
				}

				cb(null, parseInt(data) / parseInt(max));
			});
		});
	});
};

module.exports.set = function (val, cb) {
	var dir = '/sys/class/backlight';

	if (process.platform !== 'linux') {
		throw new Error('Only Linux systems are supported');
	}

	if (typeof val !== 'number' || val < 0 || val > 1) {
		throw new Error('Expected a number between 0 and 1');
	}

	fs.readdir(dir, function (err, dirs) {
		if (err) {
			cb(err);
			return;
		}

		if (!dirs.length) {
			cb(new Error('No backlight device found'));
			return;
		}

		fs.readFile(path.join(dir, dirs[0], 'max_brightness'), 'utf8', function (err, data) {
			if (err) {
				cb(err);
				return;
			}

			var max = parseInt(data);
			var brightness = Math.floor(val * max).toString();

			fs.writeFile(path.join(dir, dirs[0], 'brightness'), brightness, function (err) {
				if (err) {
					cb(err);
					return;
				}

				cb();
			});
		});
	});
};

@@ -1480,24 +1480,190 @@
 ion (err) %7B%0A
+%09%09%09%09if (err && err.code === 'EACCES') %7B%0A%09%09%09%09%09err.message = 'You don%5C't seem to have permission to change the brightness. Try running this command with sudo.';%0A%09%09%09%09%7D%0A%0A
 %09%09%09%09if (err)

Add a helpful error message if it's a permission error