Skip to content

Commit

Permalink
[miio] add moppath & carpet area to robomap (openhab#11097)
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Verpaalen <[email protected]>
  • Loading branch information
marcelrv authored and frederictobiasc committed Oct 26, 2021
1 parent e40d652 commit 6e0df54
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class RRMapDraw {
private static final Color COLOR_MAP_INSIDE = new Color(32, 115, 185);
private static final Color COLOR_MAP_OUTSIDE = new Color(19, 87, 148);
private static final Color COLOR_MAP_WALL = new Color(100, 196, 254);
private static final Color COLOR_CARPET = new Color(0xDF, 0xDF, 0xDF, 0xA0);
private static final Color COLOR_GREY_WALL = new Color(93, 109, 126);
private static final Color COLOR_PATH = new Color(147, 194, 238);
private static final Color COLOR_ZONES = new Color(0xAD, 0xD8, 0xFF, 0x8F);
Expand Down Expand Up @@ -189,6 +190,33 @@ private void drawMap(Graphics2D g2d, float scale) {
}
}

/**
* draws the carpet map
*/
private void drawCarpetMap(Graphics2D g2d, float scale) {
if (rmfp.getCarpetMap().length == 0) {
return;
}
Stroke stroke = new BasicStroke(1.1f * scale);
g2d.setStroke(stroke);
for (int y = 0; y < rmfp.getImgHeight() - 1; y++) {
for (int x = 0; x < rmfp.getImgWidth() + 1; x++) {
int carpetType = rmfp.getCarpetMap()[x + rmfp.getImgWidth() * y];
switch (carpetType) {
case 0:
// ignore
break;
default:
g2d.setColor(COLOR_CARPET);
float xPos = scale * (rmfp.getImgWidth() - x);
float yP = scale * y;
g2d.draw(new Line2D.Float(xPos, yP, xPos, yP));
break;
}
}
}
}

/**
* draws the vacuum path
*
Expand Down Expand Up @@ -445,6 +473,7 @@ public BufferedImage getImage(float scale) {
tx.translate(-width, -height);
g2d.setTransform(tx);
drawMap(g2d, scale);
drawCarpetMap(g2d, scale);
drawZones(g2d, scale);
drawNoGo(g2d, scale);
drawWalls(g2d, scale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ public class RRMapFileParser {
public static final int NO_GO_AREAS = 9;
public static final int VIRTUAL_WALLS = 10;
public static final int BLOCKS = 11;
public static final int MFBZS_AREA = 12;
public static final int MOB_FORBIDDEN_AREA = 12;
public static final int OBSTACLES = 13;
public static final int IGNORED_OBSTACLES = 14;
public static final int OBSTACLES2 = 15;
public static final int IGNORED_OBSTACLES2 = 16;
public static final int CARPET_MAP = 17;
public static final int MOP_PATH = 18;
public static final int CARPET_FORBIDDEN_AREA = 19;

public static final int DIGEST = 1024;
public static final int HEADER = 0x7272;
Expand Down Expand Up @@ -94,6 +96,7 @@ public class RRMapFileParser {
private Map<Integer, ArrayList<int[]>> obstacles = new HashMap<>();
private byte[] blocks = new byte[0];
private int[] carpetMap = {};
private int[] mopPath = {};

private final Logger logger = LoggerFactory.getLogger(RRMapFileParser.class);

Expand Down Expand Up @@ -183,7 +186,8 @@ public RRMapFileParser(byte[] raw) {
}
break;
case NO_GO_AREAS:
case MFBZS_AREA:
case MOB_FORBIDDEN_AREA:
case CARPET_FORBIDDEN_AREA:
int areaPairs = getUInt16(header, 0x08);
ArrayList<float[]> area = new ArrayList<float[]>();
for (int areaPair = 0; areaPair < areaPairs; areaPair++) {
Expand Down Expand Up @@ -258,12 +262,18 @@ public RRMapFileParser(byte[] raw) {
carpetMap[carpetNode] = data[carpetNode] & 0xFF;
}
break;
case MOP_PATH:
mopPath = new int[blockDataLength];
for (int mopNode = 0; mopNode < blockDataLength; mopNode++) {
mopPath[mopNode] = data[mopNode] & 0xFF;
}
break;
case BLOCKS:
int blocksPairs = getUInt16(header, 0x08);
blocks = getBytes(data, 0, blocksPairs);
break;
default:
logger.info("Unknown blocktype (pls report to author)");
logger.info("Unknown blocktype {} (pls report to author)", blocktype);
printBlockDetails = true;
}
if (logger.isTraceEnabled() || printBlockDetails) {
Expand Down Expand Up @@ -335,7 +345,19 @@ public String toString() {
pw.printf("Robo pos:\tX: %.0f\tY: %.0f\tAngle: %d\r\n", getRoboX(), getRoboY(), getRoboA());
pw.printf("Goto:\tX: %.0f\tY: %.0f\r\n", getGotoX(), getGotoY());
for (Entry<Integer, ArrayList<float[]>> area : areas.entrySet()) {
pw.print(area.getKey() == NO_GO_AREAS ? "No Go zones:\t" : "MFBZS zones:\t");
switch (area.getKey()) {
case NO_GO_AREAS:
pw.print("Regular No Go zones:\t");
break;
case MOB_FORBIDDEN_AREA:
pw.print("Mop No Go zones:\t");
break;
case CARPET_FORBIDDEN_AREA:
pw.print("Carpet No Go zones:\t");
break;
default:
pw.print("Unknown type zones:\t");
}
pw.printf("%d\r\n", area.getValue().size());
printAreaDetails(area.getValue(), pw);
}
Expand All @@ -356,6 +378,8 @@ public String toString() {
}
}
pw.println();
pw.printf("Carpet Map:\t%d\r\n", carpetMap.length);
pw.printf("Mop Path:\t%d\r\n", mopPath.length);
pw.close();
return sw.toString();
}
Expand Down Expand Up @@ -506,4 +530,8 @@ public byte[] getBlocks() {
public final int[] getCarpetMap() {
return carpetMap;
}

public final int[] getMopPath() {
return mopPath;
}
}

0 comments on commit 6e0df54

Please sign in to comment.