Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added listeners to commands to listen for when it completes. #1809

Merged
merged 2 commits into from
Mar 17, 2022

Conversation

breiler
Copy link
Collaborator

@breiler breiler commented Feb 20, 2022

I started working on a new controller implementation and found a need for listening to if a command was completed.
This could be done using a UGSEventListener and listening for a CommandEvent in the application, but not from the controller. From the controller we have access to the ControllerLisener but would require to implement a rather large listener interface.

I propose to add a listener to the GcodeCommand, this would it make it possible to execute a command and wait for it to be completed:

try {
  GcodeCommand command = new GcodeCommand("G0 X10 Y10");
  ControllerUtils.sendAndWaitForCompletion(controller, command, 1000); // Wait max 1000ms for the command to complete
  if (command.isOk()) {
    // Do something with the response
  }
} catch (RuntimeException e) {
  // The command has timed out
}

@breiler breiler requested a review from winder February 20, 2022 07:07
@codecov-commenter
Copy link

Codecov Report

Merging #1809 (b517f8b) into master (ff31d88) will increase coverage by 0.13%.
The diff coverage is 74.57%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1809      +/-   ##
============================================
+ Coverage     18.20%   18.33%   +0.13%     
- Complexity     1914     1938      +24     
============================================
  Files           698      699       +1     
  Lines         29423    29466      +43     
  Branches       2314     2318       +4     
============================================
+ Hits           5355     5403      +48     
+ Misses        23618    23613       -5     
  Partials        450      450              
Impacted Files Coverage Δ
...om/willwinder/universalgcodesender/TinyGUtils.java 65.21% <0.00%> (-0.36%) ⬇️
...inder/universalgcodesender/AbstractController.java 65.41% <66.66%> (-0.26%) ⬇️
...llwinder/universalgcodesender/TinyGController.java 44.50% <66.66%> (+1.64%) ⬆️
...inder/universalgcodesender/types/GcodeCommand.java 74.28% <72.00%> (-5.03%) ⬇️
...er/universalgcodesender/utils/ControllerUtils.java 76.92% <76.92%> (ø)
...illwinder/universalgcodesender/GrblController.java 55.35% <100.00%> (+0.26%) ⬆️
...nder/universalgcodesender/GrblEsp32Controller.java 93.93% <100.00%> (+10.60%) ⬆️
...com/willwinder/universalgcodesender/GrblUtils.java 72.50% <100.00%> (+0.10%) ⬆️
...inder/universalgcodesender/SmoothieController.java 11.26% <100.00%> (+11.26%) ⬆️
...der/universalgcodesender/ConnectionWatchTimer.java 54.54% <0.00%> (-9.10%) ⬇️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ff31d88...b517f8b. Read the comment docs.

@breiler breiler merged commit 63f4af8 into winder:master Mar 17, 2022
@breiler breiler deleted the feature/command-listener branch January 23, 2023 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants