From 0348b972995b8406898246bca7d0a1bb3095a51a Mon Sep 17 00:00:00 2001 From: Simon Bernard Date: Wed, 5 Feb 2020 12:08:57 +0100 Subject: [PATCH] Improve location (wasd) commands. --- .../leshan/client/demo/LeshanClientDemo.java | 13 +++++++++++-- .../org/eclipse/leshan/client/demo/MyLocation.java | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/leshan-client-demo/src/main/java/org/eclipse/leshan/client/demo/LeshanClientDemo.java b/leshan-client-demo/src/main/java/org/eclipse/leshan/client/demo/LeshanClientDemo.java index fd8acd7fc8..27a19dab48 100644 --- a/leshan-client-demo/src/main/java/org/eclipse/leshan/client/demo/LeshanClientDemo.java +++ b/leshan-client-demo/src/main/java/org/eclipse/leshan/client/demo/LeshanClientDemo.java @@ -465,7 +465,13 @@ public void objectAdded(LwM2mObjectEnabler object) { commandsHelp.append(System.lineSeparator()); commandsHelp.append(" - delete : to disable a new object."); commandsHelp.append(System.lineSeparator()); - commandsHelp.append(" - 'w','a','s','d' : to change reported Location."); + commandsHelp.append(" - w : to move to North."); + commandsHelp.append(System.lineSeparator()); + commandsHelp.append(" - a : to move to East."); + commandsHelp.append(System.lineSeparator()); + commandsHelp.append(" - s : to move to South."); + commandsHelp.append(System.lineSeparator()); + commandsHelp.append(" - d : to move to West."); commandsHelp.append(System.lineSeparator()); LOG.info(commandsHelp.toString()); @@ -482,6 +488,7 @@ public void run() { // Change the location through the Console try (Scanner scanner = new Scanner(System.in)) { + List wasdCommands = Arrays.asList('w', 'a', 's', 'd'); while (scanner.hasNext()) { String command = scanner.next(); if (command.startsWith("create")) { @@ -518,8 +525,10 @@ public void run() { scanner.next(); LOG.info("\"Invalid syntax, must be an integer : delete "); } - } else { + } else if (command.length() == 1 && wasdCommands.contains(command.charAt(0))) { locationInstance.moveLocation(command); + } else { + LOG.info("Unknown command '{}'", command); } } } diff --git a/leshan-client-demo/src/main/java/org/eclipse/leshan/client/demo/MyLocation.java b/leshan-client-demo/src/main/java/org/eclipse/leshan/client/demo/MyLocation.java index 58ca5dcb2f..b015f124f8 100644 --- a/leshan-client-demo/src/main/java/org/eclipse/leshan/client/demo/MyLocation.java +++ b/leshan-client-demo/src/main/java/org/eclipse/leshan/client/demo/MyLocation.java @@ -62,15 +62,19 @@ public void moveLocation(String nextMove) { switch (nextMove.charAt(0)) { case 'w': moveLatitude(1.0f); + LOG.info("Move to North {}/{}", getLatitude(), getLongitude()); break; case 'a': moveLongitude(-1.0f); + LOG.info("Move to East {}/{}", getLatitude(), getLongitude()); break; case 's': moveLatitude(-1.0f); + LOG.info("Move to South {}/{}", getLatitude(), getLongitude()); break; case 'd': moveLongitude(1.0f); + LOG.info("Move to West {}/{}", getLatitude(), getLongitude()); break; } }