Fixed minor issues with the tick code, works suprisingly well otherwise!
This commit is contained in:
parent
84ddcb3a1d
commit
1319dd43c6
128
API.md
Normal file
128
API.md
Normal file
@ -0,0 +1,128 @@
|
||||
# API
|
||||
|
||||
- [GET /api/version](#get-version)
|
||||
- [GET /api/connection/status](#get-connection-status)
|
||||
- [GET /api/connection](#get-connection)
|
||||
- [POST /api/connection](#post-connection)
|
||||
- [GET /api/steps](#get-steps)
|
||||
- [POST /api/steps](#post-steps)
|
||||
- [POST /api/firmware](#post-firmware)
|
||||
|
||||
<a name="get-version"></a>
|
||||
## GET /api/version
|
||||
|
||||
Returns the unique identifier of the chip and the version of the firmware.
|
||||
|
||||
*Example response:*
|
||||
```json
|
||||
{
|
||||
"systemID": "st41r",
|
||||
"version": "2.0.0-beta.1+6"
|
||||
}
|
||||
```
|
||||
|
||||
<a name="get-connection-status"></a>
|
||||
## GET /api/connection/status
|
||||
|
||||
Returns the status of the WiFi connections.
|
||||
|
||||
The value of the 'status' element corresponds to the ```wl_status_t``` enum as defined in [wl_definitions.h](https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/include/wl_definitions.h).
|
||||
|
||||
*Example response:*
|
||||
```json
|
||||
{
|
||||
"ap": {
|
||||
"enabled": true,
|
||||
"ip": "192.168.4.1"
|
||||
},
|
||||
"station": {
|
||||
"enabled": true,
|
||||
"status": 3,
|
||||
"ip": "10.138.1.10"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<a name="get-connection"></a>
|
||||
## GET /api/connection
|
||||
|
||||
Returns the settings of the WiFi connections.
|
||||
|
||||
*Example response:*
|
||||
```json
|
||||
{
|
||||
"hostname": "stairs",
|
||||
"accesspoint": true,
|
||||
"station": true,
|
||||
"ssid": "MyWiFi",
|
||||
"password": "12345678",
|
||||
"dhcp": true,
|
||||
"ip": "",
|
||||
"subnetmask": "",
|
||||
"gateway": ""
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
<a name="post-connection"></a>
|
||||
## POST /api/connection
|
||||
|
||||
Updates the settings of the WiFi connections. The module will apply the new settings immediately and will break existing connections.
|
||||
|
||||
*Example request:*
|
||||
```json
|
||||
{
|
||||
"hostname": "LivingRoomStairs",
|
||||
"accesspoint": false,
|
||||
"station": true,
|
||||
"ssid": "MyWiFi",
|
||||
"password": "12345678",
|
||||
"dhcp": false,
|
||||
"ip": "10.138.1.100",
|
||||
"subnetmask": "255.255.255.0",
|
||||
"gateway": "10.138.1.1"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
<a name="get-steps"></a>
|
||||
## GET /api/steps
|
||||
|
||||
Returns the current brightness value for each step. The number of items in the array is equal to the number of configured steps. Each value has a range of 0 to 255.
|
||||
|
||||
*Example response:*
|
||||
```json
|
||||
[
|
||||
0, 10, 30, 50, 80, 110, 130, 150,
|
||||
160, 170, 180, 190, 200, 230, 255
|
||||
]
|
||||
```
|
||||
|
||||
<a name="post-steps"></a>
|
||||
## POST /api/steps
|
||||
|
||||
Changes the brightness value for each step. If the number of values in the array is less than the number of configured steps, each subsequent step is considered to be off.
|
||||
|
||||
An optional element 'transitionTime' can be included which specifies how long the transition from the current value of each step to it's new value should take, the module will then smoothly fade between the values. The transition time must be specified in milliseconds. Assume a maximum of 30 seconds, because I did not test with higher values. Ain't nobody got time for that! If no transition time or 0 is specified, the new values will be applied immediately.
|
||||
|
||||
An optional array 'startTime' can be included which specifies the delay, for each step individually, before the transition will start. The example request uses this to create a sweeping effect. If no or not enough values are provided, they are assumed to be 0.
|
||||
|
||||
*Example request:*
|
||||
```json
|
||||
{
|
||||
"transitionTime": 500,
|
||||
"values": [
|
||||
128, 128, 128, 128, 128, 128, 128, 128,
|
||||
128, 128, 128, 128, 128, 128, 128
|
||||
],
|
||||
"startTime": [
|
||||
0, 50, 100, 150, 200, 250, 300, 350,
|
||||
400, 450, 500, 550, 600, 650, 700
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
<a name="post-firmware"></a>
|
||||
## POST /api/firmware
|
||||
|
||||
Uploads new firmware. The bin file should be posted as a multipart/form-data file attachment. Name is not relevant.
|
@ -2120,8 +2120,8 @@ const uint8_t EmbeddedBundleJS[] PROGMEM = {
|
||||
0xde,0x3f,0xe5,0xcf,0xd2,0x8f,0x6f,0x91,0x8d,0x3d,0x0d,0x25,0x4b,0xdc,0x65,0x6b,0x3b,0xef,0xab,0x52,
|
||||
0x06,0x14,0xde,0xf9,0x32,0xb9,0xab,0xf2,0xec,0x97,0x3a,0x6d,0x5e,0xb7,0x1f,0x6c,0x74,0x8c,0xdd,0x05,
|
||||
0x17,0xb8,0x79,0xf0,0x8f,0x0e,0x0f,0xbf,0x10,0x42,0x23,0x99,0x1c,0xc0,0xcf,0x60,0x19,0xc3,0x8d,0x53,
|
||||
0xbf,0x46,0x25,0x4c,0x2d,0x4b,0x83,0x4b,0xcc,0xed,0x03,0xd2,0x9d,0x7f,0x4f,0x0c,0x12,0x3b,0x4b,0xb8,
|
||||
0x6d,0xfc,0x9b,0xcb,0xb5,0xd5,0x61,0x22,0xcc,0x9d,0xe3,0xf4,0xe6,0x39,0xe3,0x98,0xad,0x30,0x9f,0xc3,
|
||||
0xba,0xe2,0xaa,0x6e,0xf3,0xbf,0x01,0x22,0xb6,0x27,0xc8,0x5c,0xdc,0x01,0x00};
|
||||
0x7f,0x8b,0x4a,0x98,0x5a,0xb6,0x06,0x17,0x99,0xdb,0x87,0xa4,0xbb,0x06,0x9e,0x18,0x25,0x76,0x96,0x70,
|
||||
0xdd,0xf8,0x37,0x97,0x6c,0xab,0xd3,0x44,0x9c,0x3b,0x47,0xea,0xcd,0xf3,0xc6,0x71,0x5b,0x61,0x42,0x87,
|
||||
0xb5,0xc5,0x75,0xdd,0xe6,0x7f,0x03,0xa4,0x3f,0xb2,0xfe,0x60,0xdc,0x01,0x00};
|
||||
|
||||
#endif
|
||||
|
@ -4,10 +4,10 @@
|
||||
const uint8_t VersionMajor = 2;
|
||||
const uint8_t VersionMinor = 0;
|
||||
const uint8_t VersionPatch = 0;
|
||||
const uint8_t VersionMetadata = 5;
|
||||
const uint8_t VersionMetadata = 7;
|
||||
const char VersionBranch[] = "release/2.0";
|
||||
const char VersionSemVer[] = "2.0.0-beta.1";
|
||||
const char VersionFullSemVer[] = "2.0.0-beta.1+5";
|
||||
const char VersionCommitDate[] = "2018-01-04";
|
||||
const char VersionFullSemVer[] = "2.0.0-beta.1+7";
|
||||
const char VersionCommitDate[] = "2018-01-05";
|
||||
|
||||
#endif
|
||||
|
@ -69,6 +69,7 @@ void setup()
|
||||
pwmDriver = new PCA9685();
|
||||
pwmDriver->setAddress(PWMDriverAddress, PinSDA, PinSCL);
|
||||
pwmDriver->setPWMFrequency(PWMDriverPWMFrequency);
|
||||
pwmDriver->setAll(0);
|
||||
|
||||
_dln("Setup :: initializing Stairs");
|
||||
stairs = new Stairs();
|
||||
@ -76,8 +77,6 @@ void setup()
|
||||
|
||||
|
||||
_dln("Setup :: starting initialization sequence");
|
||||
stairs->setAll(0);
|
||||
|
||||
stairs->set(0, 255);
|
||||
delay(300);
|
||||
|
||||
|
@ -21,9 +21,11 @@ void handleGetSteps(AsyncWebServerRequest *request)
|
||||
|
||||
DynamicJsonBuffer jsonBuffer(JSON_ARRAY_SIZE(17));
|
||||
|
||||
bool target = !request->hasParam("current");
|
||||
|
||||
JsonArray& root = jsonBuffer.createArray();
|
||||
for (uint8_t step = 0; step < stepsSettings->count(); step++)
|
||||
root.add(stairs->get(step));
|
||||
root.add(stairs->get(step, target));
|
||||
|
||||
AsyncResponseStream *response = request->beginResponseStream("application/json");
|
||||
root.printTo(*response);
|
||||
@ -56,7 +58,7 @@ void handlePostSteps(AsyncWebServerRequest *request, uint8_t *data, size_t len,
|
||||
|
||||
|
||||
for (uint8_t step = 0; step < valueCount; step++)
|
||||
stairs->set(step, values[step], transitionTime, step < startTimeCount ? 1 : 0);
|
||||
stairs->set(step, values[step], transitionTime, step < startTimeCount ? startTime[step] : 0);
|
||||
|
||||
request->send(200);
|
||||
}
|
||||
|
@ -70,5 +70,5 @@ void handleFirmwareFile(AsyncWebServerRequest *request, String filename, size_t
|
||||
|
||||
void registerFirmwareRoutes(AsyncWebServer* server)
|
||||
{
|
||||
server->on("/firmware", HTTP_POST, handleFirmware, handleFirmwareFile);
|
||||
server->on("/api/firmware", HTTP_POST, handleFirmware, handleFirmwareFile);
|
||||
}
|
@ -126,6 +126,9 @@ void Stairs::tick()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!mTick)
|
||||
mLastTransitionTime = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -138,11 +141,16 @@ uint8_t Stairs::get(uint8_t step, bool target)
|
||||
|
||||
void Stairs::set(uint8_t step, uint8_t brightness, uint16_t transitionTime, uint16_t startTime)
|
||||
{
|
||||
_d("Stairs :: set step = "); _d(step);
|
||||
_d(", brightness = "); _d(brightness);
|
||||
_d(", transitionTime = "); _d(transitionTime);
|
||||
_d(", startTime = "); _dln(startTime);
|
||||
|
||||
|
||||
if (step >= MaxStepCount) return;
|
||||
if (mStep[step].currentValue == brightness)
|
||||
return;
|
||||
|
||||
mTick = true;
|
||||
mStep[step].targetValue = brightness;
|
||||
|
||||
if (transitionTime > 0)
|
||||
@ -150,6 +158,16 @@ void Stairs::set(uint8_t step, uint8_t brightness, uint16_t transitionTime, uint
|
||||
mStep[step].startValue = mStep[step].currentValue;
|
||||
mStep[step].startTime = startTime;
|
||||
mStep[step].remainingTime = transitionTime;
|
||||
|
||||
if (!mLastTransitionTime)
|
||||
mLastTransitionTime = currentTime;
|
||||
|
||||
mTick = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mStep[step].currentValue = brightness;
|
||||
applyCurrentValue(step);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -270,7 +270,7 @@ function startApp()
|
||||
}
|
||||
};
|
||||
|
||||
axios.post('/firmware', data, config)
|
||||
axios.post('/api/firmware', data, config)
|
||||
.then(function(response)
|
||||
{
|
||||
// TODO show "now updating, please wait"
|
||||
|
2
web/dist/bundle.js
vendored
2
web/dist/bundle.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user