# The target angle offset used to reorient the sensor
# (heading, roll, pitch)
target_angle_offset = (0, 0, 0)

# The project's main while loop
while True:
    # Get the Euler angle values from the sensor
    # The Euler angle limits are: +180 to -180 pitch, +360 to -360 heading, +90 to -90 roll
    sensor_euler = sensor.euler
    print(f"Euler angle: {sensor_euler}")
    # Adjust the Euler angle values with the target_angle_offset
    heading, roll, pitch = [position - target_angle_offset[idx] for idx, position in enumerate(sensor_euler)]

    # Scale the heading for horizontal movement range
    horizontal_mov = int(map_range(heading, -20, 20, -30, 30))
    print(f"mouse x: {horizontal_mov}")

    # Scale the roll for vertical movement range
    vertical_mov = int(map_range(roll, -25, 25, 30, 30))
    print(f"mouse y: {vertical_mov}")

    # Translate to stuff needed for HID
    mouse.move(x=horizontal_mov)
    mouse.move(y=vertical_mov)
    
    # Check the "reorient" button was pressed
    if reorientation_button:
        print(f"Reorient the sensor")
        # Use the current Euler angle values to reorient the target angle
        target_angle_offset = [angle for angle in sensor_euler]