Provides access to core Grabba driver and hardware functionality, such as opening and closing communications.
This API provides access to device-wide functionality, and to selected features common to all Grabba hardware (e.g. battery level).
Callbacks to user-provided code may be triggered when the driver connects to or disconnects from the Grabba device. Refer to the ConnectionListener class for the details of these callbacks and how to enable them.
Most calls to this and other driver APIs will not succeed until a connection to a Grabba device has been established. This connection may be triggered by calling open(), typically in the onResume handler for an activity, and then either waiting for a connection event or polling the output of connected() until it returns true.
If open() has been called, close() or deferredClose() must be called at a later time to terminate any active connections and free resources. Typically this should take the form of a call to deferredClose() in the onPause handler for an activity, however this call may occur earlier if an activity no longer needs access to the Grabba Driver.
Thread safety: This class is fully thread-safe.
Static Public Member Functions | |
static byte | batteryLevel () |
Query the battery level of a connected Grabba device. More... | |
static void | close () |
Close the communication channel to the device if it has previously been opened. More... | |
static boolean | closePending () |
Query whether a deferredClose() operation is currently pending. More... | |
static boolean | connected () |
Query whether the driver is currently connected to a Grabba device. More... | |
static void | deferredClose (int interval) |
Close the communication channel to the device if it has previously been opened, after a given interval has elapsed. More... | |
static String | deviceModel () |
Query the model number of a connected Grabba device. More... | |
static String | driverVersion () |
Query the version number of the Grabba driver. More... | |
static String | hardwareVersion () |
Query the hardware version number of a connected Grabba device. More... | |
static boolean | open (@NonNull Context ctxt) |
Attempt to open the communications channel to the device. More... | |
static boolean | opened () |
Query whether the communication channel has been opened. More... | |
static String | serialNumber () |
Query the serial number of a connected Grabba device. More... | |
|
static |
Query the battery level of a connected Grabba device.
This is a non-blocking call; the driver polls the battery level at regular intervals and caches the value internally.
|
static |
Close the communication channel to the device if it has previously been opened.
If the communication channel is open (even if not connected), then this call will close it, preventing further communication with the hardware. If the communication channel is already closed, then this call has no effect.
This is a blocking call, and consequently should not typically be triggered from any thread or other context which is latency-sensitive (e.g. UI threads). The one exception to this is that it may be desirable to call this from the UI thread in an activity's onPause handler; doing so would ensure that the Grabba driver is fully closed prior to application suspension or shutdown.
|
static |
Query whether a deferredClose() operation is currently pending.
This is a non-blocking call.
|
static |
Query whether the driver is currently connected to a Grabba device.
This is a non-blocking call; it will return the current state immediately, without waiting for any in-progress operations to complete.
|
static |
Close the communication channel to the device if it has previously been opened, after a given interval has elapsed.
This call is asynchronous, and will trigger processing as follows:
Note that other applications will be unable to access the Grabba Driver whilst the interval elapses, so it is important to avoid setting it too high. However, if set too low there is a risk that the connection may be lost, which is likely to involve a delay of several seconds for re-establishment.
interval | Duration in milliseconds which this call will wait before calling close(), subject to there being no open() or close() calls in the meantime. The permitted range is 0-5000ms (i.e. 0-5s); any values outside that range will be clamped. Values in the 1000-2000ms (i.e. 1-2s) range are likely to be reasonable for most applications. |
|
static |
Query the model number of a connected Grabba device.
This is a non-blocking call; the driver caches the model number internally.
|
static |
Query the version number of the Grabba driver.
This is a non-blocking call.
|
static |
Query the hardware version number of a connected Grabba device.
This is a non-blocking call; the driver caches the hardware version number internally.
|
static |
Attempt to open the communications channel to the device.
If the communications channel is presently closed (or has yet to be opened for the first time), then this call will attempt to open the channel. If the communications channel is already opened, then this call has no effect other than cancelling any pending deferredClose() calls.
This is a non-blocking call; consequently, it can't report on the success or failure of a connection attempt. If a connection attempt succeeds, any active ConnectionListener objects will receive events, and can trigger callbacks into application code; consequently, constructing an object of a ConnectionListener subclass is recommended prior to the first call to open().
If a connection attempt fails, or if an existing connection is lost, then the driver will automatically attempt to reconnect; there is no need to call open() again. If it is necessary to guarantee disconnection, then close() should be called; open() can then be called again if a subsequent reconnection is needed.
ctxt | Android context in which the driver is to operate; should be the context of the enclosing application. If the supplied context is not an application-level context, then the driver will obtain a reference to the associated application context from it, so as to avoid memory leaks. |
|
static |
Query whether the communication channel has been opened.
This is a non-blocking call; it will return the current state immediately, without waiting for any in-progress open or close operations to complete.
|
static |
Query the serial number of a connected Grabba device.
This is a non-blocking call; the driver caches the serial number internally.