Skip to content

Commit

Permalink
feat(vendor.viomi): Track active segments
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Nov 11, 2022
1 parent 7882db4 commit 56b0bf6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions backend/lib/robots/viomi/ViomiMapParser.js
Expand Up @@ -315,7 +315,7 @@ class ViomiMapParser {
type: Map.MapLayer.TYPE.SEGMENT,
metaData: {
segmentId: segmentId,
active: false,
active: !!this.img.activeSegments[segmentId],
name: mapContents.zones[segmentId].name
}
}));
Expand Down Expand Up @@ -540,6 +540,8 @@ class ViomiMapParser {
wall: [],
rooms: {}
};
const activeSegments = {};

if (height > 0 && width > 0) {
for (let i = 0; i < height * width; i++) {
const val = this.buf.readUInt8(this.offset++);
Expand All @@ -557,7 +559,14 @@ class ViomiMapParser {
pixels.floor.push([coords[0], coords[1]]);
break;
default: {
const segmentId = val >= 60 ? val - 50 : val; //TODO: this can't be right but it works?
const isActive = val >= 60;
let segmentId = val;

if (isActive) {
segmentId = segmentId - 50; //TODO: this can't be right but it works?
activeSegments[segmentId] = true;
}

if (!Array.isArray(pixels.rooms[segmentId])) {
pixels.rooms[segmentId] = [];
}
Expand All @@ -578,6 +587,7 @@ class ViomiMapParser {
height: height,
width: width,
},
activeSegments: activeSegments,
pixels: pixels,
};
}
Expand Down
Expand Up @@ -1654,7 +1654,7 @@
"__class": "MapLayer",
"metaData": {
"segmentId": "10",
"active": false,
"active": true,
"name": "room1",
"area": 39775
},
Expand Down

0 comments on commit 56b0bf6

Please sign in to comment.