Zum Inhalt springen

HSC2011/Software/Frontend/Application development: Unterschied zwischen den Versionen

Chrysn (Diskussion | Beiträge)
moved from Frontend documentation
 
Chrysn (Diskussion | Beiträge)
updated to last upload
 
Zeile 17: Zeile 17:
by simply overwriting the <tt>display</tt> function.
by simply overwriting the <tt>display</tt> function.


=== querying buzzers ===
If you set up interval callbacks, make sure you remove them when <tt>Edubuzzer.stop_application</tt> is called.


<tt>/ygor</tt> is the base URI for the middleware endpoint. Send <tt>GET</tt> requests to
=== general infrastructure ===
certain named queries, e.g. <tt>?name=ls_accepted_login.sql</tt>. For the full list,
see directory <tt>Ygor/sql/</tt> in the [https://github.com/Metalab/hsc2011/tree/master/software software repository]. It returns a JSON array of objects/hashes whose
keys are described in the SQL file, e.g. for above:


<code>   
Throughout the games, the [http://api.jquery.com/jQuery.getJSON/ jQuery] library is used. In order to display buzzers, fill the <tt>$("#buzzers")</tt> area, additional user interface can be shown in <tt>$("#post-buzzers")</tt>.
    [{"rowid":42,"src":"BUZZER-DEVICE-ID","dest":"MASTER-DEVICE-ID",
        "seqnum":23,"ibutton":"SOMETHING","since":"TIMESTAMP",
        "accepted":true,"ack":false}, … ]
</code>


Refer to the table schemas in <tt>Ygor/schema/</tt> for explicit key/row names. Rely
=== talking to buzzers ===
on <tt>src</tt> for uniquely identifying a buzzer.


The most important query is <tt>ls_events.sql</tt> because it deals with the device
The <tt>global.js</tt> 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 <tt>dst</tt>, do this:
buttons. The first line in the file hints at the additional query parameters,
in this case <tt>loginid</tt>, i.e. the full query string is
<tt>?name=ls_events&loginid=ROWID</tt> where <tt>ROWID</tt> is a number received in earlier
different queries. Extract the button status from the <tt>eventmask</tt> field. See
<tt>docs/serialprotocol</tt> for the semantics.


For debugging purposes the middleware exposes an echo interface at base URI
Edubuzzer.send_package(dst, 'S', 's', 'n n yyyy 00 00', function() {});
<tt>/echo</tt>. The query string is ignored except for the parameter name
<tt>Response-Body</tt>. Its value is a percent encoded JSON string which
unsurprisingly is returned as response body.


For example, you want to mock:
<tt>'S'</tt> is the package type to send (as described in [[HSC2011/Communication/Serial protocol|the serial documentation]]), <tt>'s'</tt> the type of the acknowledgement that is expected, <tt>'n n …'</tt> the payload (as described there as well), and the function will get called once the command is acknowledged by the buzzer.


<code>
Be aware that while the [[HSC2011/Software/Ygor|underlying middleware]] handles all requests in sequence, you can't rely on the browser to deliver multiple <tt>send_package</tt> calls in sequence.
    $.getJSON(
        Edubuzzer.middleware_endpoint+'?name=…',
        function (foo) {
            …
        }
    )
</code>


Add a [http://api.jquery.com/jQuery.getJSON/ second parameter to the <tt>getJSON</tt> call], thus:
Events other than acknowledgements you can receive by implementing the hook <tt>Edubuzzer.new_event(event)</tt>. Event will be an object with members <tt>src</tt>, <tt>type</tt> and <tt>payload</tt>, with <tt>type</tt> typically being <tt>"E"</tt>. The payload is typically <tt>"b0001"</tt> for the first button going down etc. (again, see, the serial documentation).


<code>
    $.getJSON(
        Edubuzzer.middleware_mock_endpoint+'?name=…',
        'Response-Body'+encodeURIComponent('[{"rowid":123}]')
        function (foo) {
            …
        }
    )
</code>


=== instruction list ===
=== instruction list ===