mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 22:02:17 +01:00
fix: give out ids up to the maximum
New ids stopped two short of the limits, at 30 shades, 14 groups and 14 rooms instead of 32, 16 and 16, while the web UI showed the full limits. The original loop ran i < MAX - 1, an off-by-one: nothing indexes by id or treats the last two ids as special. ModelSnapshot's next-id answers and SomfyShadeController's allocation now run from 1 to the maximum. Found during LOOP_QUEUE_PLAN.md's review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
bee6a6d60b
commit
e4ac7a29c6
3 changed files with 17 additions and 8 deletions
|
|
@ -126,18 +126,18 @@ void writeGroup(JsonFormatter &json, const group_snapshot_t &group, shade_lookup
|
|||
uint8_t nextRoomId(const model_snapshot_t &snap) {
|
||||
uint8_t ids[SOMFY_MAX_ROOMS];
|
||||
for(uint8_t i = 0; i < snap.roomCount; i++) ids[i] = snap.rooms[i].roomId;
|
||||
return firstFreeId(ids, snap.roomCount, SOMFY_MAX_ROOMS - 2);
|
||||
return firstFreeId(ids, snap.roomCount, SOMFY_MAX_ROOMS);
|
||||
}
|
||||
uint8_t nextShadeId(const model_snapshot_t &snap) {
|
||||
uint8_t ids[SOMFY_MAX_SHADES];
|
||||
for(uint8_t i = 0; i < snap.shadeCount; i++) ids[i] = snap.shades[i].shadeId;
|
||||
const uint8_t id = firstFreeId(ids, snap.shadeCount, SOMFY_MAX_SHADES - 2);
|
||||
const uint8_t id = firstFreeId(ids, snap.shadeCount, SOMFY_MAX_SHADES);
|
||||
return id == 0 ? 255 : id;
|
||||
}
|
||||
uint8_t nextGroupId(const model_snapshot_t &snap) {
|
||||
uint8_t ids[SOMFY_MAX_GROUPS];
|
||||
for(uint8_t i = 0; i < snap.groupCount; i++) ids[i] = snap.groups[i].groupId;
|
||||
const uint8_t id = firstFreeId(ids, snap.groupCount, SOMFY_MAX_GROUPS - 2);
|
||||
const uint8_t id = firstFreeId(ids, snap.groupCount, SOMFY_MAX_GROUPS);
|
||||
return id == 0 ? 255 : id;
|
||||
}
|
||||
uint32_t nextRemoteAddress(const model_snapshot_t &snap, uint8_t id) {
|
||||
|
|
|
|||
|
|
@ -149,11 +149,11 @@ void SomfyShadeController::processWaitingFrame() {
|
|||
if(this->shades[i].getShadeId() != 255) this->shades[i].processWaitingFrame();
|
||||
}
|
||||
// A deleted shade, group or room leaves a gap, so a new one takes the lowest
|
||||
// free id. Ids stop two short of the maximum, as they always have.
|
||||
// free id, from 1 up to the maximum.
|
||||
uint8_t SomfyShadeController::getNextShadeId() {
|
||||
uint8_t ids[SOMFY_MAX_SHADES];
|
||||
for(uint8_t i = 0; i < SOMFY_MAX_SHADES; i++) ids[i] = this->shades[i].getShadeId();
|
||||
const uint8_t id = firstFreeId(ids, SOMFY_MAX_SHADES, SOMFY_MAX_SHADES - 2);
|
||||
const uint8_t id = firstFreeId(ids, SOMFY_MAX_SHADES, SOMFY_MAX_SHADES);
|
||||
return id == 0 ? 255 : id;
|
||||
}
|
||||
int8_t SomfyShadeController::getMaxShadeOrder() {
|
||||
|
|
@ -173,13 +173,13 @@ int8_t SomfyShadeController::getMaxGroupOrder() {
|
|||
uint8_t SomfyShadeController::getNextGroupId() {
|
||||
uint8_t ids[SOMFY_MAX_GROUPS];
|
||||
for(uint8_t i = 0; i < SOMFY_MAX_GROUPS; i++) ids[i] = this->groups[i].getGroupId();
|
||||
const uint8_t id = firstFreeId(ids, SOMFY_MAX_GROUPS, SOMFY_MAX_GROUPS - 2);
|
||||
const uint8_t id = firstFreeId(ids, SOMFY_MAX_GROUPS, SOMFY_MAX_GROUPS);
|
||||
return id == 0 ? 255 : id;
|
||||
}
|
||||
uint8_t SomfyShadeController::getNextRoomId() {
|
||||
uint8_t ids[SOMFY_MAX_ROOMS];
|
||||
for(uint8_t i = 0; i < SOMFY_MAX_ROOMS; i++) ids[i] = this->rooms[i].roomId;
|
||||
return firstFreeId(ids, SOMFY_MAX_ROOMS, SOMFY_MAX_ROOMS - 2);
|
||||
return firstFreeId(ids, SOMFY_MAX_ROOMS, SOMFY_MAX_ROOMS);
|
||||
}
|
||||
int8_t SomfyShadeController::getMaxRoomOrder() {
|
||||
int8_t orders[SOMFY_MAX_ROOMS];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue