⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mobileroboticsmidlet.java

📁 1、手持设备机器人——应用端; 2、基于蓝牙传输;
💻 JAVA
字号:
/*************************************************************
 *
 * The Mobile Robotics Project
 * - mobilerobotics.sourceforge.net
 *
 * Coders in no particular order:
 *
 *  Niklas Bivald,    webmaster[a/t]bivald.com
 *  Johan Johansson,  something[a/t]something.com
 *                               *
 * Other team members, lego builders:
 *
 *  Gabriel Lundmark, something[a/t]something.com
 *  Thomas Erdelyi,   something[a/t]something.com
 *
 * This file was created 2005-01-05
 *
 * Other, none important dates:
 * 2005-01-07: First time the program was tested on a real
 *         cell phone. Shout goes to Mikael Lenneryd for
 *         letting me use and abuse his v800
 *
 *         Thoughts: SE Simulator is slower then phone
 *
 * 2005-02-20: Shrinked and reformated the code (15% less)
 *
 * 2005-02-25: Code and graphics for everything but
 *             bluetooth communication is done.
 *
 * 2005-02-26: Bluetooth communication is done, in teory.
 *             Yet to be tested.
 *
 * 2005-04-08: First active bluetooth search (services
 *             and devices) and connection.
 *
 * Shout goes to:
 *  - Mikael for putting up with me using his phone
 *  - Those who could bare my questions and comments (usually Johan)
 *  - Sun developers and their articles
 *  - Java articles on the net
 *
 *  - J2ME Gaming book
 *       URL: http://sourceforge.net/projects/j2megamingbook/
 *
 *  - Klings Bluetooth Master Thesis
 *       URL: http://wireless.klings.org/klings_jabwt_master_thesis.pdf
 *
 *  - Jason Lam J2ME tutorials on Bluetooth,
 *    http://www.jasonlam604.com/articles_introduction_to_bluetooth_and_j2me_part2.php
 *    Perfect if you are new to Bluetooth.
 *
 *************************************************************/

 /*

	  The runes say:
	  Harald Christianized the Danes
	  Harald controlled Denmark and Norway
	  Harald thinks notebooks and cellular phones should communicate seamlessly


	  And one last thing..
	  "Beware of bugs in the above code; I have only proved it correct, not tried it. - Donald Knuth"

	  PS: We have tried it I just like the quote.

  */


 /*

  Visit http://mobilerobotics.sf.net for more information!

  Instructions to compile java midp2 software.

  1. Download and install Sony Ericsson J2ME SDK

    Register on developer.sonyericsson.com and log in,
    download "Sony Ericsson J2ME SDK"

    2. Start the Ktoolbar via the start menu:

    Start -> Program -> Sony Ericson -> J2ME SDK ->
    WTK2 -> Ktoolbar

  3. Copy the MobileRobotics folder to the
     C:\SonyEricsson\J2ME_SDK\PC_Emulation\WTK2\apps folder.

    If you want to put it on a regular phone do Projekt ->
    Package -> Create Package

  */

  /*

      As an intro I suggest reading overview.txt

   */

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class MobileRoboticsMidlet extends MIDlet {

  private Display display;
  private boolean btstatus;

  private Bluetooth blue              = null;
  private ControllRobot controllRobot = null;

  public void startApp()
       {
        display = Display.getDisplay(this);

        /*

          We start by initiating the blueooth thread. We pass on the valuse
          "this" in order for the thread to be able to call functions from this
          file and "display" so it can chooe what to display. We will call the
          bluetooth thread blue.

         */

    	 System.err.println("Init: Bluetooth thread");

     	           blue   = new Bluetooth ( this, display );
    	 Thread bluetooth = new Thread    ( blue          );
     	        bluetooth.start();


         // Initiate bluetooth discovery
           System.err.println("Init: Bluetooth discovery");
           btstatus = blue.initiate();



           System.err.println("Inited: Bluetooth discovery, " + btstatus);

 	     if(btstatus == false)
 	      {
 	        exit();
 	      }

          // Since the btstatus returned true we have establised a bluetooth connection.
          // Therefor we continue with initating the controllRobot thread

          System.err.println("Init: controllRobot thread");

                        controllRobot = new ControllRobot(this, blue);
                        controllRobot.start();

          // We've initated the controllRobot, let's make so we actually see what we just
          // initated.

        display.setCurrent(controllRobot);
       }

public void setDisplayToControllRobot(Display display)
 {
        controllRobot.resetDirection();
	display.setCurrent( controllRobot );
 }


public Display getDisplay()
 {
   // Return our current Display
   return display;
 }


public void pauseApp()
 {
   // Pause application, exit software
   exit();
 }

public void destroyApp(boolean unconditional) {
  exit();
}

public void exit() {

  if(blue != null)
   {
    if(blue.connection !=null && blue.os != null)
     {
       blue.command(1);
       blue.cleanUp();
     }
   }

  if(controllRobot != null)
   controllRobot.stop();

  System.gc();
  destroyApp(true);
  notifyDestroyed();
 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -