|
next
|
View the entire source
|
package motionsensor.app;
import com.buglabs.bug.module.motion.pub.IMotionObserver;
import com.buglabs.bug.module.motion.pub.IMotionSubject;
public class MotionSensorWatcher implements IMotionObserver {
private IMotionSubject motion;
public MotionSensorWatcher(IMotionSubject motion) {
this.motion = motion;
}
/**
* This method runs whenever a motion event has happened.
* Here you put all the meat of your application.
*/
public void motionDetected() {
//This app just prints a message to the console in the SDK
//type motion after the (: prompt and this method will be called
System.out.println("Motion has been detected");
}
}
|
|
next
|
View the entire source
|
package bugmotionhelloworld;
import com.buglabs.bug.module.motion.pub.IMotionObserver;
import com.buglabs.bug.module.motion.pub.IMotionSubject;
public class MotionTracker implements IMotionObserver {
/**
* The motion sensor service
*/
private IMotionSubject motion;
/**
* Access to the base LCD
*/
private StatusBarWriter writer;
public MotionTracker(IMotionSubject motion, StatusBarWriter writer) {
this.motion = motion;
this.writer = writer;
}
/**
* This method runs whenever a motion event has happened.
* Here you put all the meat of your application.
*/
public void motionDetected() {
writer.write("Motion Detected!");
}
}
|
|
next
|
View the entire source
|
package triggeredsound.motionwatcher;
import triggeredsound.servicetracker.AudioServiceTracker;
import com.buglabs.bug.module.motion.pub.IMotionObserver;
import com.buglabs.bug.module.motion.pub.IMotionSubject;
public class MotionSensorWatcher implements IMotionObserver {
//private IMotionSubject motion;
private AudioServiceTracker myAudio;
public MotionSensorWatcher(IMotionSubject motion, AudioServiceTracker audio) {
//this.motion = motion;
myAudio = audio;
}
/**
* This method runs whenever a motion event has happened.
* Here you put all the meat of your application.
*/
public void motionDetected() {
//type motion after the (: prompt and this method will be called
System.out.println("Motion has been detected");
if (!myAudio.hasStarted()) {
System.out.println("Can't play: audio hasn't started!");
} else {
myAudio.playAudio();
}
}
}
|
|
next
|
View the entire source
|
/**
* Generated by DragonFly
*
*/
package motionsensor.servicetracker;
import motionsensor.app.MotionSensorWatcher;
import org.osgi.framework.BundleContext;
import com.buglabs.application.AbstractServiceTracker;
import com.buglabs.bug.module.motion.pub.IMotionSubject;
/**
* Service tracker for the BugApp Bundle;
*
* All of this is automatically generated by the Dragonfly app wizard, the only modification
* is to the doStart() method. Make sure that the Virtual BUG is running when you open the new
* project dialog, and that a motion sensor is attached. Then check off IMotionSubject in the list of
* services, and all of this code will come for free. If you have trouble with it, hit the forums
* at http://www.bugcommunity.com/forums/ or via IRC, channel #buglabs on irc.freenode.net
*
*/
public class MotionSensorServiceTracker extends AbstractServiceTracker {
/**
* Serves up the motion detector to other classes
*/
private IMotionSubject motion;
public MotionSensorServiceTracker(BundleContext context) {
super(context);
}
/**
* Determines if the application can start.
*/
public boolean canStart() {
return super.canStart();
}
/**
* If canStart returns true this method runs. This is the only method we need to modify
* within the service tracker class
*/
public void doStart() {
System.out.println("MotionSensorServiceTracker: start");
//This line tells the Bug that we need the motion detector's service.
motion = (IMotionSubject) getService(IMotionSubject.class);
//Once we get the motion detector service, we create an instance of the Motion Sensor Watcher class, which
//is just the class that holds our actual app.
MotionSensorWatcher watcher = new MotionSensorWatcher(motion);
//This tells the motion sensor that it has a listener, it keeps a list of subscribed listeners
//so every time there is a motion event, it sends over a message that makes the motionDetected()
//method run in the MotionSensorWatcher class. You can have as many listeners connected to the module
//as need be
motion.register(watcher);
//to cause the motion detector to think it has moved on the virtual bug, just type motion in the console below
}
/**
* Called when a service that this application depends is unregistered.
*/
public void doStop() {
System.out.println("MotionSensorServiceTracker: stop");
}
/**
* Allows the user to set the service dependencies by
* adding them to services list returned by getServices().
* i.e.nl getServices().add(MyService.class.getName());
*/
public void initServices() {
getServices().add("com.buglabs.bug.module.motion.pub.IMotionSubject");
}
}
|
|
next
|
View the entire source
|
/**
* Generated by DragonFly
*
*/
package triggeredsound.servicetracker;
import org.osgi.framework.BundleContext;
import triggeredsound.servicetracker.AudioServiceTracker;
import triggeredsound.motionwatcher.MotionSensorWatcher;
import com.buglabs.application.AbstractServiceTracker;
import com.buglabs.bug.module.motion.pub.IMotionSubject;
/**
* Service tracker for the BugApp Bundle;
*
* All of this is automatically generated by the Dragonfly app wizard, the only modification
* is to the doStart() method. Make sure that the Virtual BUG is running when you open the new
* project dialog, and that a motion sensor is attached. Then check off IMotionSubject in the list of
* services, and all of this code will come for free. If you have trouble with it, hit the forums
* at http://www.bugcommunity.com/forums/ or via IRC, channel #buglabs on irc.freenode.net
*
*/
public class MotionSensorServiceTracker extends AbstractServiceTracker {
/**
* Serves up the motion detector to other classes
*/
private IMotionSubject motion;
private AudioServiceTracker myAudio;
public MotionSensorServiceTracker(BundleContext context, AudioServiceTracker audio) {
super(context);
myAudio = audio;
}
/**
* Determines if the application can start.
*/
public boolean canStart() {
return super.canStart();
}
/**
* If canStart returns true this method runs. This is the only method we need to modify
* within the service tracker class
*/
public void doStart() {
System.out.println("MotionSensorServiceTracker: start");
//This line tells the Bug that we need the motion detector's service.
motion = (IMotionSubject) getService(IMotionSubject.class);
//Once we get the motion detector service, we create an instance of the Motion Sensor Watcher class, which
//is just the class that holds our actual app.
MotionSensorWatcher watcher = new MotionSensorWatcher(motion, myAudio);
//This tells the motion sensor that it has a listener, it keeps a list of subscribed listeners
//so every time there is a motion event, it sends over a message that makes the motionDetected()
//method run in the MotionSensorWatcher class. You can have as many listeners connected to the module
//as need be
motion.register(watcher);
//to cause the motion detector to think it has moved on the virtual bug, just type motion in the console below
}
/**
* Called when a service that this application depends is unregistered.
*/
public void doStop() {
System.out.println("MotionSensorServiceTracker: stop");
}
/**
* Allows the user to set the service dependencies by
* adding them to services list returned by getServices().
* i.e.nl getServices().add(MyService.class.getName());
*/
public void initServices() {
getServices().add("com.buglabs.bug.module.motion.pub.IMotionSubject");
}
}
|
|
next
|
View the entire source
|
/**
* Generated by Dragonfly SDK
*
*/
package bugmotionhelloworld.servicetracker;
import bugmotionhelloworld.*;
import org.osgi.framework.BundleContext;
import com.buglabs.bug.module.motion.pub.IMotionSubject;
import com.buglabs.application.AbstractServiceTracker;
import com.buglabs.status.IStatusBarProvider;
/**
* Service tracker for the BugApp Bundle;
*
*/
public class BUGmotionHelloWorldServiceTracker extends AbstractServiceTracker {
private IMotionSubject motion;
private MotionTracker app;
private StatusBarWriter writer;
public BUGmotionHelloWorldServiceTracker(BundleContext context) {
super(context);
}
/**
* Determines if the application can start.
*/
public boolean canStart() {
return super.canStart();
}
/**
* If canStart returns true
* this method is called to start the application.
* Place your fun logic here.
*/
public void doStart() {
System.out.println("BUGmotionHelloWorldServiceTracker: start");
motion = (IMotionSubject) getService(IMotionSubject.class);
writer = new StatusBarWriter((IStatusBarProvider) getService(IStatusBarProvider.class));
app = new MotionTracker(motion, writer);
motion.register(app);
}
/**
* Called when a service that this application depends is unregistered.
*/
public void doStop() {
System.out.println("BUGmotionHelloWorldServiceTracker: stop");
motion.unregister(app);
writer.doStop();
}
/**
* Allows the user to set the service dependencies by
* adding them to services list returned by getServices().
* i.e.nl getServices().add(MyService.class.getName());
*/
public void initServices() {
getServices().add("com.buglabs.bug.module.motion.pub.IMotionSubject");
getServices().add("com.buglabs.status.IStatusBarProvider");
}
}
|
|
next
|
View the entire source
|
/**
* Generated by DragonFly
*
*/
package bugtalkviaaim.servicetracker;
import lib.AdminConfigManager;
import lib.IAdminConfigManager;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.util.tracker.ServiceTracker;
import bugtalkviaaim.BUGtalkApp;
import com.buglabs.application.AbstractServiceTracker;
import com.buglabs.bug.accelerometer.pub.IAccelerometerSampleProvider;
import com.buglabs.bug.module.motion.pub.IMotionSubject;
import com.buglabs.module.IModuleControl;
/**
* Service tracker for the BugApp Bundle;
*
*/
public class BUGtalkViaAIMServiceTracker extends AbstractServiceTracker {
public BUGtalkApp app;
private static IAdminConfigManager configManager;
private ServiceTracker moduleTracker;
private IAccelerometerSampleProvider accel;
private IMotionSubject motion;
public BUGtalkViaAIMServiceTracker(BundleContext context) {
super(context);
}
/**
* Determines if the application can start.
*/
public boolean canStart() {
return super.canStart();
}
/**
* If canStart returns true
* this method is called to start the application.
* Place your fun logic here.
*/
public void doStart() {
System.out.println("BUGtalkViaAIMServiceTracker: start");
configManager = new AdminConfigManager(context);
Object oAccel = getService(IAccelerometerSampleProvider.class);
Object oMotion = getService(IMotionSubject.class);
if (oAccel != null)
accel = (IAccelerometerSampleProvider)oAccel;
if (oMotion != null)
motion = (IMotionSubject)oMotion;
app = new BUGtalkApp(configManager, accel, motion);
if (motion != null)
motion.register(app);
Filter f;
try {
f = context.createFilter("(" + Constants.OBJECTCLASS + "=" + IModuleControl.class.getName() + ")");
moduleTracker = new ServiceTracker(context, f, new ModuleServiceTracker(context));
moduleTracker.open();
} catch (InvalidSyntaxException e) {
e.printStackTrace();
}
}
/**
* Called when a service that this application depends is unregistered.
*/
public void doStop() {
System.out.println("BUGtalkViaAIMServiceTracker: stop");
app.cleanup();
if (motion != null)
motion.unregister(app);
}
/**
* Allows the user to set the service dependencies by
* adding them to services list returned by getServices().
* i.e.nl getServices().add(MyService.class.getName());
*/
public void initServices() {
getServices().add("com.buglabs.application.IDesktopApp");
getServices().add("com.buglabs.bug.accelerometer.pub.IAccelerometerSampleProvider");
getServices().add("com.buglabs.bug.module.motion.pub.IMotionSubject");
getServices().add("org.osgi.service.log.LogService");
getServices().add("org.osgi.service.cm.ConfigurationAdmin");
}
}
|
|
next
|
View the entire source
|
/**
* Generated by DragonFly
*
*/
package rpgdiceroller.servicetracker;
import org.osgi.framework.BundleContext;
import rpgdiceroller.app.RPGDiceRollerGUI;
import com.buglabs.application.AbstractServiceTracker;
import com.buglabs.bug.module.lcd.pub.IModuleDisplay;
import com.buglabs.bug.module.motion.pub.IMotionSubject;
/**
* Service tracker for the BugApp Bundle;
*
*/
public class RPGDiceRollerServiceTracker extends AbstractServiceTracker {
private IModuleDisplay display;
private IMotionSubject motion;
public RPGDiceRollerServiceTracker(BundleContext context) {
super(context);
}
/**
* Determines if the application can start.
*/
public boolean canStart() {
return super.canStart();
}
/**
* If canStart returns true
* this method is called to start the application.
* Place your fun logic here.
*/
public void doStart() {
System.out.println("RPGDiceRollerServiceTracker: start");
display = (IModuleDisplay) getService(IModuleDisplay.class);
motion = (IMotionSubject) getService(IMotionSubject.class);
RPGDiceRollerGUI app = new RPGDiceRollerGUI(display, motion);
motion.register(app);
}
/**
* Called when a service that this application depends is unregistered.
*/
public void doStop() {
System.out.println("RPGDiceRollerServiceTracker: stop");
}
/**
* Allows the user to set the service dependencies by
* adding them to services list returned by getServices().
* i.e.nl getServices().add(MyService.class.getName());
*/
public void initServices() {
getServices().add("com.buglabs.bug.module.lcd.pub.IModuleDisplay");
getServices().add("com.buglabs.bug.module.motion.pub.IMotionSubject");
}
}
|
|
next
|
View the entire source
|
/**
* Generated by Dragonfly SDK
*
*/
package bugmotionhelloworld.servicetracker;
import bugmotionhelloworld.*;
import org.osgi.framework.BundleContext;
import com.buglabs.bug.module.motion.pub.IMotionSubject;
import com.buglabs.application.AbstractServiceTracker;
import com.buglabs.status.IStatusBarProvider;
/**
* Service tracker for the BugApp Bundle;
*
*/
public class BUGmotionHelloWorldServiceTracker extends AbstractServiceTracker {
private IMotionSubject motion;
private MotionTracker app;
private StatusBarWriter writer;
public BUGmotionHelloWorldServiceTracker(BundleContext context) {
super(context);
}
/**
* Determines if the application can start.
*/
public boolean canStart() {
return super.canStart();
}
/**
* If canStart returns true
* this method is called to start the application.
* Place your fun logic here.
*/
public void doStart() {
System.out.println("BUGmotionHelloWorldServiceTracker: start");
motion = (IMotionSubject) getService(IMotionSubject.class);
writer = new StatusBarWriter((IStatusBarProvider) getService(IStatusBarProvider.class));
app = new MotionTracker(motion, writer);
motion.register(app);
}
/**
* Called when a service that this application depends is unregistered.
*/
public void doStop() {
System.out.println("BUGmotionHelloWorldServiceTracker: stop");
writer.doStop();
}
/**
* Allows the user to set the service dependencies by
* adding them to services list returned by getServices().
* i.e.nl getServices().add(MyService.class.getName());
*/
public void initServices() {
getServices().add("com.buglabs.bug.module.motion.pub.IMotionSubject");
getServices().add("com.buglabs.status.IStatusBarProvider");
}
}
|
|
next
|
View the entire source
|
/**
* Generated by Dragonfly SDK
*
*/
package motionalarmclock.servicetracker;
import org.osgi.framework.BundleContext;
import com.buglabs.application.AbstractServiceTracker;
import com.buglabs.bug.base.pub.ITimeProvider;
import com.buglabs.bug.base.pub.IToneGenerator;
import com.buglabs.bug.module.motion.pub.IMotionSubject;
import com.buglabs.menu.IMenuProvider;
import motionalarmclock.app.*;
/**
* Service tracker for the BugApp Bundle;
*
*/
public class MotionAlarmClockServiceTracker extends AbstractServiceTracker {
private IMotionSubject motion;
private IToneGenerator tone;
private IMenuProvider menu;
private ITimeProvider time;
public MotionAlarmClockServiceTracker(BundleContext context) {
super(context);
}
/**
* Determines if the application can start.
*/
public boolean canStart() {
return super.canStart();
}
/**
* If canStart returns true
* this method is called to start the application.
* Place your fun logic here.
*/
public void doStart() {
motion = (IMotionSubject) getService(IMotionSubject.class);
tone = (IToneGenerator) getService(IToneGenerator.class);
menu = (IMenuProvider) getService(IMenuProvider.class);
time = (ITimeProvider) getService(ITimeProvider.class);
MotionAlarmClockApp app = new MotionAlarmClockApp(motion, tone, menu, time);
motion.register(app);
System.out.println("MotionAlarmClockServiceTracker: start");
}
/**
* Called when a service that this application depends is unregistered.
*/
public void doStop() {
System.out.println("MotionAlarmClockServiceTracker: stop");
}
/**
* Allows the user to set the service dependencies by
* adding them to services list returned by getServices().
* i.e.nl getServices().add(MyService.class.getName());
*/
public void initServices() {
getServices().add("com.buglabs.bug.base.pub.ITimeProvider");
getServices().add("com.buglabs.bug.base.pub.IToneGenerator");
getServices().add("com.buglabs.bug.module.motion.pub.IMotionSubject");
getServices().add("com.buglabs.menu.IMenuProvider");
getServices().add("com.buglabs.status.IStatusBarProvider");
}
}
|