alexatts – Diff between revs 1 and 2

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 1 Rev 2
Line 7... Line 7...
7 7
8 const Gpio = require('onoff').Gpio 8 const Gpio = require('onoff').Gpio
9 const mqtt = require('mqtt') 9 const mqtt = require('mqtt')
10 const YAML = require('yamljs'); 10 const YAML = require('yamljs');
-   11 const winston = require('winston')
Line 11... Line 12...
11 const winston = require('winston') 12 const picoSpeaker = require('pico-speaker')
12 13
-   14 // Load configuration file.
-   15 const config = YAML.load('config.yml')
-   16  
-   17 // Define configuration for pico TTS.
-   18 var picoConfig = {
-   19 AUDIO_DEVICE: config.card,
-   20 LANGUAGE: config.language
-   21 };
-   22  
13 // Load configuration file. 23 // Initialize with config
14 const config = YAML.load('config.yml'); 24 picoSpeaker.init(picoConfig)
15 25  
16 // Generate GPIO pins for configuration. 26 // Generate GPIO pins for configuration.
17 var COOL = {}; 27 var ATTS = {};
18 for(var i in config.GPIO) { 28 for(var i in config.GPIO) {
Line 19... Line 29...
19 if(!config.GPIO.hasOwnProperty(i)) 29 if(!config.GPIO.hasOwnProperty(i))
20 continue; 30 continue;
Line 21... Line 31...
21 31
22 if(config.GPIO[i] === -1) 32 if(config.GPIO[i] === -1)
Line 23... Line 33...
23 continue; 33 continue;
24 34
Line 41... Line 51...
41 return; 51 return;
Line 42... Line 52...
42 52
43 // Remove any retained message. 53 // Remove any retained message.
Line 44... Line -...
44 client.publish(topic, "", {retain: true}) -  
45 54 client.publish(topic, "", {retain: true})
46 message. 55
47 message = message.toString() -  
48 winston.info('Received message: ' + message) -  
49 if(!(message in config.GPIO)) { -  
50 winston.warn('Request to toggle unknown GPIO: ' + message) -  
51 return; 56 message = message.toString()
52 } -  
53 -  
54 var pin = config.GPIO[message] -  
55 if(pin === -1) { -  
56 winston.warn('GPIO pin for "' + message + '" is not configured') -  
57 return; -  
58 } -  
59 57 winston.info('Received message: ' + message)
60 winston.info('Toggling pin ' + pin + ' for ' + message) 58  
61 COOL[message].write(1, (err) => { 59 ATTS["ptt"].write(1, (err) => {
62 if(err) { 60 if(err) {
63 winston.err('Unable to toggle pin ' + pin + ' error message received is: ' + err.message) 61 winston.err('Unable to press push-to-talk button: ' + err.message)
64 return; 62 return;
65 } 63 }
-   64  
66 65 // Send the message.
-   66 picoSpeaker.speak(config.alexa + ", Simon says, " + message).then(function() {
67 setTimeout(function() { 67 winston.info('Message ' + message + ' sent to Alexa.')
68 winston.info('Toggled pin ' + pin + ' for ' + message) 68  
69 COOL[message].write(0) 69 ATTS["ptt"].write(0)
70 }, 1000) 70 }.bind(this));
71 }) -