#!/usr/bin/env python
#
# Microchip Peripheral I/O
#
# <NAME> <<EMAIL>>
# Copyright (C) 2017 Microchip Technology Inc.  All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""
Asks the user to select an input device from a list and then it will print any
input events generated by that device.
"""
import mpio
import sys

if sys.version_info[0] == 3:
    raw_input = input

def main():
    devices = mpio.Input.enumerate()
    print "Available input devices"
    for d in devices:
        print d, "(", mpio.Input.desc(d), ")"

    device = raw_input("Which input name? ")

    i = mpio.Input(device)
    print "Generate events for input", device, "now"
    while True:
        (tv_sec, tv_usec, evtype, code, value) = i.read()
        print "Event type %u, code %u, value: %u, at: %d.%d" % \
            (evtype, code, value, tv_sec, tv_usec)

if __name__ == "__main__":
    if len(sys.argv) > 1:
        print("Usage: ./input1.py")
        sys.exit(1)

    main()

#!/usr/bin/env python
#
# Microchip Peripheral I/O
#
# <NAME> <<EMAIL>>
# Copyright (C) 2017 Microchip Technology Inc.  All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""
Asks the user to select an input device from a list and then it will print any
input events generated by that device.
"""
import mpio
import sys

if sys.version_info[0] == 3:
    raw_input = input

def main():
    devices = mpio.Input.enumerate()
    print "Available input devices"
    for d in devices:
        print d, "(", mpio.Input.desc(d), ")"

    device = raw_input("Which input name? ")

    i = mpio.Input(device)
    print "Generate events for input", device, "now"
    while True:
        (tv_sec, tv_usec, evtype, code, value) = i.read()
        print "Event type %u, code %u, value: %u, at: %d.%d" % \
            (evtype, code, value, tv_sec, tv_usec)

if __name__ == "__main__":
    if len(sys.argv) > 1:
        print("Usage: ./input1.py")
        sys.exit(1)

    main()

#!/usr/bin/env python # # Microchip Peripheral I/O # # <NAME> <<EMAIL>> # Copyright (C) 2017 Microchip Technology Inc.  All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # #     http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Asks the user to select an input device from a list and then it will print any input events generated by that device.