/// <summary>
 /// execute a command on the motor controller
 /// </summary>
 /// <param name="motorcode">the motor on which perform</param>
 public void executeCommandMotorController(string motorcode, int duration, int speed, bool clockwise)
 {
     if (executecommand == null)
     {
         executecommand = new SmartToyExecuteStatus();
     }
     if (executecommand.motorControlCommands != null)
     {
         List <MotorControllerSetter> temp = executecommand.motorControlCommands.ToList();
         MotorControllerSetter        t    = new MotorControllerSetter();
         t.code      = motorcode;
         t.duration  = duration;
         t.speed     = speed;
         t.direction = clockwise ? "cw" : "ccw";
         temp.Add(t);
         executecommand.motorControlCommands = temp.ToArray();
     }
     else
     {
         MotorControllerSetter t = new MotorControllerSetter();
         t.code      = motorcode;
         t.duration  = duration;
         t.speed     = speed;
         t.direction = clockwise ? "cw" : "ccw";
         executecommand.motorControlCommands    = new MotorControllerSetter[1];
         executecommand.motorControlCommands[0] = t;
     }
 }
 /// <summary>
 /// Execute a command on the light controller
 /// </summary>
 /// <param name="color">color to be assigned to the led</param>
 /// <param name="brightness">brightness of the led</param>
 /// <param name="lightpartcode">the name of the liht part form the configuration of the light controller component</param>
 public void executeCommandLightController(Color color, int brightness, string lightpartcode = null)
 {
     if (executecommand == null)
     {
         executecommand = new SmartToyExecuteStatus();
     }
     if (executecommand.lightsControllerCommand != null)
     {
         List <lightControllerSetter> temp = executecommand.lightsControllerCommand.ToList();
         lightControllerSetter        t    = new lightControllerSetter();
         t.code       = lightpartcode;
         t.brightness = brightness;
         t.color      = "#" + ColorUtility.ToHtmlStringRGB(color);
         temp.Add(t);
         executecommand.lightsControllerCommand = temp.ToArray();
     }
     else
     {
         lightControllerSetter t = new lightControllerSetter();
         t.code       = lightpartcode;
         t.brightness = brightness;
         t.color      = "#" + ColorUtility.ToHtmlStringRGB(color);
         executecommand.lightsControllerCommand    = new lightControllerSetter[1];
         executecommand.lightsControllerCommand[0] = t;
     }
 }
 /// <summary>
 /// start an effect
 /// </summary>
 /// <param name="effecttoactivate">name of the effect form the list of names of effects in the effect state compoentn</param>
 public void executeCommandEffectEmitter(string effecttoactivate)
 {
     if (executecommand == null)
     {
         executecommand = new SmartToyExecuteStatus();
     }
     executecommand.effectnametoActivate = effecttoactivate;
 }
 private void executeCommandRFIDSensor(bool turnonsensor)
 {
     if (executecommand == null)
     {
         executecommand = new SmartToyExecuteStatus();
     }
     executecommand.rfid = turnonsensor;
 }
 private void executeCommandButtonSensor(bool turnonsensor)
 {
     if (executecommand == null)
     {
         executecommand = new SmartToyExecuteStatus();
     }
     executecommand.button = turnonsensor;
 }
 private void executeCommandTouchSensor(bool turnonsensor)
 {
     if (executecommand == null)
     {
         executecommand = new SmartToyExecuteStatus();
     }
     executecommand.touch = turnonsensor;
 }
 private void executeCommandPositionSensor(bool turnonAccelerometer, bool turnonGyroscope, bool turnonPosition)
 {
     if (executecommand == null)
     {
         executecommand = new SmartToyExecuteStatus();
     }
     executecommand.accelerometer = turnonAccelerometer;
     executecommand.gyroscope     = turnonGyroscope;
     executecommand.position      = turnonPosition;
 }
 /// <summary>
 /// xecute a commadn on audio player
 /// </summary>
 /// <param name="trackname">the name of the track form the sound controller compoentn</param>
 /// <param name = "volume" > the volume of the player</param>
 /// <param name="repeat">the vieo shoul e put in repeat mode</param>
 /// <param name="state">the state of the player</param>
 public void executeCommandSoundEmitter(string trackname, int volume, bool repeat, SoundAndVideoState state)
 {
     if (executecommand == null)
     {
         executecommand = new SmartToyExecuteStatus();
     }
     executecommand.soundEmitterCommand           = new soundEmitterSet();
     executecommand.soundEmitterCommand.repeat    = repeat;
     executecommand.soundEmitterCommand.state     = state.ToString().Split('.')[1];
     executecommand.soundEmitterCommand.trackname = trackname;
 }
 void LateUpdate()
 {
     if (MagicRoomSmartToyManager.instance.MagicRoomSmartToyManager_active)
     {
         //once I reach this the whole update frame has been computed
         if (executecommand != null)
         {
             //send the data
             string json = executecommand.ToJson();//JsonUtility.ToJson(executecommand);
             MagicRoomSmartToyManager.instance.sendCommandExecuteSmartToy(smartToyName, json);
             //clean up executecommand
             executecommand = null;
         }
         if (getstatus != null)
         {
             //send the data
             string json = JsonUtility.ToJson(getstatus);
             MagicRoomSmartToyManager.instance.sendCommandGetStateSmartToy(smartToyName, json);
             //clean up executecommand
             getstatus = null;
         }
     }
 }
 /// <summary>
 /// execute a command on the motor controller
 /// </summary>
 /// <param name="motorcode">the motor on which perform</param>
 /// <param name="value">the value of the motor: for vibrational and contunous motor represent the duration of the motion, for step motor the number of steps for servo the angle to reach</param>
 public void executeCommandMotorController(string motorcode, float value)
 {
     if (executecommand == null)
     {
         executecommand = new SmartToyExecuteStatus();
     }
     if (executecommand.motorControlCommands != null)
     {
         List <MotorControllerSetter> temp = executecommand.motorControlCommands.ToList();
         MotorControllerSetter        t    = new MotorControllerSetter();
         t.code        = motorcode;
         t.destination = value;
         temp.Add(t);
         executecommand.motorControlCommands = temp.ToArray();
     }
     else
     {
         MotorControllerSetter t = new MotorControllerSetter();
         t.code        = motorcode;
         t.destination = value;
         executecommand.motorControlCommands    = new MotorControllerSetter[1];
         executecommand.motorControlCommands[0] = t;
     }
 }