Browse Source

Bugfixes

master
ruudii8 2 years ago
parent
commit
d78d82190f
6 changed files with 326 additions and 30 deletions
  1. +16
    -28
      database.js
  2. +2
    -2
      index.js
  3. +0
    -0
      old/config.json
  4. +58
    -0
      old/lights.json
  5. +55
    -0
      old/test.js
  6. +195
    -0
      queries/led-dump.sql

+ 16
- 28
database.js View File

@ -130,22 +130,16 @@ class Database {
let dbRequests = []
console.log("+++ createLamp")
return db.execute("SELECT PK_type FROM `led`.`type` WHERE `led`.`type`.`key` = '" + light.type + "';")
console.log(light)
console.log("SELECT PK_type FROM `led`.`type` WHERE `led`.`type`.`PK_type` = " + light.typeID + ";")
return db.execute("SELECT PK_type FROM `led`.`type` WHERE `led`.`type`.`PK_type` = " + light.typeID + ";")
.then(res => {
dbRequests = []
dbRequests.push(db.execute("INSERT INTO `led`.`light` (`FK_type`,`name`,`description`) VALUES ("+res[0][0]['PK_type'] + ",\"" + light.title + "\",\"" + light.description + "\");"))
for (let channelKey in light.channels) {
dbRequests.push(db.execute("SELECT PK_board FROM `led`.`board` WHERE `led`.`board`.`address` = \"" + light.channels[channelKey].board + "\";"))
}
return Promise.allSettled(dbRequests)
.then((promRes) => {
switch (light.type) {
case 'rgb':
this.addRGBChannels(light.channels, promRes)
db.execute("INSERT INTO `led`.`light` (`FK_type`,`name`,`description`) VALUES ("+res[0][0]['PK_type'] + ",\"" + light.title + "\",\"" + light.description + "\");")
.then((res2) => {
switch (light.typeID) {
case 1:
this.addRGBChannels(light.channels, res2[0]['insertId'], light.boardID)
break;
default:
console.log("Unknown lighttype")
return reject()
@ -158,23 +152,17 @@ class Database {
.catch(err => {
console.log("failed to add lamp: " + err)
})
// AddLight
}
addRGBChannels(channels, res) {
addRGBChannels(channels, insertID, boardID) {
let command = "INSERT INTO `led`.`mapping-light` (`FK_light`,`FK_board`,`channel`,`key`, `description`) VALUES"
let keys=Object.keys(channels)
for (let i = 0; i<3; i++) {
command += "(" + res[0].value[0].insertId + "," + res[i+1].value[0][0].PK_board + "," + channels[keys[i]].channel + ",\"" + keys[0] + "\",\".\"),"
}
Object.keys(channels).forEach(channel => {
command += "(" + insertID + "," + boardID + "," + channels[channel] + ",\"" + channel + "\",\".\"),"
})
command = command.substr(0, command.length - 1)
console.log(command)
return db.execute(command)
.then(res=> {
console.log("Created light")

+ 2
- 2
index.js View File

@ -179,8 +179,8 @@ function initRoutes() {
})
app.post('/createLamp', (req, res) => {
//console.log(req.body)
db.createLamp(req.body)
console.log(req.body.light)
db.createLamp(req.body.light)
.then(()=>{
console.log("Success: ")
res.sendStatus(200)

+ 0
- 0
old/config.json View File


+ 58
- 0
old/lights.json View File

@ -0,0 +1,58 @@
{
"ledb1l": {
"type": "led_stripe",
"name": "Block 1 - links",
"channels": {
"r": 0,
"g": 0,
"b": 0
},
"positions": {
"description": "",
"block": 1,
"direction": "left"
}
},
"ledb1r": {
"type": "led_stripe",
"name": "Block 1 - rechts",
"channels": {
"r": 0,
"g": 0,
"b": 0
},
"positions": {
"description": "",
"block": 1,
"direction": "right"
}
},
"ledb2l": {
"type": "led_stripe",
"name": "Block 2 - links",
"channels": {
"r": 0,
"g": 0,
"b": 0
},
"positions": {
"description": "",
"block": 2,
"direction": "left"
}
},
"ledb2r": {
"type": "led_stripe",
"name": "Block 1 - rechts",
"channels": {
"r": 0,
"g": 0,
"b": 0
},
"positions": {
"description": "",
"block": 2,
"direction": "right"
}
}
}

+ 55
- 0
old/test.js View File

@ -0,0 +1,55 @@
var i2cBus
var Pca9685Driver
i2cBus = require("i2c-bus")
Pca9685Driver = require("pca9685").Pca9685Driver
let options = {
i2c: i2cBus.openSync(1),
address: 0x40,
frequency: 200,
debug: false
};
function initBoard(){
let options = {
i2c: i2cBus.openSync(1),
address: 0x40,
frequency: 200,
debug: false
};
return new Promise(
(resolve, reject) => {
console.log("beforeRealInit")
this.pwm = new Pca9685Driver(options, function (err) {
if (err) {
reject("Failed to initialize boards");
} else {
console.log("I2C Driver loaded")
pwm.channelOn(6)
resolve();
}
});
});
}
initBoard()
.then(res =>{
console.log("worked")
pwm.channelOn(8);
pwm.setPulseRange(9,50,255);
});
/**
*
* @param {*} channel channel to set
* @param {*} value Between 0&256
*/
/**setChannel(channel, value) {
console.log(`I2C: Set channel ${channel} on board ${this.address} to ${value}`)
this.pwm.setPulseRange(channel, 0, (value * 16))
*/

+ 195
- 0
queries/led-dump.sql View File

@ -0,0 +1,195 @@
-- MySQL dump 10.15 Distrib 10.0.28-MariaDB, for debian-linux-gnueabihf (armv7l)
--
-- Host: led Database: led
-- ------------------------------------------------------
-- Server version 10.0.28-MariaDB-2+b1
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `board`
--
Use `led`;
DROP TABLE IF EXISTS `board`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `board` (
`PK_board` int(11) NOT NULL AUTO_INCREMENT,
`address` varchar(10) DEFAULT NULL,
PRIMARY KEY (`PK_board`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `board`
--
LOCK TABLES `board` WRITE;
/*!40000 ALTER TABLE `board` DISABLE KEYS */;
INSERT INTO `board` VALUES (1,'0x40');
/*!40000 ALTER TABLE `board` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `light`
--
DROP TABLE IF EXISTS `light`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `light` (
`PK_light` int(11) NOT NULL AUTO_INCREMENT,
`FK_type` int(11) NOT NULL,
`name` varchar(45) NOT NULL,
`description` varchar(255) NOT NULL,
PRIMARY KEY (`PK_light`),
KEY `FK_type` (`FK_type`),
CONSTRAINT `light_ibfk_1` FOREIGN KEY (`FK_type`) REFERENCES `type` (`PK_type`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `light`
--
LOCK TABLES `light` WRITE;
/*!40000 ALTER TABLE `light` DISABLE KEYS */;
INSERT INTO `light` VALUES (1,1,'1. Stripe','Absout erster Stripe'),(2,1,'2. Stripe','Der zweite Stripe');
/*!40000 ALTER TABLE `light` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `mapping-light`
--
DROP TABLE IF EXISTS `mapping-light`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mapping-light` (
`PK_mapping-light` int(11) NOT NULL AUTO_INCREMENT,
`FK_light` int(11) NOT NULL,
`FK_board` int(11) NOT NULL,
`channel` int(11) NOT NULL,
`key` varchar(10) NOT NULL,
`description` varchar(255) DEFAULT NULL,
PRIMARY KEY (`PK_mapping-light`),
KEY `FK_light` (`FK_light`),
KEY `FK_board` (`FK_board`),
CONSTRAINT `mapping-light_ibfk_1` FOREIGN KEY (`FK_light`) REFERENCES `light` (`PK_light`),
CONSTRAINT `mapping-light_ibfk_2` FOREIGN KEY (`FK_board`) REFERENCES `board` (`PK_board`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `mapping-light`
--
LOCK TABLES `mapping-light` WRITE;
/*!40000 ALTER TABLE `mapping-light` DISABLE KEYS */;
INSERT INTO `mapping-light` VALUES (1,1,1,0,'r','red'),(2,1,1,1,'g','green'),(3,1,1,2,'b','blue'),(4,2,1,3,'r','red'),(5,2,1,4,'g','green'),(6,2,1,5,'b','blue');
/*!40000 ALTER TABLE `mapping-light` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `mapping-preset`
--
DROP TABLE IF EXISTS `mapping-preset`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mapping-preset` (
`PK_mapping-preset` int(11) NOT NULL AUTO_INCREMENT,
`FK_mapping-light` int(11) NOT NULL,
`FK_preset` int(11) NOT NULL,
`value` int(11) NOT NULL,
`channel` varchar(45) NOT NULL,
PRIMARY KEY (`PK_mapping-preset`),
KEY `FK_mapping-light` (`FK_mapping-light`),
KEY `mapping-preset_ibfk_2` (`FK_preset`),
CONSTRAINT `mapping-preset_ibfk_1` FOREIGN KEY (`FK_mapping-light`) REFERENCES `mapping-light` (`PK_mapping-light`),
CONSTRAINT `mapping-preset_ibfk_2` FOREIGN KEY (`FK_preset`) REFERENCES `preset` (`PK_preset`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `mapping-preset`
--
LOCK TABLES `mapping-preset` WRITE;
/*!40000 ALTER TABLE `mapping-preset` DISABLE KEYS */;
INSERT INTO `mapping-preset` VALUES (1,1,1,255,'r'),(2,2,1,18,'r'),(3,2,1,14,'g'),(4,2,1,255,'b'),(5,1,2,255,'r'),(6,2,2,18,'r'),(7,2,2,14,'g'),(8,2,2,255,'b');
/*!40000 ALTER TABLE `mapping-preset` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `preset`
--
DROP TABLE IF EXISTS `preset`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `preset` (
`PK_preset` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(20) DEFAULT NULL,
`description` varchar(255) DEFAULT NULL,
PRIMARY KEY (`PK_preset`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `preset`
--
LOCK TABLES `preset` WRITE;
/*!40000 ALTER TABLE `preset` DISABLE KEYS */;
INSERT INTO `preset` VALUES (1,'Test',''),(2,'Test2','Description');
/*!40000 ALTER TABLE `preset` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `type`
--
DROP TABLE IF EXISTS `type`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `type` (
`PK_type` int(11) NOT NULL AUTO_INCREMENT,
`key` varchar(20) NOT NULL,
`name` varchar(45) DEFAULT NULL,
`description` varchar(255) DEFAULT NULL,
PRIMARY KEY (`PK_type`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `type`
--
LOCK TABLES `type` WRITE;
/*!40000 ALTER TABLE `type` DISABLE KEYS */;
INSERT INTO `type` VALUES (1,'rgb','RGB','3-Channel RGB stripe'),(2,'switch','ON/OFF switch','1-way ON/OFF switch');
/*!40000 ALTER TABLE `type` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2020-05-29 2:20:26

Loading…
Cancel
Save