HSP Over REST API

Version 9 (J. Simmons, 10/11/2017 12:30 am)

1 1 J. Simmons
h1. HSP Over REST API
2 1 J. Simmons
3 1 J. Simmons
{{>toc}}
4 1 J. Simmons
5 1 J. Simmons
h2. Meaning of HTTP Verbs
6 1 J. Simmons
7 1 J. Simmons
|_.Verb|_.Meaning|
8 1 J. Simmons
|GET|Read value from controller|
9 1 J. Simmons
|PUT|Write value to controller (volatile) |
10 1 J. Simmons
|POST|Write value to controller (non-volatile)|
11 1 J. Simmons
|DELETE|Clear value from controller (volatile)|
12 1 J. Simmons
13 1 J. Simmons
h2. REST API
14 1 J. Simmons
15 5 J. Simmons
Items in _italics_ are for future development.  These methods will return a 501 not implemented status code (see "status codes":http://www.django-rest-framework.org/api-guide/status-codes/ for more details).
16 1 J. Simmons
17 1 J. Simmons
|_.URI |_.Verb|_.Operation|
18 1 J. Simmons
|/api/main/enabled|GET|Returns current enabled state|
19 1 J. Simmons
|/api/main/enabled|PUT|Update enabled state|
20 1 J. Simmons
|/api/main/stepsize|GET|Returns current step size [1-4]|
21 1 J. Simmons
|/api/main/stepsize|PUT|Update current step size [1-4]|
22 1 J. Simmons
|/api/main/profile|GET|Returns current profile name (will end in a * if settings have been updated since profile was set)|
23 2 J. Simmons
| _/api/main/profile_ | _PUT_ | _Sets current profile name (cannot end in a '*')_ |
24 1 J. Simmons
|/api/main/cadence|GET|Returns current cadence (>0 means forward, <0 means reverse)|
25 6 J. Simmons
|/api/main/version|GET|Returns hardware and firmware version data|
26 4 J. Simmons
|/api/forward|GET|Returns current forward action (see below), returns 404 status if no forward action is active|
27 1 J. Simmons
|/api/forward|PUT|Sets current forward action (see below)|
28 2 J. Simmons
| _/api/forward_ | _DELETE_ | _Clears current forward action_ |
29 4 J. Simmons
| _/api/forward/sprint_ | _GET_ | _Returns current forward sprint action (see below), returns 404 status if no forward sprint action is active_ |
30 2 J. Simmons
| _/api/forward/sprint_ | _PUT_ | _Sets current forward sprint action (see below)_| 
31 2 J. Simmons
| _/api/forward/sprint_ | _DELETE_ | _Clears current forward sprint action_ |
32 4 J. Simmons
|/api/reverse|GET|Returns current reverse action (see below), returns 404 status if no reverse action is active|
33 1 J. Simmons
|/api/reverse|PUT|Sets current reverse action (see below)|
34 2 J. Simmons
| _/api/reverse_ | _DELETE_ | _Clears current reverse action_ |
35 4 J. Simmons
| _/api/reverse/sprint_ | _GET_ | _Returns current reverse sprint action (see below), returns 404 status if no forward sprint action is active_ |
36 2 J. Simmons
| _/api/reverse/sprint_ | _PUT_ | _Sets current reverse sprint action (see below)_ |
37 2 J. Simmons
| _/api/reverse/sprint_ | _DELETE_ | _Clears current reverse sprint action_ |
38 1 J. Simmons
|/api/defaults|GET|Returns current defaults (see below)|
39 1 J. Simmons
|/api/defaults|POST|Sets new defaults (see below)|
40 1 J. Simmons
|/api/defaults|DELETE|Restore factory defaults (see below)|
41 2 J. Simmons
| _/api/resistance_ | _GET_ | _Returns current resistance setting of the pedals_ |
42 2 J. Simmons
| _/api/resistance_ | _PUT_ | _Sets current resistance setting of the pedals_ |
43 8 J. Simmons
|/api/debug|GET|Returns current debug state (True/False) as defined by the service configuration|
44 9 J. Simmons
|/api/debug/serial|GET|Returns last serial message from Holoseat (returns status 401 not authorized if debug state is false)|
45 9 J. Simmons
|/api/debug/serial|PUT|Sends a serial message to Holoseat (returns status 401 not authorized if debug state is false)|
46 1 J. Simmons
47 1 J. Simmons
h2. Specifying an Action
48 1 J. Simmons
49 1 J. Simmons
Actions are composed of 4 parts:
50 1 J. Simmons
# Device [keyboard|mouse|joypad] - what device is being emulated to implement this action
51 1 J. Simmons
#Input - what input value (e.g. key on a keyboard or button on a mouse) is being activated by the command
52 1 J. Simmons
# Command [press|hold] - how the input value should be sent:
53 1 J. Simmons
	press = press and release the input (e.g. press a key on a keyboard or click a mouse button)
54 1 J. Simmons
	hold = press and hold the input (e.g. hold down a key on a keyboard or a button on a mouse)
55 1 J. Simmons
# End [release|repeat|noop] - how to end the action
56 3 J. Simmons
	release = release the held input (requires command == 'hold')
57 3 J. Simmons
	repeat = repeat the action to end the action (requires command == 'press')
58 3 J. Simmons
	noop = no steps required to end the action, it will timeout in game (requires command == 'press') 
59 1 J. Simmons
60 3 J. Simmons
The JSON format for an action is show below for the default forward action (hold down the 'w' key down on a keyboard)
61 1 J. Simmons
62 1 J. Simmons
<pre>
63 1 J. Simmons
{
64 3 J. Simmons
"device": "keyboard",
65 3 J. Simmons
"input": 'w',
66 3 J. Simmons
"command": "hold",
67 3 J. Simmons
"end": "release"
68 1 J. Simmons
}
69 1 J. Simmons
</pre>
70 1 J. Simmons
71 1 J. Simmons
h2. Defaults	
72 1 J. Simmons
73 1 J. Simmons
The default settings for the Holoseat are those settings which are persisted in non-volatile memory.  They represent the most generic use case for the Holoseat and as such make a number of assumptions about the default actions associated with pedaling forward and backward.
74 1 J. Simmons
75 1 J. Simmons
Specifically, the default settings assume the only device being emulated is a keyboard, with a command/end pairing of hold/release for both the forward and backward actions.  Further, the default settings assume there are no sprint actions.  These assumptions leave the following minimum set of default settings.
76 1 J. Simmons
77 1 J. Simmons
# Enabled [True|False] - whether the Holoseat starts in the enabled state or not
78 1 J. Simmons
# Step Size [1-4] - the relative length of single steps (smaller values yield shorter steps)
79 1 J. Simmons
# Forward Character [alphanumeric character] - the key to press as the default forward action
80 1 J. Simmons
# Reverse Character [alphanumeric character] - the key to press as the default reverse action
81 1 J. Simmons

82 1 J. Simmons
The JSON format for default settings is show below for the factory defaults.
83 1 J. Simmons
84 1 J. Simmons
<pre>
85 1 J. Simmons
{
86 3 J. Simmons
"enabled": "True",
87 3 J. Simmons
"stepsize": 2,
88 3 J. Simmons
"forward": 'w',
89 3 J. Simmons
"reverse": 's'
90 1 J. Simmons
}
91 1 J. Simmons
</pre>
92 1 J. Simmons
93 1 J. Simmons
Note, the default settings are written to the Holoseat controller’s EEPROM which has an expected life of approximately 100,000 write operations.  While this should allow for more than sufficient lifespan for the Holoseat controller, we still want to take precautions to avoid malicious code burning through the available write operations.  To that end, the POST method on /api/defaults will be protected to only support calls from the application GUI.  Additionally, there will be a minimum 5 second timeout that must elapse between calls to update the default settings.