DVD Player Example

.

DVD Player Pebbles:

  • Display

  • Mechanism

  • Keypad

    The selection of output device, over the network, is unfortunately not implemented in this version of the script.

    
    def pebble dvdControl
    {  
      input devices#keypad#now : { Stop : Play Pause Eject Tfwd Trwd};
      output works#cmd : {stop : play pause resume eject};
      output devices#keypad#playled : {0 : 1};
      output devices#keypad#pauseled : {0 : 1};
      output devices#keypad#stopled : {0 : 1};
      input parts#mech#stat#track : {0..99};
      input parts#mech#stat#sec : {0..59};
      input parts#mech#stat#min : {0..99};
      input parts#mech#stat#idx : {0..99};
      output parts#disp#track : {0..99};
      output parts#disp#sec : {0..59};
      output parts#disp#min : {0..99};
      output parts#disp#idx : {0..99};
    
      // Display update
      with parts#mech#stat
        {
          parts#disp#track  := #track;
          parts#disp#min  := #min;
          parts#disp#sec  := #sec;
          parts#disp#idx  := #idx;
        } 
    
      local keypad_old : { Stop : Play Pause Eject Tfwd Trwd };
     
      with (devices#keypad)
      {
        keypad_old := #now;
        if (#now == Stop) 
          {
            #(playled, pauseled, stopled)  := (0,0,1);
            works#cmd  := Stop;
            works#cmd  == stop;
          }
        else if (#now == Play)    
          {
            #(playled, pauseled, stopled)  := (1,0,0);
            works#cmd  := play;
          }
        else if (#now == Pause && keypad_old != Pause)    
          {
            if (works#cmd == play) 
    	  {
                #(playled, pauseled, stopled)  := (1,1,0);
      	    works#cmd  := pause;
      	  }
            else if (works#cmd == pause) 
    	  {	
                #(playled, pauseled, stopled)  := (1,0,0);
    	    works#cmd  := resume;
      	  }
          }
        else if (#now == Eject)
          {
            #(playled, pauseled, stopled)  := (0,0,0);
            works#cmd  := eject;
          }
      }
    
    
      // Trackup and down are more interesting because all scripts need to be idempotent (multi-runnable)
    	    
      if (^devices#keypad#now)
        {
          if (devices#keypad#now == Tfwd) 
            {
    	  parts#mech#stat#track := parts#mech#stat#track + 1;
      	  // If this is end of disk, then a rollback will undo this assign
            }
          else if (devices#keypad#now == Trwd)
            {
    	  parts#mech#stat#track := parts#mech#stat#track - 1;
    	  // If this is end of disk, then a rollback will undo this assign
            }
        }
    }
    // EOF