Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleInterfacesInterfacesInc
linenumberstrue
collapsetrue
/** 
 * PLabOrientationEvent is the event object received when phone changes orientation 
 */ 
class PLabOrientationEvent { 
  /** 
   * alpha - magnetic direction (in degrees) 
   */ 
  float alpha; 
  /** 
   * beta - tilt front-to-back, front is positive (in degrees) 
   */ 
  float beta; 
  /** 
   * gamma - tilt left-to-right, right is positive(in degrees) 
   */ 
  float gamma; 
}

/** 
 * PLabAccelerationEvent is the event object received at regular intervals, telling what acceleration is 
 */ 
class PLabAccelerationEvent { 
  /** 
   * x - acceleration in x direction 
   */ 
  float x; 
  /** 
   * y - acceleration in y direction 
   */ 
  float y; 
  /** 
   * z - acceleration in z direction 
   */ 
  float z; 
  /** 
   * timestamp - when the acceleration was meassured 
   */ 
  float timestamp; 
}

/** 
 * PLabBridge is the interface we have for communicating with the plab app. 
 */ 
interface PLabBridge { 
  /** 
   * gets the width we have available to draw on 
   */ 
  public int getWidth (); 
  /** 
   * gets the height we have available to draw on 
   */ 
  public int getHeight (); 
  /** 
   * sends a string to a connected bluetooth device. Can not send more than 20 characters. 
   */ 
  public void send (String string); 
  /** 
   * register callback function that will get the data sent from the connected device 
   */ 
  public void subscribeMessages (PLabRecv sub); 
  /** 
   * Disconnects the device and returns to main menu 
   */ 
  public void disconnect(); 
  /** 
   * hides the back button 
   */ 
  public void hideBackButton(); 
  /** 
   * display the back button 
   */ 
  public void showBackButton(); 
   
  /** 
   * make the device vibrate for given amount of time. On iOS time will be ignored. 
   */ 
  public void vibrate(int milliseconds); 
  /** 
   * Listen for device orientation changes 
   */ 
  public void addDeviceOrientationListener(PLabOrientationListener listener); 
  /** 
   * remove device orientation changes listener 
   */ 
  public void removeDeviceOrientationListener(PLabOrientationListener listener); 
  /** 
   * Listen for device acceleration changes 
   */ 
  public void addDeviceAccelerationListener(PLabAccelerationListener listener); 
  /** 
   * remove device acceleration changes listener 
   */ 
  public void removeDeviceAccelerationListener(PLabAccelerationListener listener); 
  /** 
   * Set milliseconds between each acceleration update 
   */ 
  public void setDeviceAccelerationUpdateInterval(int milliseconds); 
} 
 
/** 
 * A simple interface that defines the callback read function 
 */ 
interface PLabRecv { 
  /** 
   * The callback function. Will be called when the connected device sends something to this program. 
   */ 
  public void receive(String message); 
} 
 
/** 
 * PLabOrientationListener is the interface describing an orientation change listener 
 */ 
interface PLabOrientationListener { 
  public void deviceOrientation(PLabOrientationEvent event); 
} 
 
/** 
 * PLabAccelerationListener is the interface describing an acceleration event listener 
 */ 
interface PLabAccelerationListener { 
  public void deviceAcceleration(PLabAccelerationEvent event); 
}

...

Når du har paret en enhet kan du bruke datamaskina som kontroll på samme måte som du kan bruke appen vår. Vi har lagd kopier-og-lim-inn kode som skal hjelpe deg med det, og gjøre det rett fram å overføre koden du har skrevet til mobil enhet. Koden ligger som del av ArduinoMobileIntegrationExamples/MinimalBTExample/Processing-computer/MinimalBTExample. Koden du kan klippe ut og lime inn er den som er rett under. Endre på linje 46-56 for å tilpasse til din maskin/os. Kall , og er fila AppReplacer. Bare kopier denne fila til prosjektet ditt, endre navn på kom port/ fjern kommentering på søkealgoritmen og kall setupSerial() fra den vanlige setup() metoden for å få det hele til å virke.

...

languagejava
titleProcessingComputerCode
linenumberstrue

...

.

...

Den forutsetter at interfacene beskrevet i Interfaces er tilstede, og vi legger dem ved for helhetens skyld.

...

languagejava
titleInterfaces - gjentatt
linenumberstrue

...

For at det skal virke, må dere kalle setupSerial() fra setup(). Ellers er det bare å kjøre vanlig Processing utvikling og kode.

...