commit 7ae2c22077344530912b53d780e0829128a49316 Author: Hello_User Date: Tue Dec 27 16:39:07 2022 +0100 Working slider, resets after sliding 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