Versions Compared

Key

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

...

Vi råder derfor alle til å KUN KJØRE KODE SOM DERE STOLER PÅ! Det vil si kode som ligger hos en bruker dere har kontroll på. Den kjørbare koden kan alltid leses på nett på  Som standard ser appen etter filer på hjemmeområdet ditt på NTNU. Plasseringen er folk.ntnu.no/[BRUKERNAVN]/plab/plab.pde og du kan se etter der om du er usikker før du kobler til, men dette kan endres i innstillinger i appen (trykk på det lille tannhjulet i høyre hjørnet). Hvis du ikke kjenner koden fra før, anbefaler vi at du sjekker på nett hva den faktisk er før du kjører den.

Det injiserte objektet

Javascript objektet som injiseres har tydelig definerte interfaces, som dokumenteres i InterfacesInc eksempelet på GitHub kontoen vår. I denne koden ligger også to event klasser og lytte interfacer. Denne koden er med i appen, så du trenger ikke å laste opp denne filen når du laster opp kode til appen.

Code Block
languagejava
titleInterfaces
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); 
}

...