Fix #62 - light intensity and duration now on /hugvey_fade

This commit is contained in:
Ruben van de Ven 2019-07-04 16:33:10 +02:00
parent cd87c7a442
commit 2eeee9095f
3 changed files with 102 additions and 52 deletions

View file

@ -90,7 +90,7 @@ def getWebSocketHandler(central_command):
# client disconnected # client disconnected
def on_close(self): def on_close(self):
WebSocketHandler.rmConnection(self) self.__class__.rmConnection(self)
logger.info("Client disconnected") logger.info("Client disconnected")
@classmethod @classmethod
@ -168,7 +168,7 @@ def getWebSocketHandler(central_command):
toRemove.append(client) # If we remove it here from the set we get an exception about changing set size during iteration toRemove.append(client) # If we remove it here from the set we get an exception about changing set size during iteration
for client in toRemove: for client in toRemove:
rmConnection(client) wsHandlerClass.rmConnection(client)
return WebSocketHandler return WebSocketHandler

View file

@ -1,24 +1,26 @@
import json
import time
import logging
import re
import asyncio import asyncio
import urllib.parse import json
from .communication import LOG_BS import logging
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
import uuid
import shortuuid
import threading
import faulthandler
from zmq.asyncio import Context
import zmq
import wave
import sox
from pythonosc import udp_client
import random
import pickle
import os import os
import pickle
import random
import re
import threading
import time
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
import traceback import traceback
import urllib.parse
import uuid
import wave
import zmq
from zmq.asyncio import Context
from pythonosc import udp_client
import shortuuid
import sox
from .communication import LOG_BS
mainLogger = logging.getLogger("hugvey") mainLogger = logging.getLogger("hugvey")
logger = mainLogger.getChild("narrative") logger = mainLogger.getChild("narrative")
@ -1034,6 +1036,16 @@ class Configuration(object):
id = 'configuration' id = 'configuration'
volume = 1 # Volume multiplier for 'play' command volume = 1 # Volume multiplier for 'play' command
nothing_text = "nothing" # When variable is not set, but used in sentence, replace it with this word. nothing_text = "nothing" # When variable is not set, but used in sentence, replace it with this word.
light0_intensity = 0
light0_fade = 30. # fade duration in seconds
light1_intensity = 150
light1_fade = 10.
light2_intensity = 75
light2_fade = 10.
light3_intensity = 150
light3_fade = 10.
light4_intensity = 150
light4_fade = 10.
@classmethod @classmethod
def initFromJson(configClass, data, story): def initFromJson(configClass, data, story):
@ -1041,6 +1053,16 @@ class Configuration(object):
config.__dict__.update(data) config.__dict__.update(data)
return config return config
def getLightPresets(self):
c = self.__dict__
l = []
for i in range(5):
l.append({
'intensity': int(c[f"light{i}_intensity"]),
'fade': float(c[f"light{i}_fade"])
})
return l
storyClasses = { storyClasses = {
'Msg': Message, 'Msg': Message,
@ -1686,7 +1708,8 @@ class Story(object):
}) })
if message.lightChange is not None: if message.lightChange is not None:
self.hugvey.setLightStatus(message.lightChange) self.fadeLightPreset(message.lightChange)
# self.hugvey.setLightStatus(message.lightChange)
# 2019-02-22 temporary disable listening while playing audio: # 2019-02-22 temporary disable listening while playing audio:
# if self.hugvey.google is not None: # if self.hugvey.google is not None:
@ -1702,6 +1725,15 @@ class Story(object):
self.logger.log(LOG_BS,logmsg) self.logger.log(LOG_BS,logmsg)
self.storeState() self.storeState()
def fadeLightPreset(self, presetNr: int):
if presetNr < 0 or presetNr > 4:
self.logger.critical(f"Error parsing light fade preset code '{presetNr}'")
return
preset = self.configuration.getLightPresets()[presetNr]
self.hugvey.transitionLight(preset['intensity'], preset['fade'])
def getCurrentDirections(self): def getCurrentDirections(self):
if self.currentMessage.id not in self.directionsPerMsg: if self.currentMessage.id not in self.directionsPerMsg:
return [] return []

View file

