18. initialize service
ServiceRequests sr = new ServiceRequests();
sr.addRequest(ServiceRequests.USE_CAMERA);
sr.addRequest(ServiceRequests.USE_COMPASS);
sr.addRequest(ServiceRequests.USE_SENSOR_TYPE_ACCELEROMETER);
sr.addRequest(ServiceRequests.USE_SENSOR_TYPE_MAGNETIC_FIELD);
ServerContainer sc = new ServerContainer(8012, sr);
IT 52-11 18
23. receive data from mobile phone
- Sensor
container.registerSensorListener(sensorListener);
container.sensorOn(ServiceRequests.USE_COMPASS);
container.sensorOn(ServiceRequests.USE_SENSOR_TYPE_MAGNETI
C_FIELD);
container.sensorOn(ServiceRequests.USE_SENSOR_TYPE_ACCELER
OMETER);
@Override
public void onSensorChange(SensorEvent e) {
if (e.type == ServiceRequests.USE_COMPASS) {
System.out.println(e.values[0]);
}
}
IT 52-11 23
24. receive data from mobile phone
- Location
container.registerLocationListener(locationListener);
container.requestLocation();
container.requestLastKnownLocation();
@Override
public void onLocationChange(LocationEvent e) {
System.out.println(e.latitude+”:”+e.longitude);
}
IT 52-11 24
25. receive data from mobile phone
- Camera
container.registerVideoListener(videoListener);
@Override
public void onGetNewVideoFrame(VideoEvent e) {
//you can get BufferedImage by use e.image
}
IT 52-11 25
26. receive data from mobile phone
- Battery
container.setBatteryListener(this);
@Override
public void phoneBatteryChanged(int level) {
// percent unit
}
@Override
public void batteryChanged(int level) {
// maximum is 0 and minimum is 4.
}
IT 52-11 26
27. receive data from mobile phone -
Disconnect
container.setOnDisconnectListener(DisconnectListener);
@Override
public void onClientDisconnected() {
System.exit(0);
}
IT 52-11 27
28. receive data from mobile phone –
Capture Audio
- Capture microphone on Mobile to Server
container.captureAudio();
container.stopAudio();
- Capture microphone on Server to Mobile
Speaker sk = container.getSpeaker();
sk.startCapture();
sk.stopCapture();
IT 52-11 28
Notes de l'éditeur
Before server connected with client, you need to define what Service do you want. It has xx services such as Camera, blablabla.
This method will wait client to connect server. After it’s connected ServerContainer will release Container object
After it’s connected. Now, you need to be create the objects (that have the number of port on microcontroller) of any device and put the device to the container
If you want to create your own device, you need to extends BaseDevice for example.You can control device by setting pulseWidth whatever you want and call execute() to activate it. In this example it’s a led light.