if __name__ == "__main__":
    import cst816, time
    from machine import I2C, Pin
    # Initialize I2C
    i2c = I2C(0, sda=Pin("TOUCH_SDA"), scl=Pin("TOUCH_SCL"), freq=200000)
    devices = i2c.scan()  # Returns a list of connected device addresses
    touch = cst816.CST816(i2c, Pin("TOUCH_INT"))
    if touch.available:
        print("Device found!")
    
        # Check if the touch controller is detected
        dev = touch.get_model_name()
        
        print(dev, "FW Rev:", touch.read_revision())
        if dev:
            while True:
                if not touch._get_irq():
                    point = touch.get_point()
                    gesture = touch.get_gesture()
                    press = touch.get_touch()
                    distance = touch.get_distance()
                    event = touch.get_event()
                    print(
                        "Position: {0},{1} - Gesture: {2} - Pressed? {3} - Distance: {4},{5} - Event: {6}".format(
                            point.x_point,
                            point.y_point,
                            gesture,
                            press,
                            distance.x_dist,
                            distance.y_dist,
                            event,
                        )
                    )
                    time.sleep(0.05)
    else:
        print("Device not found.")
    
    

