monitor mouse status on Mac OSX - objective-c

I wanted to monitor mouse status(connect/disconnect) in system wide on OS X. I checked the Apple developer library, but cannot find any clues.
My goal is to monitor both USB and Bluetooth mouse. Any API that I could use?
Thank you very much.
--N

You can use I/O Kit's HID manager API to find out when new HIDs (Human Interface Devices) appear in the system, or are disconnected from it. This is a complex topic in itself, so I won't throw random code at you - just go read Accessing a HID Device (in particular the Matching HID Devices and Registering for Unplug Notifications sections). Example code is included.

Related

Device driver for USB lamp and fans

I have a USB lamp,which just switches on when plugged into a USB port. I connected it to my computer and ran lsusb, but could not find the device. How does the OS handle these devices? Are the USB power pins always powered with 5V, or does it get powered when the OS detects a device? If the OS detects a device and then supplies power to the USB slot, how do I locate the drivers associated with the device?
The device is something similar to the device listed here:
https://www.amazon.in/Codered-Portable-Flexible-Light-Colors/dp/B078N9DQ8B
From the image and description below, the product in question looks like a "dumb" device to me. By dumb i mean it only uses the +5V and GND lines from the USB connector. The D+/D- used to communicate are not connected and therefore no drivers are required/applicable. Given USB is a fairly complex and comprehensive protocol, you could probably pick up a copy of USB Complete: the first few chapters should get you started in the right direction.
I have also found this helpful.
BTW, external links (esp amazon products) tend to die, so upload and include a picture (when you have the reputation points) otherwise the context of the question can be lost.

What's the best way to determine if a HID device driver can be written in user space on OSX?

I need to write a number of drivers for both HID USB devices as well as some old serial devices. The drivers are to pull data off the device and then send the data over to an application that then consumes it. Since the Apple Docs mention that a lot of USB and HID communication can be done from the user space I had assumed that I would not need to write a kernel extension, at least not for the HID devices. Could some one tell me a more solid way to determine this?
Thanks!
If you're writing a single application that must talk to one or more USB HID devices you may well find you can just access the devices straight from the application using the application-level USB APIs.
A kernel driver would be more for something like a networking or mass storage device that needed to integrate with the kernel to be be available to multiple applications.
This Apple document Common QA and Roadmap for USB Software Development on Mac OS X goes into some detail on the matter and links to example code too.

How to write usb touchscreen driver kext in os x 10.9?

I want to write a usb touchscreen kext for usb touch screen .
I have read the Kernel Extension Programming Topics and the I/O Kit Fundamentals etc,
My question is,
1 . how to get the input report messages from touch screen ?
2 . how to post the coordinate info to system ?
I have no idea, anybody help?
It depends on the hardware; moreover, this question is quite broad - you'll need to be more specific in your question to get more specific answers. I'll try to provide a broad overview:
A touchscreen has 2 parts:
Output: showing the image coming from the computer on the display
Input: the touch events to feed back into the computer
As you haven't asked about (1) at all, I assume your device just plugs into a display port on the Mac and is already displaying correctly. If not, you'll want to look into the IOFramebuffer API.
For (2) - Pretty much all USB input devices are HID devices of some form. If you're new to HID in general, you'll probably want to read and understand the USB HID specification and related documentation as you'll be using that information throughout.
OSX already comes with comprehensive support for the standard HID device classes such as keyboards, mice, touchpads, graphics tablets, etc. If your device claims to be any kind of HID device, OSX should already be detecting it and attaching its generic HID driver to it. You should see a IOUSBHIDDriver instance in the I/O Registry (eg. using Apple's IORegistryExplorer tool, or ioreg on the command line).
I'd also expect your device to conform to HID's absolute pointing device profile, so at least single touches should already be working properly. If it's a multitouch device, or you need other extra features, you'll probably want to implement a IOUSBHIDDriver subclass that generates or converts the necessary multitouch events.
If your device for some reason isn't already a HID USB device, you'll need to write a custom USB driver for it, and convert the events coming from it into HID events, as the HID events are passed directly into userspace and processed there. You can actually write USB drivers and generate HID events from userspace, so you might be able to avoid writing any kernel code at all if you prefer.
Apple provides some documentation on HID:
The HID Class Device Interface Guide covers some general concepts and the userspace interfaces.
The Kernel Framework Reference has API documentation for the various IOHID* classes in the kernel.
If you're going to be writing your own kernel HID device driver, your best bet is probably the IOHIDFamily source code. You can probably also find some open source examples around the web.
Apple's USB mailing lists is probably also worth checking, both for the archives and if you have questions. The darwin-kernel and darwin-drivers lists are also relevant.

How to catch bluetooth peripheral's command

I want to catch commands from bluetooth peripheral in iOS.
Could anyone help me out?
There are a few ways of doing Bluetooth on iOS, and different ones have different methods:
An accessory that's part of the Made for iPhone program (see the answer to this question if you want to know what that entails)
A device that uses Bluetooth 4.0 Low Energy mode
Talking to another iPhone with GameKit
A device using one of the Bluetooth profiles Apple support natively: Hands-free profile, headset profile, A2DP, AVRCP, etc.
To answer those in order:
If you're part of the Made for iPhone program, you'll already know where to find this information, and it's not public: ask your contact at Apple for help.
If your device uses Bluetooth 4.0 Low Energy, look into the Core Bluetooth framework.
If you're trying to get two iPhones talking together, look into GameKit.
If you're working with a device that uses an Apple provided profile, you shouldn't have to do anything, it'll just work. For example, an A2DP device will stream audio played from the phone without needing programmer intervention. You can do a few things to control it: there's a Core Audio function somewhere that lets you choose whether to send audio to a Bluetooth device. If you're trying to support AVRCP, look into handling remote control events.
If your device doesn't fall into any of the above categories, you're probably out of luck and can't use it with iOS.

Find available USB devices Mac OS X

I was wondering if there was any way to see if a usb device (only specific ones) are plugged in and unplugged using objective c. All I need to know is if a device has been plugged in, such as an iPhone/iPod Touch. If not, any other device will work
Thanks
The information in Apple's USB Device Interface Guide (see the "USB Devices on Mac OS X" and "Finding USB Devices and Interfaces" sections) and Accessing Hardware From Applications (see the "Finding and Accessing Devices" section) docs should put you on the right track.
That said, I suspect you'll need to delve below the shiny Cocoa surface into the world of I/O Kit functions and (potentially) POSIX.