|
|
@ -14,17 +14,12 @@ function init() { |
|
|
|
|
|
|
|
Promise.all([initDB(), initBoards()]) |
|
|
|
.then(res => { |
|
|
|
app = express(); |
|
|
|
app.use(function (req, res, next) { |
|
|
|
res.header("Access-Control-Allow-Origin", "*"); |
|
|
|
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); |
|
|
|
next(); |
|
|
|
}); |
|
|
|
app = express(); |
|
|
|
app.use(cors()) |
|
|
|
// parse application/x-www-form-urlencoded
|
|
|
|
app.use(bodyParser.urlencoded({ extended: false })) |
|
|
|
// parse application/json
|
|
|
|
app.use(bodyParser.json()) |
|
|
|
app.use(cors()) |
|
|
|
app.listen(3002, () => { |
|
|
|
console.log('Server running on port 3002') |
|
|
|
}) |
|
|
@ -38,15 +33,8 @@ function initDB() { |
|
|
|
} |
|
|
|
|
|
|
|
function initBoards() { |
|
|
|
driver = new HardwareDriver(DRIVERTYPE.I2C) |
|
|
|
driver = new HardwareDriver(DRIVERTYPE.DUMMY) |
|
|
|
return driver.init() |
|
|
|
/* if(demo){ |
|
|
|
return Promise.resolve() |
|
|
|
}else{ |
|
|
|
driver = new HardwareDriver(); |
|
|
|
console.log("beforeInit") |
|
|
|
return driver.init() |
|
|
|
} */ |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -87,14 +75,12 @@ function initRoutes() { |
|
|
|
db.getLampChannelConfig(req.body.id) |
|
|
|
.then(lamp => { |
|
|
|
if (driver) { |
|
|
|
driver.setRGB(lamp, req.body.colors); |
|
|
|
res.sendStatus(200) |
|
|
|
} else { |
|
|
|
console.log("Board not found") |
|
|
|
demoDriver(lamp, req.body.colors) |
|
|
|
console.log(req.body.color) |
|
|
|
driver.setRGB(lamp, req.body.color); |
|
|
|
res.sendStatus(200) |
|
|
|
}else{ |
|
|
|
res.sendStatus(500) |
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
.catch(err => { |
|
|
|
console.log(err) |
|
|
|