/**
 * by 'Draw2D Shape Designer'
 *
 * Custom JS code to tweak the standard behaviour of the generated
 * shape. add your custome code and event handler here.
 *
 *
 */
ArduinoLed = ArduinoLed.extend({

    init: function(attr, setter, getter){
         this._super(attr, setter, getter);

         this.attr({resizeable:false});
         this.installEditPolicy(new draw2d.policy.figure.AntSelectionFeedbackPolicy());
         
         var _this= this;
         this.onChangeCallback = function(emitter, event){
            if(event.value){
                _this.layerAttr("circle",{fill:"#C21B7A"});
            }
            else{
                _this.layerAttr("circle",{fill:"#f0f0f0"});
            }
            // set the LED on the Arduino on/off
            hardware.arduino.set(3, !!event.value);
         }
    },
    
    calculate:function(){
    },
    
    /**
     *  Called if the simulation mode is starting
     **/
    onStart:function(){
        this.getInputPort(0).on("change:value", this.onChangeCallback);

    },

    /**
     *  Called if the simulation mode is stopping
     **/
    onStop:function(){
        this.getInputPort(0).off("change:value", this.onChangeCallback);
    }
    
});