package com.ociweb.oe.foglight.api;

import com.ociweb.iot.maker.DigitalListener;
import com.ociweb.iot.maker.FogCommandChannel;
import com.ociweb.iot.maker.FogRuntime;
import com.ociweb.iot.maker.Port;

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

public class DigitalListenerBehavior implements DigitalListener {

	private static final Port BUZZER_PORT = D2;
	private static final Port BUTTON_PORT = D3;
	private static final Port TOUCH_SENSOR_PORT = D4;

	private FogCommandChannel channel;
	public DigitalListenerBehavior(FogRuntime runtime) {
		channel = runtime.newCommandChannel(FogCommandChannel.PIN_WRITER | DYNAMIC_MESSAGING);
	}

	@Override
	public void digitalEvent(Port port, long time, long durationMillis, int value) {
		if(value == 1){
			channel.setValue(BUZZER_PORT, true);
			System.out.println("Digital event came from " + port);
			
			
		}
		else{
			channel.setValue(BUZZER_PORT, false);
			System.out.println("Buzzer was on for " + durationMillis + " milliseconds");
			System.out.println("time: " + time);
		}
		channel.shutdown();
	}

}

@@ -250,16 +250,59 @@
 t.*;%0D%0A%0D%0A
+import com.ociweb.gl.api.PubSubService;%0D%0A%0D%0A
 public c
@@ -545,16 +545,55 @@
 annel;%0D%0A
+%09private PubSubService pubService;%0D%0A%09%0D%0A
 %09public 
@@ -709,30 +709,58 @@
 ITER
- %7C DYNAMIC_MESSAGING);
+);%0D%0A%09%09pubService = channel.newPubSubService();%0D%0A%09%09
 %0D%0A%09%7D
@@ -1172,23 +1172,26 @@
 %0A%09%09%7D%0D%0A%09%09
-channel
+pubService
 .shutdow

update API