package com.ociweb.grove;


import static com.ociweb.iot.grove.GroveTwig.Button;
import static com.ociweb.iot.grove.GroveTwig.LED;

import com.ociweb.iot.maker.Hardware;
import com.ociweb.iot.maker.FogCommandChannel;
import com.ociweb.iot.maker.FogRuntime;
import com.ociweb.iot.maker.FogApp;
import com.ociweb.iot.maker.Port;

import static com.ociweb.iot.maker.Port.*;

import com.ociweb.gl.api.GreenCommandChannel;

public class IoTApp implements FogApp
{
    ///////////////////////
    //Connection constants 
    ///////////////////////
    // // by using constants such as these you can easily use the right value to reference where the sensor was plugged in
      
    private static final Port BUTTON_PORT = D3;
	private static final Port LED_PORT    = D2;
    //private static final Port RELAY_PORT  = D7;
    //private static final Port LIGHT_SENSOR_PORT= A2;

    @Override
    public void declareConnections(Hardware c) {
        ////////////////////////////
        //Connection specifications
        ///////////////////////////
        
        // // specify each of the connections on the harware, eg which component is plugged into which connection.        
              
        c.connect(Button, BUTTON_PORT); 
        //c.connect(Relay, RELAY_PORT);         
        //c.connect(LightSensor, LIGHT_SENSOR_PORT); 
        c.connect(LED, LED_PORT);        
        c.useI2C();
        
    }


    @Override
    public void declareBehavior(FogRuntime runtime) {
        //////////////////////////////
        //Specify the desired behavior
        //////////////////////////////
        
        //  //Use lambdas or classes and add listeners to the runtime object
        //  //CommandChannels are created to send outgoing events to the hardware
        //  //CommandChannels must never be shared between two lambdas or classes.
        //  //A single lambda or class can use mulitiple CommandChannels for cuoncurrent behavior
        
        
                final FogCommandChannel channel1 = runtime.newCommandChannel(GreenCommandChannel.DYNAMIC_MESSAGING);
               //this digital listener will get all the button press and un-press events 
                runtime.addDigitalListener((port, connection, time, value)->{ 
        //            
        //            //connection could be checked but unnecessary since we only have 1 digital source
        //            
                    if (BUTTON_PORT == port){
                    	channel1.setValue(LED_PORT, value); 
        //                //keep the relay on or off for 1 second before doing next command
        //                channel1.digitalBlock(RELAY_PORT, 1000); 
                    }
               });
    }
        
  
}

@@ -456,222 +456,8 @@
 p%0A%7B%0A
-    ///////////////////////%0A    //Connection constants %0A    ///////////////////////%0A    // // by using constants such as these you can easily use the right value to reference where the sensor was plugged in%0A      %0A
     
@@ -500,17 +500,20 @@
 T = D3;%0A
-%09
+    
 private 
@@ -556,564 +556,119 @@
     
-//private static final Port RELAY_PORT  = D7;%0A    //private static final Port LIGHT_SENSOR_PORT= A2;%0A%0A    @Override%0A    public void declareConnections(Hardware c) %7B%0A        ////////////////////////////%0A        //Connection specifications%0A        ///////////////////////////%0A        %0A        // // specify each of the connections on the harware, eg which component is plugged into which connection.        %0A              %0A        c.connect(Button, BUTTON_PORT); %0A        //c.connect(Relay, RELAY_PORT);         %0A        //c.connect(LightSensor, LIGHT_SENSOR
+%0A    @Override%0A    public void declareConnections(Hardware c) %7B%0A              %0A        c.connect(Button, BUTTON
 _POR
@@ -734,25 +734,16 @@
 eI2C();%0A
-        %0A
     %7D%0A%0A%0A
@@ -822,500 +822,17 @@
     
-//////////////////////////////%0A        //Specify the desired behavior%0A        //////////////////////////////%0A        %0A        //  //Use lambdas or classes and add listeners to the runtime object%0A        //  //CommandChannels are created to send outgoing events to the hardware%0A        //  //CommandChannels must never be shared between two lambdas or classes.%0A        //  //A single lambda or class can use mulitiple CommandChannels for cuoncurrent behavior%0A        %0A        %0A                
+   %0A    %09
 fina
@@ -936,23 +936,16 @@
         
-       
 //this d
@@ -1019,24 +1019,16 @@
         
-    
-    
 runtime.
@@ -1080,17 +1080,16 @@
 alue)-%3E%7B
- 
 %0A       
@@ -1093,170 +1093,9 @@
     
-//            %0A        //            //connection could be checked but unnecessary since we only have 1 digital source%0A        //            %0A                    
+%09
 if (
@@ -1132,20 +1132,16 @@
         
-    
 %09channel
@@ -1150,16 +1150,24 @@
 setValue
+AndBlock
 (LED_POR
@@ -1178,166 +1178,11 @@
 alue
-); %0A        //                //keep the relay on or off for 1 second before doing next command%0A        //                channel1.digitalBlock(RELAY_PORT, 10
+, 2
 00);
@@ -1203,28 +1203,18 @@
     
-    %7D%0A      
+%7D%0A
         
  %7D);
@@ -1209,17 +1209,16 @@
         
- 
 %7D);%0A    
@@ -1223,18 +1223,6 @@
   %7D%0A
-        %0A  %0A
 %7D%0A

Update IoTApp.java