ddetommaso / TobiiGlassesPyController

Tobii Pro Glasses 2 Python controller
GNU General Public License v3.0
56 stars 28 forks source link

Can't input project's name #7

Closed leeweizhe1993 closed 5 years ago

leeweizhe1993 commented 5 years ago

Glasses Firmware Version: 1.25.4-citronkola-0 Headunit version: 0.0.62 Python: Python 3.5.6 :: Anaconda, Inc. IDE: Jupyter lab with Ipykernel 5.1.0

Copied from demo code:

import time
from tobiiglassesctrl.controller import TobiiGlassesController

if hasattr(__builtins__, 'raw_input'):
      input=raw_input

def main():

    tobiiglasses = TobiiGlassesController("192.168.71.50")
    print(tobiiglasses.get_battery_info())
    print(tobiiglasses.get_storage_info())

    if tobiiglasses.is_recording():
        rec_id = tobiiglasses.get_current_recording_id()
        tobiiglasses.stop_recording(rec_id)

    project_name = input("Please insert the project's name: ")
    project_id = tobiiglasses.create_project(project_name)

    participant_name = input("Please insert the participant's name: ")
    participant_id = tobiiglasses.create_participant(project_id, participant_name)

    calibration_id = tobiiglasses.create_calibration(project_id, participant_id)
    input("Put the calibration marker in front of the user, then press enter to calibrate")
    tobiiglasses.start_calibration(calibration_id)

    res = tobiiglasses.wait_until_calibration_is_done(calibration_id)

    if res is False:
        print("Calibration failed!")
        exit(1)

    recording_id = tobiiglasses.create_recording(participant_id)
    print("Important! The recording will be stored in the SD folder projects/%s/recordings/%s" % (project_id, recording_id))
    input("Press enter to start recording")
    tobiiglasses.start_recording(recording_id)
    tobiiglasses.send_custom_event("start_recording", "Start of the recording ")
    input("Press enter to stop recording")
    tobiiglasses.send_custom_event("stop_recording", "Stop of the recording " + str(recording_id))
    tobiiglasses.stop_recording(recording_id)

    if res is False:
        print("Recording failed!")
        exit(1)

if __name__ == '__main__':
    main()

Error:

[DEBUG]: Connecting to the Tobii Pro Glasses 2 ...
[DEBUG]: Tobii Pro Glasses 2 successful connected!
Battery info = [ Level: 86.00 % - Remaining Time: 5160.00 s ]
Storage info = [ Remaining Time: 5160.00 s ]
Please insert the project's name:  Li
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-19-4597c1eb8694> in <module>
     44 
     45 if __name__ == '__main__':
---> 46     main()

<ipython-input-19-4597c1eb8694> in main()
     14 
     15         project_name = input("Please insert the project's name: ")
---> 16         project_id = tobiiglasses.create_project(project_name)
     17 
     18         participant_name = input("Please insert the participant's name: ")

D:\Miniconda3\envs\python35\lib\site-packages\tobiiglassesctrl\controller.py in create_project(self, projectname)
    320                 if project_id is None:
    321             data = {'pr_info' : {'CreationDate': self.__get_current_datetime__(),
--> 322                                                                  'EagleId':  str(uuid.uuid5(uuid.NAMESPACE_DNS, projectname.encode('utf-8'))),
    323                                  'Name': projectname},
    324                     'pr_created': self.__get_current_datetime__() }

D:\Miniconda3\envs\python35\lib\uuid.py in uuid5(namespace, name)
    606     """Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
    607     from hashlib import sha1
--> 608     hash = sha1(namespace.bytes + bytes(name, "utf-8")).digest()
    609     return UUID(bytes=hash[:16], version=5)
    610 

TypeError: encoding without a string argument
ddetommaso commented 5 years ago

Hi @leeweizhe1993,

thank you for reporting your issue. I think this is due to different behaviors of encode methods between Python2 and 3.

Now should be fixed in latest master branch! Best,