@ -1014,7 +1014,7 @@ class Graph {
}) })
), ),
crel('hr'), crel('hr'),
crel('h2', 'Light setting #0'), crel('h2', 'Light fade setting #0'),
crel( crel(
'label', 'label',
"Light intensity: ", "Light intensity: ",
@ -1027,7 +1027,7 @@ class Graph {
panopticon.graph.configuration['light0_intensity'] = e.target.value panopticon.graph.configuration['light0_intensity'] = e.target.value
} }
}, },
'value': this.configuration.hasOwnProperty('light0_intensity') ? this.configuration.light1_intensity : 0 'value': this.configuration.hasOwnProperty('light0_intensity') ? this.configuration.light1_intensity : ""
}) })
), ),
crel( crel(
@ -1036,17 +1036,17 @@ class Graph {
crel('input', { crel('input', {
'type': 'number', 'type': 'number',
'min': 1, 'min': 1,
'max': 5, // 'max': 5,
'step': .1, 'step': .1,
'on': { 'on': {
'change': function(e){ 'change': function(e){
panopticon.graph.configuration['light0_fade'] = e.target.value panopticon.graph.configuration['light0_fade'] = e.target.value
} }
}, },
'value': this.configuration.hasOwnProperty('light0_fade') ? this.configuration.light0_fade: 30 'value': this.configuration.hasOwnProperty('light0_fade') ? this.configuration.light0_fade: ""
}) })
), ),
crel('h2', 'Light setting #1'), crel('h2', 'Light fade setting #1'),
crel( crel(
'label', 'label',
"Light intensity: ", "Light intensity: ",
@ -1059,7 +1059,7 @@ class Graph {
panopticon.graph.configuration['light1_intensity'] = e.target.value panopticon.graph.configuration['light1_intensity'] = e.target.value
} }
}, },
'value': this.configuration.hasOwnProperty('light1_intensity') ? this.configuration.light1_intensity : 150 'value': this.configuration.hasOwnProperty('light1_intensity') ? this.configuration.light1_intensity : ""
}) })
), ),
crel( crel(
@ -1068,17 +1068,17 @@ class Graph {
crel('input', { crel('input', {
'type': 'number', 'type': 'number',
'min': 1, 'min': 1,
'max': 5, // 'max': 5,
'step': .1, 'step': .1,
'on': { 'on': {
'change': function(e){ 'change': function(e){
panopticon.graph.configuration['light1_fade'] = e.target.value panopticon.graph.configuration['light1_fade'] = e.target.value
} }
}, },
'value': this.configuration.hasOwnProperty('light1_fade') ? this.configuration.light1_fade: 10 'value': this.configuration.hasOwnProperty('light1_fade') ? this.configuration.light1_fade: ""
}) })
), ),
crel('h2', 'Light setting #2'), crel('h2', 'Light fade setting #2'),
crel( crel(
'label', 'label',
"Light intensity: ", "Light intensity: ",
@ -1091,7 +1091,7 @@ class Graph {
panopticon.graph.configuration['light2_intensity'] = e.target.value panopticon.graph.configuration['light2_intensity'] = e.target.value
} }
}, },
'value': this.configuration.hasOwnProperty('light2_intensity') ? this.configuration.light2_intensity : 75 'value': this.configuration.hasOwnProperty('light2_intensity') ? this.configuration.light2_intensity : ""
}) })
), ),
crel( crel(
@ -1100,17 +1100,17 @@ class Graph {
crel('input', { crel('input', {
'type': 'number', 'type': 'number',
'min': 1, 'min': 1,
'max': 5, // 'max': 5,
'step': .1, 'step': .1,
'on': { 'on': {
'change': function(e){ 'change': function(e){
panopticon.graph.configuration['light2_fade'] = e.target.value panopticon.graph.configuration['light2_fade'] = e.target.value
} }
}, },
'value': this.configuration.hasOwnProperty('light2_fade') ? this.configuration.light2_fade: 10 'value': this.configuration.hasOwnProperty('light2_fade') ? this.configuration.light2_fade: ""
}) })
), ),
crel('h2', 'Light setting #3'), crel('h2', 'Light fade setting #3'),
crel( crel(
'label', 'label',
"Light intensity: ", "Light intensity: ",
@ -1123,7 +1123,7 @@ class Graph {
panopticon.graph.configuration['light3_intensity'] = e.target.value panopticon.graph.configuration['light3_intensity'] = e.target.value
} }
}, },
'value': this.configuration.hasOwnProperty('light3_intensity') ? this.configuration.light3_intensity : 150 'value': this.configuration.hasOwnProperty('light3_intensity') ? this.configuration.light3_intensity : ""
}) })
), ),
crel( crel(
@ -1132,17 +1132,17 @@ class Graph {
crel('input', { crel('input', {
'type': 'number', 'type': 'number',
'min': 1, 'min': 1,
'max': 5, // 'max': 5,
'step': .1, 'step': .1,
'on': { 'on': {
'change': function(e){ 'change': function(e){
panopticon.graph.configuration['light3_fade'] = e.target.value panopticon.graph.configuration['light3_fade'] = e.target.value
} }
}, },
'value': this.configuration.hasOwnProperty('light3_fade') ? this.configuration.light3_fade: 10 'value': this.configuration.hasOwnProperty('light3_fade') ? this.configuration.light3_fade: ""
}) })
), ),
crel('h2', 'Light setting #4'), crel('h2', 'Light fade setting #4'),
crel( crel(
'label', 'label',
"Light intensity: ", "Light intensity: ",
@ -1155,7 +1155,7 @@ class Graph {
panopticon.graph.configuration['light4_intensity'] = e.target.value panopticon.graph.configuration['light4_intensity'] = e.target.value
} }
}, },
'value': this.configuration.hasOwnProperty('light4_intensity') ? this.configuration.light4_intensity : 150 'value': this.configuration.hasOwnProperty('light4_intensity') ? this.configuration.light4_intensity : ""
}) })
), ),
crel( crel(
@ -1164,14 +1164,14 @@ class Graph {
crel('input', { crel('input', {
'type': 'number', 'type': 'number',
'min': 1, 'min': 1,
'max': 5, // 'max': 5,
'step': .1, 'step': .1,
'on': { 'on': {
'change': function(e){ 'change': function(e){
panopticon.graph.configuration['light4_fade'] = e.target.value panopticon.graph.configuration['light4_fade'] = e.target.value
} }
}, },
'value': this.configuration.hasOwnProperty('light4_fade') ? this.configuration.light4_fade: 10 'value': this.configuration.hasOwnProperty('light4_fade') ? this.configuration.light4_fade: ""
}) })
) )
); );
@ -1259,15 +1259,35 @@ class Graph {
) : 'Auto-generated') ) : 'Auto-generated')
); );
let lightOptionNone = {'value': null} let lightOptions = [
let lightOptionOn = {'value': 1} crel("option", {'value': null}, "Do nothing")
let lightOptionOff = {'value': 0} ];
for(let i = 0; i < 5; i++) {
if(msg.hasOwnProperty('light')) { let l = {'value': i};
if(msg['light'] === 1) lightOptionOn['selected'] = 'selected'; if(msg.hasOwnProperty('light') && msg['light'] == i) {
if(msg['light'] === 0) lightOptionOff['selected'] = 'selected'; l['selected'] = 'selected';
if(msg['light'] === null) lightOptionNone['selected'] = 'selected';
} }
let intensity = "?";
if(this.configuration.hasOwnProperty(`light${i}_intensity`)) {
intensity = this.configuration[`light${i}_intensity`];
}
let duration = "?";
if(this.configuration.hasOwnProperty(`light${i}_fade`)) {
duration = this.configuration[`light${i}_fade`];
}
lightOptions.push(crel("option", l, `Fade preset #${i} (${intensity} in ${duration}s)`));
}
// let lightOptionNone = {'value': null}
//
// let lightOptionOn = {'value': 1}
// let lightOptionOff = {'value': 0}
//
// if(msg.hasOwnProperty('light')) {
// if(msg['light'] === 1) lightOptionOn['selected'] = 'selected';
// if(msg['light'] === 0) lightOptionOff['selected'] = 'selected';
// if(msg['light'] === null) lightOptionNone['selected'] = 'selected';
// }
let msgInfoEl = crel( 'div', { 'class': 'msg__info' }, let msgInfoEl = crel( 'div', { 'class': 'msg__info' },
crel('div', { crel('div', {
@ -1416,9 +1436,7 @@ class Graph {
} }
} }
}, },
crel('option', lightOptionNone, "Do nothing"), lightOptions
crel('option', lightOptionOn, "Turn on"),
crel('option', lightOptionOff, "Turn off")
) )
) )
); );