API Reference

adafruit_xteink_x4

CircuitPython helper library to interface with the Xteink X4 eReader

  • Author(s): Liz Clark

Implementation Notes

Software and Dependencies:

class adafruit_xteink_x4.BatteryMonitor(adc_pin=None, divider_multiplier=2.0)

Monitor battery voltage and percentage via an ADC pin with a voltage divider.

Parameters:
  • adc_pin (Pin) – The ADC pin connected to the battery voltage divider. Defaults to board.A0.

  • divider_multiplier (float) – The voltage divider multiplier. Defaults to 2.0.

deinit()

Release the underlying ADC resource.

property millivolts

Battery voltage in millivolts, accounting for the voltage divider.

property percentage

Estimated battery percentage (0-100) using a cubic fit curve for a typical Li-Ion discharge profile.

property volts

Battery voltage in volts.

class adafruit_xteink_x4.InputManager(adc_pin_1=None, adc_pin_2=None, power_pin=None, debounce=0.05)

Manage button input from two ADC channels and a digital power button.

Buttons are read from two ADC pins using resistor-ladder thresholds and a dedicated digital pin for the power button. Call update() once per main-loop iteration to poll and debounce.

Parameters:
  • adc_pin_1 (Pin) – First ADC pin (Back, Confirm, Left, Right). Defaults to board.BUTTON_ADC_1.

  • adc_pin_2 (Pin) – Second ADC pin (Up, Down). Defaults to board.BUTTON_ADC_2.

  • power_pin (Pin) – Digital pin for the power button (active-low). Defaults to board.BUTTON.

  • debounce (float) – Debounce delay in seconds. Defaults to 0.05 (50 ms).

property any_pressed

True if any button was just pressed this update cycle.

property any_released

True if any button was just released this update cycle.

property back_pressed

True if the Back button is currently held.

static button_name(button_index)

Return a human-readable name for a button index.

Parameters:

button_index (int) – A button index constant.

property confirm_pressed

True if the Confirm button is currently held.

property current_state

Bitmask of currently held buttons (after debounce).

deinit()

Release all underlying pin resources.

property down_pressed

True if the Down button is currently held.

property held_time

Duration in seconds a button has been or was held.

is_pressed(button_index)

Return True if the given button is currently held.

Parameters:

button_index (int) – A button index constant (e.g. BTN_BACK).

property left_pressed

True if the Left button is currently held.

property power_button_pressed

True if the power button is currently held.

property pressed_events

Bitmask of buttons that became pressed since the last update().

property released_events

Bitmask of buttons that were released since the last update().

property right_pressed

True if the Right button is currently held.

property up_pressed

True if the Up button is currently held.

update()

Poll buttons, debounce, and compute pressed/released events.

Call this once per main-loop iteration.

was_pressed(button_index)

Return True if the given button was just pressed this cycle.

Parameters:

button_index (int) – A button index constant.

was_released(button_index)

Return True if the given button was just released this cycle.

Parameters:

button_index (int) – A button index constant.