HSC2011/Software/Frontend/Application development

aus Metalab Wiki, dem offenen Zentrum für meta-disziplinäre Magier und technisch-kreative Enthusiasten.
Zur Navigation springenZur Suche springen


architectural overview

Each Edubuzzer app, e.g. Raise Your Hands, is chiefly implemented in a single responsible JavaScript file, e.g. raise-your-hands.js, located in Ygor's www directory. Each one can define a single callback, Edubuzzer.run_application which is called when the application is started.

Inside Edubuzzer.run_application it may register other callbacks like Edubuzzer.updated_known_logins which is called whenever a client is added or removed, or Edubuzzer.display which is called in regular intervals.

global.js runs a poor man's event loop and schedules all pollings to the server which result in callbacks of the active app registered being called. An app is activated by changing the URI #hash. The skeleton switches to an app by simply overwriting the display function.

If you set up interval callbacks, make sure you remove them when Edubuzzer.stop_application is called.

general infrastructure

Throughout the games, the jQuery library is used. In order to display buzzers, fill the $("#buzzers") area, additional user interface can be shown in $("#post-buzzers").

talking to buzzers

The global.js library implements most of the buzzer communication you'll need. For example, in order to turn on all the four LEDs on a buzzer called dst, do this:

Edubuzzer.send_package(dst, 'S', 's', 'n n yyyy 00 00', function() {});

'S' is the package type to send (as described in the serial documentation), 's' the type of the acknowledgement that is expected, 'n n …' the payload (as described there as well), and the function will get called once the command is acknowledged by the buzzer.

Be aware that while the underlying middleware handles all requests in sequence, you can't rely on the browser to deliver multiple send_package calls in sequence.

Events other than acknowledgements you can receive by implementing the hook Edubuzzer.new_event(event). Event will be an object with members src, type and payload, with type typically being "E". The payload is typically "b0001" for the first button going down etc. (again, see, the serial documentation).

instruction list

  • decide on an app name (e.g. exampleapp)
  • create a new JavaScript file with the name
  • implement the run_application function and the hooks you need
    • present the app UI in element #buzzers
    • keep internal data under the Edubuzzer.exampleapp namespace
  • add the app name/link in index.xhtml
  • register the app in global.js
  • add styles in edubuzzer.css