"use strict";

var express = require('express')
var http = require('http')
var bodyParser = require('body-parser')
var blaster = require('pi-blaster.js')

var app = express()
var server = http.createServer(app)

var port = 8700

var strips = [
	{ red: 17, green: 27, blue: 22 }
]

console.log("Starting Node Server on port " + port)

server.listen(port)

app.use(bodyParser.json())
app.use(express.static('public'))

app.post('/update', function (req, res) {
	var data = req.body

	if (data.strip > strips.length - 1) {
		res.status(400).send("Strip #" + data.strip + " does not exist.")
		return
	}

	blaster.setPwm(strips[data.strip].red, data.red / 255)
	blaster.setPwm(strips[data.strip].green, data.green / 255)
	blaster.setPwm(strips[data.strip].blue, data.blue / 255)

	res.send('ok')
})

@@ -245,17 +245,17 @@
 %09%7B red: 
-1
+2
 7, green
@@ -256,17 +256,17 @@
  green: 
-2
+1
 7, blue:

Fix red/green pins