Shop OBEX P1 Docs P2 Docs Learn Events
eb500 and Javelin code samples — Parallax Forums

eb500 and Javelin code samples

jmstepanekjmstepanek Posts: 3
edited 2005-02-25 03:16 in General Discussion
Does anyone have any code samples showing how to use the eb500 and the Javelin together? Are they posted somewhere and I'm just not seeing them?

Thanks,

J. Stepanek

Comments

  • TimCTimC Posts: 77
    edited 2005-02-25 02:41
    Yes here is a class I was playing around with last year. Have fun!
    import stamp.core.*;
    import stamp.util.*;
    /**
     * Bluetooth EB500: ruff demo.
     *
     * @version 0.0 5/2/04
     * @author Tim C
     */
    
    
    public class TestBlue {
    
      final static char HOME      = 0x01;
      final static char CLS = '\u0010';        // Clear Screen
      final static char CR = 0x0d;          // CR
      final static char LF = 0x0a;          // LF
      final static char BUFFLEN = 40;
      final static char RDELAY = 15;        // receive delay
      final static char EXPECTDELAY = 1;    // seconds for rxUart
      final static int SERIAL_TX_PIN  = CPU.pin1;
      final static int SERIAL_RX_PIN  = CPU.pin0;
      final static int CONNECT_STATUS  = CPU.pin5;
      final static int COMMAND_PIN  = CPU.pin6;
    
      //static Timer tTimer = new Timer();    // used to end waiting for rxUart
    
      static StringBuffer buf = new StringBuffer(BUFFLEN);
      static char tempChar;
    
      static Uart rxUart = new Uart( Uart.dirReceive, SERIAL_RX_PIN, Uart.dontInvert,
                               Uart.speed9600, Uart.stop1 );
      static Uart txUart = new Uart( Uart.dirTransmit, SERIAL_TX_PIN,Uart.dontInvert,
                               Uart.speed9600, Uart.stop1 );
    
    
      static void getblue(boolean prt){
          buf.clear();
          while ( (tempChar =(char)rxUart.receiveByte()) != '\r' )
            buf.append(tempChar);
          if (prt){
            System.out.println(buf.toString());
            buf.clear();  //assume buffer should be destroyed since printed
          }
      }
    
      static void printprmt(boolean prt){
          buf.clear();
          tempChar = '*';
          do {
            while ( (tempChar =(char)rxUart.receiveByte()) != '\r' ) {
              buf.append(tempChar);
              if (tempChar == '>')
                return;
            }
            if (prt){
              System.out.println(buf.toString());
              buf.clear();  //assume buffer should be destroyed since printed
            }
          } while (tempChar != '>');
      }
    
    
      static void blueCommand2(String me, boolean prt){
      // using soft and gaining a pin but is slower
          boolean b;
          int x;
          if (CPU.readPin(CONNECT_STATUS) == true){
            if (softbufMode() == false) {
              System.out.println("Failed: Switch to buf mode\r");
              return;
            }
          }
          buf.clear();
          txUart.sendString(me);
          txUart.sendString("\r");
          if (Expect.string(rxUart, "ACK\r", EXPECTDELAY)){
              printprmt(prt);
          }else{
            System.out.print("buf: ");
            System.out.print(me);
            System.out.println(" Did not ACK!\r");
          }
          if (CPU.readPin(CONNECT_STATUS) == true){
            txUart.sendString("\r"); // seems to work better than examples in book
          }
      }
    
      static void blueCommand3(String me, boolean prt){
      // using hard switching between modes usws a pin but is faster
          boolean b;
          int x;
          if (CPU.readPin(CONNECT_STATUS) == true){
            if (hardbufMode() == false) {
              System.out.println("Failed: Switch to buf mode\r");
              return;
            }
          }
          buf.clear();
          txUart.sendString(me);
          txUart.sendString("\r");
          if (Expect.string(rxUart, "ACK\r", EXPECTDELAY)){
              printprmt(prt);
          }else{
            System.out.print("buf: ");
            System.out.print(me);
            System.out.println(" Failed");
          }
          if (CPU.readPin(CONNECT_STATUS) == true){
            CPU.writePin(COMMAND_PIN,true);
            CPU.delay(50);
          }
      }
    
      static boolean softbufMode(){
        CPU.delay(20000);   //2 secs
        txUart.sendString("+++");
        CPU.delay(20000);   //2 secs
        txUart.sendString("\r");
        if (Expect.string(rxUart, ">", 3))
          return true;
        else
          return false;
      }
    
      static boolean hardbufMode(){
        CPU.writePin(COMMAND_PIN,false);
        txUart.sendString("\r");
        if (Expect.string(rxUart, ">", EXPECTDELAY))
          return true;
        else
          return false;
      }
    
      public static void main() {
    
         char data;
         if (CPU.readPin(CONNECT_STATUS) == true){
           System.out.println("Currently Connected");
           blueCommand3("dis",true);
         }else
           System.out.println("NOT Currently Connected");
         if (CPU.readPin(COMMAND_PIN) == true)
           System.out.println("IN Data Mode");
         else
           System.out.println("IN Command Mode");
    
         blueCommand3("get addr",true);
         blueCommand3("ver all",true);
         blueCommand3("lst 15",true);
         blueCommand3("con 00:0B:0D:21:46:FD",true);
    
         System.out.println("Listening...");
         getblue(true);   // puts sent data into buf and prints till enter
    
         System.out.println("*** Test FINISHED ***");
    
    
      }
    
    
  • jmstepanekjmstepanek Posts: 3
    edited 2005-02-25 03:16
    Thanks, TimC.

    That was a very quick reply. This code sample should be very helpful.

    Thanks again.

    J. Stepanek
Sign In or Register to comment.