Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/jiecang/height.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (j *Jiecang) GoToHeight(ctx context.Context, height uint8) error {
j.mu.RUnlock()

if currentHeight == height {
fmt.Printf("\rHeight: %d cm\n", currentHeight)
break
}

Expand All @@ -78,9 +79,10 @@ func (j *Jiecang) GoToHeight(ctx context.Context, height uint8) error {
if err := j.sendCommand(commands["stop"]); err != nil {
return fmt.Errorf("failed to send stop command: %w", err)
}
fmt.Printf("Operation cancelled at height %d cm\n", currentHeight)
fmt.Printf("\nOperation cancelled at height %d cm\n", currentHeight)
return nil
case <-ticker.C:
fmt.Printf("\rHeight: %d cm", currentHeight)
if err := j.sendCommand(command); err != nil {
return fmt.Errorf("failed to send goto command: %w", err)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/jiecang/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ func (j *Jiecang) GoToMemory(ctx context.Context, memoryNum int) error {
j.mu.RUnlock()

if currentHeight == targetHeight {
fmt.Printf("\rHeight: %d cm\n", currentHeight)
break
}

select {
case <-ctx.Done():
// Context cancelled, return
fmt.Printf("Operation cancelled at height %d cm\n", currentHeight)
fmt.Printf("\nOperation cancelled at height %d cm\n", currentHeight)
return nil
case <-ticker.C:
fmt.Printf("\rHeight: %d cm", currentHeight)
if err := j.sendCommand(commands[commandKey]); err != nil {
return fmt.Errorf("failed to send goto memory%d command: %w", memoryNum, err)
}
Expand Down
Loading