From 7ae2c22077344530912b53d780e0829128a49316 Mon Sep 17 00:00:00 2001 From: Hello_User Date: Tue, 27 Dec 2022 16:39:07 +0100 Subject: [PATCH] Working slider, resets after sliding --- app.js | 42 ++++++++++++++++++++++++++++++++++++++++++ index.html | 22 ++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 app.js create mode 100644 index.html diff --git a/app.js b/app.js new file mode 100644 index 0000000..c40d195 --- /dev/null +++ b/app.js @@ -0,0 +1,42 @@ +const http = require('http'), + fs = require('fs'); +const { exec } = require('child_process'); +const { parse } = require('querystring'); + +function setBrightness(display, value, res) { + exec(`setbrightness "${value}"`, (error, stdout, stderr) => { + if (error) { + console.error(`exec error: ${error}`); + return; + } + console.log(`stdout: ${stdout}`); + console.log(`stderr: ${stderr}`); + // Redirect the client back to the main page after the command has run + res.writeHead(303, { Location: '/' }); + res.end(); + }); +} + +http.createServer((req, res) => { + if (req.url.startsWith('/button_pressed?')) { + // Parse the query string from the request URL + const query = req.url.split('?')[1]; + // Read the brightness value from the query string + //const brightness = query.brightness; + // Set the brightness using the value from the slider + setBrightness(1, query, res); + } else if (req.url === '/') { + // Send the form when the root URL is requested + let item = fs.readFile('./index.html', function(err, html) { + if (err) { + throw err; + } + else { + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.end(html); + } + }); + } +}).listen(5000); + +console.log('Server listening on port 5000'); diff --git a/index.html b/index.html new file mode 100644 index 0000000..48a55a9 --- /dev/null +++ b/index.html @@ -0,0 +1,22 @@ + + +
+ + + +
+ + + \ No newline at end of file