自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone應用中如何使用三軸感應器代碼案例

移動開發(fā) iOS
iPhone應用中如何使用iPhone三軸感應器代碼案例是本文要介紹的內容你,主要是來認識并學習iphone應用中的三軸感應器。來考哪詳細內容。

iPhone應用中如何使用iPhone三軸感應器代碼案例是本文要介紹的內容你,主要是來認識并學習iphone應用中的三軸感應器。很多應用里都要用到蘋果iPhone自帶的三軸感應器(加速度傳感器),希望下面這段代碼例子能為您使用iPhone三軸感應器打開思路。如圖所示:

iPhone應用中如何使用三軸感應器代碼案例 

  1. #include <IOKit/IOKitLib.h> 
  2. #include <CoreFoundation/CoreFoundation.h> 
  3.  
  4. typedef struct {} *IOHIDEventSystemRef;  
  5. typedef struct {} *IOHIDEventRef;  
  6. float IOHIDEventGetFloatValue(IOHIDEventRef ref, int param);  
  7.  
  8. void handleHIDEvent(int a, int b, int c, IOHIDEventRef ptr) {  
  9. int type = IOHIDEventGetType(ptr);  
  10. if (type == 12) {  
  11. float x,y,z;  
  12. x = IOHIDEventGetFloatValue(ptr, 0xc0000);  
  13. y = IOHIDEventGetFloatValue(ptr, 0xc0001);  
  14. z = IOHIDEventGetFloatValue(ptr, 0xc0002);  
  15. // do whatever you need to do with the gravity  
  16. ballSetAccel(x, y);  
  17. }  
  18. }  
  19. #define expect(x) if(!x) { printf("failed: %sn", #x); return; }  
  20. void initialize(int hz) {  
  21. mach_port_t master;  
  22. expect(0 == IOMasterPort(MACH_PORT_NULL, &master));  
  23.  
  24. int page = 0xff00usage = 3;  
  25.  
  26. CFNumberRef nums[2];  
  27. CFStringRef keys[2];  
  28. keys[0] = CFStringCreateWithCString(0, "PrimaryUsagePage", 0);  
  29. keys[1] = CFStringCreateWithCString(0, "PrimaryUsage", 0);  
  30. nums[0] = CFNumberCreate(0, kCFNumberSInt32Type, &page);  
  31. nums[1] = CFNumberCreate(0, kCFNumberSInt32Type, &usage);  
  32. CFDictionaryRef dict = CFDictionaryCreate(0, (const void**)keys,  
  33. (const void**)nums, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);  
  34.  expect(dict);  
  35. IOHIDEventSystemRef sys = (IOHIDEventSystemRef) IOHIDEventSystemCreate(0);  
  36. expect(sys);  
  37.  CFArrayRef srvs = (CFArrayRef)IOHIDEventSystemCopyMatchingServices(sys, dict, 0, 0, 0);  
  38. expect(CFArrayGetCount(srvs)==1);  
  39.    
  40. io_registry_entry_t serv = (io_registry_entry_t)CFArrayGetValueAtIndex(srvs, 0);  
  41. expect(serv);  
  42.    
  43. CFStringRef cs = CFStringCreateWithCString(0, "ReportInterval", 0);  
  44. int rv = 1000000/hz;  
  45. CFNumberRef cn = CFNumberCreate(0, kCFNumberSInt32Type, &rv);  
  46.    
  47. int res = IOHIDServiceSetProperty(serv, cs, cn);  
  48. expect(res == 1);  
  49.    
  50. res = IOHIDEventSystemOpen(sys, handleHIDEvent, 0, 0);  
  51. expect(res != 0);  

小結:iPhone應用中如何使用三軸感應器代碼案例的內容介紹完了,希望通過本文的學習能對你有所幫助!

責任編輯:zhaolei 來源: starming社區(qū)
相關推薦

2012-07-11 09:21:35

Windows Pho

2011-08-18 16:42:07

iPhone應用APNS推送

2011-08-15 15:44:46

iPhone開發(fā)PDF

2011-08-18 16:24:44

iPhone開發(fā)圖片

2011-08-16 15:48:37

iPhone開發(fā)抓圖程序

2011-08-17 15:10:21

iPhone開發(fā)Web視圖

2013-05-21 11:24:07

Android游戲開發(fā)Sensor重力感應

2011-08-19 10:05:30

iPhone開發(fā)

2011-08-19 14:34:03

iPhone開發(fā)

2011-08-19 17:02:46

iPhone開發(fā)

2011-08-18 16:03:34

iPhone上傳圖片

2011-08-08 13:50:29

iPhone開發(fā) NSOperatio 多線程

2011-08-10 16:08:02

iPhoneProtocol協(xié)議

2011-08-15 11:23:41

iPhone開發(fā)循環(huán)滾動UIScrollVie

2011-08-18 15:40:20

iPhone文本切頁

2010-11-05 13:02:58

內存iPhone

2012-05-28 15:55:47

XNA 重力感應

2011-11-10 10:39:21

蘋果Siri

2018-07-23 09:27:44

辦公外設

2011-08-09 09:57:59

iPhone服務器Socket
點贊
收藏

51CTO技術棧公眾號