Shahariar
Published © CC BY-ND

Handsfree Operation Theater Lamp for Surgeons

Voice controlled OT lamp for hands free operation

AdvancedWork in progressOver 1 day28
Handsfree Operation Theater Lamp for Surgeons

Things used in this project

Story

Read more

Schematics

untitled_9IYQoYlxGx.png

Code

code

JavaScript
var mqtt = require('mqtt');
var client  = mqtt.connect('mqtt://localhost', { port: 1883 });
var mosfet = require('./mosfet.js');
var stepper = require('./stepper.js');
var PwmLED = require('./PwmLED.js');
var snipsUserName = 'YOUR_SNIPS_USERNAME';
var wakeword = 'hermes/hotword/default/detected';
var sessionEnd = 'hermes/dialogueManager/sessionEnded';
var lightState = 'hermes/intent/'+snipsUserName+':Lights';

client.on('connect', function() {
  console.log('Connected to Snips MQTT server\n');
  client.subscribe('hermes/hotword/default/detected');
  client.subscribe('hermes/dialogueManager/sessionEnded');
  client.subscribe(lightState);
});


client.on('message', function(topic,message) {
  var message = JSON.parse(message);
  switch(topic) {
      // * On Wakeword
      case wakeword:
          everloop.startWaiting();
          console.log('Wakeword Detected');
      break;
      // * On Light State Change
      case lightState:
          // Turn lights On/Off
          try{
              if (message.slots[0].rawValue === 'on'){
                  mosfet.lightsOn();
                  everloop.stopWaiting();
                  console.log('Lights On');
              }
              else if(message.slots[0].rawValue === 'off'){
                  mosfet.lightsOff();
                  everloop.stopWaiting();
                  console.log('Lights Off');
              }
               else if(message.slots[0].rawValue === 'increase brightness'){
                  mosfet.pwmup();
                  everloop.stopWaiting();
                  console.log('brightness increased');
              } else if(message.slots[0].rawValue === 'decrease brightness'){
                  mosfet.pwmdown();
                  everloop.stopWaiting();
                  console.log('decrease brightness');
              } else if(message.slots[0].rawValue === 'move left'){
                  servo.left();
                  everloop.stopWaiting();
                  console.log('moved left');
              } else if(message.slots[0].rawValue === 'move right'){
                  servo.right();
                  everloop.stopWaiting();
                  console.log('moved right');
              }
          }
          // Expect error if `on` or `off` is not heard
          catch(e){
              console.log('Did not receive any state')
          }
      break;
      // * On Conversation End
      case sessionEnd:
          everloop.stopWaiting();
          console.log('Session Ended\n');
      break;
  }
});

Credits

Shahariar

Shahariar

56 projects • 199 followers
"What Kills a 'Great life' is a 'Good Life', which is Living a Life Inside While Loop"

Comments