/branches/ligi_j2me/README |
---|
4,7 → 4,7 |
* * |
* Author: Marcus -LiGi- Bueschleb * |
* Project-Start: 9/2007 * |
* Version: 0.08 * |
* Version: 0.11 * |
* Mailto: ligi@smart4mobile.de * |
* Licence: Creative Commons / Non Commercial * |
* Big Up: Holger&Ingo * |
17,6 → 17,9 |
* 0.06 - added parsing of DebugData * |
* 0.07 - Code-(Doc&&Cleanup) && initial svn commit * |
* 0.08 - Initial README / ToDo List * |
* 0.09 - implemented BTScanner for detecting BT-Devices ( No hard mac anymore for first public bin) * * |
* 0.10 - initial MKMinimalMidlet / Canvas * |
* 0.11 - 1st public binary ( JAR/JAD) * |
* * |
*********************************************************************************************************************************/ |
29,6 → 32,6 |
- Sound Alarms on Batt low or other triggers |
- get/set MK-Parameters |
- Visualisation of DebugData |
- making lib to be useable with desktop JAVA |
- making lib to be useable with desktop JAVA / will be sceduled after bluecove for linux is ready ( anounced for next Version) |
- tbc |
/branches/ligi_j2me/bin/midp2_minimal/MKMiniMidlet.jad |
---|
0,0 → 1,7 |
MIDlet-Jar-URL: MKMiniMidlet.jar |
MIDlet-Jar-Size: 6596 |
MIDlet-Name: MKMiniMidlet |
MIDlet-Vendor: LiGi |
MIDlet-Version: 0.11 |
MIDlet-1: MKMiniMidlet, , MKMiniMidlet |
MIDletX-No-Command: true |
/branches/ligi_j2me/bin/midp2_minimal/MKMiniMidlet.jar |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/branches/ligi_j2me/src/BTSearcher.java |
---|
0,0 → 1,108 |
/********************************************************************************************************************************* |
* * |
* searches 4 Bluetooth Devices * |
* * |
* Author: Marcus -LiGi- Bueschleb * |
* Project-Start: 9/2007 * |
* Mailto: ligi@smart4mobile.de * |
* Licence: Creative Commons / Non Commercial * |
* Big Up: Holger&Ingo * |
*********************************************************************************************************************************/ |
import javax.bluetooth.*; |
public class BTSearcher |
implements DiscoveryListener |
{ |
private LocalDevice m_LclDevice = null; |
private DiscoveryAgent m_DscrAgent=null; |
public boolean searching=true; |
public boolean error=false; |
public String err_log="none"; |
public final int MAX_DEVICES=10; |
public RemoteDevice[] remote_devices; |
public int remote_device_count=0; |
public String[] remote_device_name; |
public String[] remote_device_mac; |
public BTSearcher() |
{ |
remote_devices=new RemoteDevice[MAX_DEVICES]; |
remote_device_name=new String[MAX_DEVICES]; |
remote_device_mac=new String[MAX_DEVICES]; |
remote_device_count=0; |
try |
{ |
//First get the local device and obtain the discovery agent. |
m_LclDevice = LocalDevice.getLocalDevice(); |
m_DscrAgent= m_LclDevice.getDiscoveryAgent(); |
m_DscrAgent.startInquiry(DiscoveryAgent.GIAC,this); |
} |
catch (BluetoothStateException ex) |
{ |
error=true; |
err_log+="Problem in searching the blue tooth devices\n" + ex; |
} |
} |
public void inquiryCompleted(int transID) { |
try { |
for(int i=0;i<remote_device_count;i++) |
{ |
remote_device_name[i]=remote_devices[i].getFriendlyName(true); |
remote_device_mac[i]=remote_devices[i].getBluetoothAddress(); |
} |
} |
catch (Exception e) |
{ |
err_log+="Problem in searching the blue tooth devices"; |
} |
searching=false; |
} |
//Called when device is found during inquiry |
public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) |
{ |
try |
{ |
if (remote_device_count!=(MAX_DEVICES-1)) |
{ |
remote_devices[remote_device_count]=btDevice; |
remote_device_count++; |
} |
} |
catch (Exception e) |
{ |
err_log+=("Device Discovered Error: " + e); |
} |
} |
public void serviceSearchCompleted(int transID, int respCode) |
{ } |
public void servicesDiscovered(int transID, ServiceRecord[] records) |
{ } |
} |
/branches/ligi_j2me/src/MKCommunicator.java |
---|
32,8 → 32,7 |
public String mk_url=""; // buffer the url which is given in the constuctor for reconnectin purposes |
// version Info from Flight Control |
public int version_major=-1; |
public int version_minor=-1; |
40,6 → 39,7 |
public int version_compatible=-1; |
public long connection_start_time=-1; |
/****************** Section: private Attributes **********************************************/ |
52,13 → 52,15 |
String p_msg="--"; |
public String msg="BT_INIT"; |
int data_count=0; |
public int data_count=0; |
/****************** Section: public Methods ************************************************/ |
public MKCommunicator(String url) // Constructor with URL string e.g. "btspp://XXXXXXXXXXXX:1" - the X-Part is the MAC-Adress of the Bluetooth-Device connected to the Fligth-Control |
{ |
debug_data=new MKDebugData(); |
mk_url=url; // remember URL for connecting / reconnecting later |
new Thread( this ).start(); // fire up main Thread |
} |
70,7 → 72,10 |
connection = (StreamConnection) Connector.open(mk_url, Connector.READ_WRITE); |
reader=connection.openInputStream(); |
writer=connection.openOutputStream(); |
connection_start_time=System.currentTimeMillis(); |
connected=true; // if we get here everything seems to be OK |
get_version(); |
} |
catch (Exception ex) |
{ |
77,8 → 82,9 |
// TODO difference fatal errors from those which will lead to reconnection |
msg="Problem connecting" + "\n" + ex; |
} |
get_version(); |
} |
152,6 → 158,7 |
{ |
int[] decoded_data; |
switch((char)data[2]) |
{ |
184,6 → 191,9 |
} |
// Thread to recieve data from Connection |
public void run() |
{ |
194,9 → 204,12 |
while(true) |
{ |
if (!connected) |
connect(); |
{ |
connect(); |
} |
else |
try{ |
pos=0; |
input=0; |
// recieve data-set |
/branches/ligi_j2me/src/MKDebugData.java |
---|
1,3 → 1,15 |
/********************************************************************************************************************************* |
* * |
* class representing the DebugData Structure * |
* * |
* Author: Marcus -LiGi- Bueschleb * |
* Project-Start: 9/2007 * |
* Mailto: ligi@smart4mobile.de * |
* Licence: Creative Commons / Non Commercial * |
* Big Up: Holger&Ingo * |
*********************************************************************************************************************************/ |
public class MKDebugData |
{ |
8,7 → 20,23 |
int sekunden; |
int[] analog; |
public MKDebugData() |
{ |
digital=new int[13]; |
analog=new int[16]; |
int i; |
for (i=0;i<13;i++) |
digital[i]=-1; |
zyklen=-1; |
zeit= -1; |
sekunden= -1; |
for (i=0;i<16;i++) |
analog[i]=-1; |
} |
public MKDebugData(int[] in_arr) |
{ |
digital=new int[13]; |
/branches/ligi_j2me/src/MKMiniCanvas.java |
---|
0,0 → 1,157 |
/********************************************************************************************************************************* |
* * |
* minimal canvas to test Abstraction layer on various Phones * |
* * |
* Author: Marcus -LiGi- Bueschleb * |
* Project-Start: 9/2007 * |
* Mailto: ligi@smart4mobile.de * |
* Licence: Creative Commons / Non Commercial * |
* Big Up: Holger&Ingo * |
*********************************************************************************************************************************/ |
import javax.microedition.lcdui.*; |
public class MKMiniCanvas |
extends Canvas |
implements Runnable |
{ |
int vibrating=0; |
//BTAbstractor bt; |
BTSearcher bt_scanner; |
MKCommunicator mk=null; |
MKStatistics mk_stat=null; |
// data Section |
public String err=""; |
public MKMiniCanvas() |
{ |
bt_scanner = new BTSearcher(); |
//////////////////////////////////////////////////////////////////////////////mk = new MKCommunicator("btspp://000BCE016B5B:1"); |
new Thread(this).start(); |
} |
/********************************************************** Thread ***********************************************************/ |
// ticking runnable Section |
public void run() |
{ |
while(true) |
{ |
long loopStartTime = System.currentTimeMillis(); |
long sleeptime=0; |
// ticked thing |
com.nokia.mid.ui.DeviceControl.setLights(0,100); |
//bt.tick(); |
// every state has sth to do in tick section |
// System.gc(); |
repaint(); |
serviceRepaints(); |
sleeptime=1000/ 15 - (int) (System.currentTimeMillis()- loopStartTime); |
if (sleeptime<0) |
sleeptime=100; // everyone has fi sleep |
try { Thread.sleep(sleeptime); } |
catch (Exception e) |
{ |
err="Problem Sleeping "; |
} |
} |
} |
// drawing section |
public void paint(Graphics g) { |
g.setColor(0xFFFFFF); |
g.fillRect(0,0,this.getWidth(),this.getHeight()); |
g.setColor(0x000000); |
if (mk==null) |
{ |
if (bt_scanner.searching) |
g.drawString("scanning for BT-Devices",0,0,Graphics.TOP | Graphics.LEFT); |
else |
{ |
g.drawString("Press key 0-"+(bt_scanner.remote_device_count-1) + " to continue" ,0,0,Graphics.TOP | Graphics.LEFT); |
for (int i=0;i<bt_scanner.remote_device_count;i++) |
g.drawString("#"+i+">" + bt_scanner.remote_device_name[i]+"("+bt_scanner.remote_device_mac[i]+")",0,15+15*i,Graphics.TOP | Graphics.LEFT); |
} |
} |
else // MK is connected |
{ |
int y_off=0; |
int spacer=15; |
g.drawString("#"+mk.data_count + "from:" + mk.mk_url,0,y_off,Graphics.TOP | Graphics.LEFT); |
y_off+=spacer; |
g.drawString("v"+mk.version_major+"."+mk.version_minor,0,y_off,Graphics.TOP | Graphics.LEFT); |
y_off+=spacer; |
try { |
g.drawString("motor1:"+mk.debug_data.analog[12],0,y_off,Graphics.TOP | Graphics.LEFT); |
y_off+=spacer; |
g.drawString("motor2:"+mk.debug_data.analog[13],0,y_off,Graphics.TOP | Graphics.LEFT); |
y_off+=spacer; |
g.drawString("motor3:"+mk.debug_data.analog[14],0,y_off,Graphics.TOP | Graphics.LEFT); |
y_off+=spacer; |
g.drawString("motor4:"+mk.debug_data.analog[15],0,y_off,Graphics.TOP | Graphics.LEFT); |
y_off+=spacer; |
} |
catch (Exception e) { } |
if (mk.connected) |
{ |
g.drawString("time conn:" +((System.currentTimeMillis()- mk.connection_start_time)/1000)+"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
y_off+=spacer; |
g.drawString("time motor>15:" +(mk_stat.motor_on_time/1000) +"s" ,0,y_off,Graphics.TOP | Graphics.LEFT); |
} |
} |
} |
/*********************************************** input Section **********************************************/ |
// keys |
public void keyPressed(int keyCode) |
{ |
if ((mk==null)&&(keyCode >= this.KEY_NUM0) && (keyCode < this.KEY_NUM0+bt_scanner.remote_device_count)) |
{ |
mk = new MKCommunicator("btspp://"+bt_scanner.remote_device_mac[keyCode-this.KEY_NUM0] + ":1"); |
mk_stat= new MKStatistics(mk); |
} |
return; |
} |
} |
/branches/ligi_j2me/src/MKMiniMidlet.java |
---|
0,0 → 1,41 |
/********************************************************************************************************************************* |
* * |
* minimal midlet to test Abstraction layer on various Phones * |
* * |
* Author: Marcus -LiGi- Bueschleb * |
* Project-Start: 9/2007 * |
* Mailto: ligi@smart4mobile.de * |
* Licence: Creative Commons / Non Commercial * |
* Big Up: Holger&Ingo * |
*********************************************************************************************************************************/ |
import javax.microedition.lcdui.*; |
import javax.microedition.midlet.*; |
public class MKMiniMidlet |
extends MIDlet |
{ |
public Display display; |
public MKMiniCanvas canvas; |
public boolean loaded=false; |
protected void startApp() |
throws MIDletStateChangeException |
{ |
if (loaded)return; |
display = Display.getDisplay(this); |
canvas=new MKMiniCanvas(); |
// fire up canvas |
display.setCurrent(canvas); |
loaded=true; |
} |
public void quit() { notifyDestroyed(); } |
protected void pauseApp() {} // not needed right now |
protected void destroyApp(boolean arg0) { } |
} |
/branches/ligi_j2me/src/MKStatistics.java |
---|
0,0 → 1,56 |
/********************************************************************************************************************************* |
* * |
* Some Statistics from MK-Connection ( needed for 2. Thread and Readability of Code ) * |
* * |
* Author: Marcus -LiGi- Bueschleb * |
* Project-Start: 9/2007 * |
* Version: 0.07 * |
* Mailto: ligi@smart4mobile.de * |
* Licence: Creative Commons / Non Commercial * |
* Big Up: Holger&Ingo * |
*********************************************************************************************************************************/ |
public class MKStatistics |
implements Runnable |
{ |
MKCommunicator mk=null; |
public MKStatistics(MKCommunicator _mk) |
{ |
mk=_mk; |
new Thread( this ).start(); // fire up main Thread |
} |
public long motor_on_time=-1; |
long last_run_ms=-1; |
public void run() |
{ |
while(true) |
{ |
if (mk.connected) |
{ |
if (last_run_ms!=-1) |
{ |
if (mk.debug_data.analog[14]>15) |
motor_on_time+=System.currentTimeMillis()-last_run_ms; |
} |
last_run_ms=System.currentTimeMillis(); |
} |
else |
{ |
last_run_ms=-1; |
motor_on_time=-1; |
} |
try { Thread.sleep(500); } |
catch (Exception e) { } |
} |
} |
} |