Elcdx.Driver.CursorTracker (elcdx v0.1.1)

View Source

Handles cursor position tracking and calculations for the LCD display.

This module manages the current cursor position and provides functions to update the position based on various operations like printing text, clearing the display, or moving the cursor manually.

Responsibilities

  • Track current cursor position (column, line)
  • Calculate new positions after text printing
  • Handle scrolling vs non-scrolling position calculations
  • Ensure positions stay within display bounds

Summary

Functions

Resets the cursor position to the top-left corner (0, 0).

Sets the cursor to a specific position.

Updates cursor position after printing text.

Functions

reset_position(state)

Resets the cursor position to the top-left corner (0, 0).

Parameters

  • state: The driver state struct

Returns

Updated state with cursor position reset to (0, 0).

set_position(state, column, line)

Sets the cursor to a specific position.

Parameters

  • state: The driver state struct
  • column: Column position (0-based)
  • line: Line position (0-based)

Returns

Updated state with new cursor position.

update_after_print(state, text, opts)

Updates cursor position after printing text.

Since we only support single-line printing without wrapping, the cursor position calculation is simplified. The cursor moves forward by the length of the printed text, but stays within the current line bounds.

Parameters

  • state: The driver state struct
  • text: The text that was printed (newlines are ignored)
  • opts: Options (scroll setting is considered but doesn't affect position)

Returns

Updated state with new cursor position.

Behavior

  • Cursor advances by text length within current line
  • Never moves to next line automatically
  • Stops at end of current line if text is truncated
  • Position reflects actual printed characters only