Browse Source

changes

master
Rino Grupp 3 years ago
parent
commit
a29a3634b1
8 changed files with 23 additions and 76 deletions
  1. +0
    -0
      config.json
  2. +1
    -1
      database.js
  3. +3
    -1
      hardwaredriver/driver-dummy.js
  4. +8
    -3
      hardwaredriver/driver-i2c.js
  5. +4
    -3
      hardwaredriver/hardwaredriver.js
  6. +7
    -21
      index.js
  7. +0
    -12
      presets.json
  8. +0
    -35
      sound.js

+ 0
- 0
config.json View File


+ 1
- 1
database.js View File

@ -8,7 +8,7 @@ class Database {
return new Promise(
(resolve, reject) => {
return mysql.createConnection({
host: '192.168.43.136',
host: 'localhost',
user: 'ledcontroller',
database: 'led'
}).then(res => {

+ 3
- 1
hardwaredriver/driver-dummy.js View File

@ -16,12 +16,14 @@ class DummyDriver {
console.log(`Set channel ${channel} on board ${board} to ${value}`)
}
setRGB(channelConfig, colors) {
setRGB(channelConfig, color) {
channelConfig.forEach(channel => {
this.setChannel(channel.address, channel.channel, channel.color)
});
}
}
module.exports = DummyDriver

+ 8
- 3
hardwaredriver/driver-i2c.js View File

@ -1,9 +1,14 @@
var i2cBus = require("i2c-bus");
var Pca9685Driver = require("pca9685").Pca9685Driver;
var i2cBus
var Pca9685Driver
class I2CDriver {
constructor(){
i2cBus = require("i2c-bus")
Pca9685Driver = require("pca9685").Pca9685Driver
}
init() {
return this.initBoard(0x70)
}

+ 4
- 3
hardwaredriver/hardwaredriver.js View File

@ -1,7 +1,6 @@
var DummyDriver = require('./driver-dummy')
var I2CDriver = require('./driver-i2c')
class HardwareDriver {
constructor(driver){
@ -33,12 +32,14 @@ class HardwareDriver {
this.driver.setChannel(board, channel, value)
}
setRGB(channelConfig, colors) {
setRGB(channelConfig, color) {
channelConfig.forEach(channel => {
this.setChannel(channel.address, channel.channel, channel.color)
this.setChannel(channel.address, channel.channel, color[channel.key])
});
}
}
const DRIVERTYPE = {

+ 7
- 21
index.js View File

@ -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)

+ 0
- 12
presets.json View File

@ -1,12 +0,0 @@
{
"p1Allon": {
"name": "Erstes Preset",
"values":{
"ledb1l":{
"r": 255,
"g": 255,
"b": 255
}
}
}
}

+ 0
- 35
sound.js View File

@ -1,35 +0,0 @@
const fs = require('fs')
const Speaker = require('speaker')
const createMusicStream = require('create-music-stream')
const {MusicBeatDetector, MusicBeatScheduler, MusicGraph} = require('.')
const musicSource = process.argv[2] //gets the first argument on cli
//MusicGraph generates a SVG graph that displays every detected peak
const musicGraph = new MusicGraph()
//MusicBeatScheduler syncs any detected peak with the listened audio. It's useful to control some bulbs or any other effect
const musicBeatScheduler = new MusicBeatScheduler(pos => {
console.log(`peak at ${pos}ms`) //do your effect here
})
//MusicBeatDetector analyzes the music
const musicBeatDetector = new MusicBeatDetector({
plotter: musicGraph.getPlotter(),
scheduler: musicBeatScheduler.getScheduler(),
})
//get any raw pcm_16le stream
createMusicStream(musicSource)
//pipe on analyzer
.pipe(musicBeatDetector.getAnalyzer())
.on('peak-detected', (pos, bpm) => console.log(`peak-detected at ${pos}ms, detected bpm ${bpm}`))
.on('end', () => {
fs.writeFileSync('graph.svg', musicGraph.getSVG())
console.log('end')
})
//pipe on speaker
.pipe(new Speaker())
.on('open', () => musicBeatScheduler.start())

Loading…
Cancel
Save