Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use Raw Input Mode in Linux #17

Open
omair-khalid opened this issue Dec 2, 2021 · 2 comments
Open

Can't use Raw Input Mode in Linux #17

omair-khalid opened this issue Dec 2, 2021 · 2 comments

Comments

@omair-khalid
Copy link

Getting data in raw mode only prints for 3-4 times before stopping. At this point, the Tap starts blinking at a fast rate (as if it is disconnected from the computer). The Tap becomes unreachable after that.

Please be assured that:

  • The tap is Developer Mode,
  • The tap has been re-paired after turning on the Developer Mode

The code is below and here is the log log_dev_raw_linux_python.txt

Will be grateful for the help.

import os
import datetime
import time

from tapsdk import TapSDK, TapInputMode
from tapsdk.models import AirGestures

import asyncio
import logging
from bleak import _logger as logger


def notification_handler(sender, data):
    """Simple notification handler which prints the data received."""
    print("{0}: {1}".format(sender, data))


def OnMouseModeChange(identifier, mouse_mode):
    # print(identifier + " changed to mode " + str(mouse_mode))
    print(str(time.strftime("%H:%M:%S", time.localtime())) + " changed to mode " + str(mouse_mode))



def OnTapped(identifier, tapcode):
    # print(identifier + " tapped " + str(tapcode))
    print(str(time.strftime("%H:%M:%S", time.localtime())) + " tapped " + str(tapcode))


def OnGesture(identifier, gesture):
    # print(identifier + " gesture " + str(AirGestures(gesture)))
    print(str(time.strftime("%H:%M:%S", time.localtime())) + " gesture " + str(AirGestures(gesture)))


def OnTapConnected(self, identifier, name, fw):
    # print(identifier + " Tap: " + str(name), " FW Version: ", fw)    
    # self.set_input_mode(TapInputMode("raw"))
    
    print(str(time.strftime("%H:%M:%S", time.localtime())) + " Tap: " + str(name), " FW Version: ", fw)


def OnTapDisconnected(self, identifier):
    # print(identifier + " Tap: " + identifier + " disconnected")
    print(str(time.strftime("%H:%M:%S", time.localtime())) + " Tap: " + identifier + " disconnected")


def OnMoused(identifier, vx, vy, isMouse):
    # print(identifier + " mouse movement: %d, %d, %d" % (vx, vy, isMouse))
    print(str(time.strftime("%H:%M:%S", time.localtime())) + " mouse movement: %d, %d, %d" % (vx, vy, isMouse))


def OnRawData(identifier, packets):
    imu_msg = [m for m in packets if m["type"] == "imu"][0]
    if len(imu_msg) > 0:
        OnRawData.cnt += 1
        if OnRawData.cnt == 10:
            OnRawData.cnt = 0
            logger.info(identifier + " raw imu : " + str(imu_msg["ts"]))
    print(identifier + " - raw data received: " + str(packets))
    for m in packets:
        if m["type"] == "imu":
            # print("imu")
            OnRawData.imu_cnt += 1
            if OnRawData.imu_cnt == 208:
                OnRawData.imu_cnt = 0
                print("imu, " + str(time.time()) + ", " + str(m["payload"][2::3]))
        if m["type"] == "accl":
            # print("accl")
            OnRawData.accl_cnt += 1
            if OnRawData.accl_cnt == 200:
                OnRawData.accl_cnt = 0
                print("accl, " + str(time.time()) + ", " + str(m["payload"][2::3]))
    
OnRawData.imu_cnt = 0
OnRawData.accl_cnt = 0
OnRawData.cnt = 0

async def pollplease(client):
    while True:
        print(client.input_mode.mode)
        await asyncio.sleep(3)

async def run(loop=None, debug=False):
    
    st = time.localtime()
    start_time = time.strftime("%H:%M:%S", st)
    stt = datetime.datetime.now()
    if debug:
        import sys

        loop.set_debug(True)
        h = logging.StreamHandler(sys.stdout)
        h.setLevel(logging.WARNING)
        logger.addHandler(h)

    client = TapSDK(None, loop)
    if not await client.client.connect_retrieved():
        logger.error("Failed to connect the the Device.")
        return

    logger.info("Connected to {}".format(client.client.address))

    await client.set_input_mode(TapInputMode("raw",[2, 1, 4]))
    
    time.sleep(3)
    # await client.set_input_mode(TapInputMode("controller"))

    print("awake")
    print(client.input_mode.mode)

    # await client.register_air_gesture_events(OnGesture)
    # await client.register_tap_events(OnTapped)
    await client.register_raw_data_events(OnRawData)
    # await client.register_mouse_events(OnMoused)
    # await client.register_air_gesture_state_events(OnMouseModeChange)    
    # logger.info("Changing to text mode")
    # await client.set_input_mode(TapInputMode("text"))
    # await asyncio.sleep(30))
    # logger.info("Changing to raw mode")nn
    # await client.set_input_mode(TapInputMode("raw"))a
    # await client.send_vibration_sequence([100, 200, 300, 400, 500])
    # await pollplease(client)

    await asyncio.sleep(60.0, loop=loop)


    print ("finished")
    et = time.localtime()
    ett = datetime.datetime.now()
    end_time = time.strftime("%H:%M:%S", et)
    print("start time:" + start_time)
    print("end time:" + end_time)
    tt = ett - stt


    print(tt)
    print(client.input_mode.mode)
    
    await client.set_input_mode(TapInputMode("controller"))


if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    # loop.run_until_complete(run(loop, True))
    loop.run_until_complete(run(loop, True))

@ilouzl
Copy link
Contributor

ilouzl commented Jan 12, 2022

Not sure whats could be the issue here. It doesn't happen on our setup...
The linux backend was contributed by the community (#3) and might be unstable in some cases.

@omair-khalid
Copy link
Author

omair-khalid commented Jan 12, 2022

@ilouzl Thanks for the reply.

Could you please share your setup details? I can try to replicate those.

My setup is the following:

  • Operating System: Ubuntu 18.04.6 LTS
  • Kernel: Linux 5.4.0-92-generic
  • BlueZ version 5.62
  • Tap Strap 2 software version: 2.6.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants