偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

iPhone應(yīng)用中如何使用三軸感應(yīng)器代碼案例

移動(dòng)開發(fā) iOS
iPhone應(yīng)用中如何使用iPhone三軸感應(yīng)器代碼案例是本文要介紹的內(nèi)容你,主要是來認(rèn)識(shí)并學(xué)習(xí)iphone應(yīng)用中的三軸感應(yīng)器。來考哪詳細(xì)內(nèi)容。

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

iPhone應(yīng)用中如何使用三軸感應(yīng)器代碼案例 

  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);  

小結(jié):iPhone應(yīng)用中如何使用三軸感應(yīng)器代碼案例的內(nèi)容介紹完了,希望通過本文的學(xué)習(xí)能對你有所幫助!

責(zé)任編輯:zhaolei 來源: starming社區(qū)
相關(guān)推薦

2012-07-11 09:21:35

Windows Pho

2011-08-18 16:42:07

iPhone應(yīng)用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ā)抓圖程序

2013-05-21 11:24:07

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

2011-08-17 15:10:21

iPhone開發(fā)Web視圖

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-08 13:50:29

iPhone開發(fā) NSOperatio 多線程

2011-08-10 16:08:02

iPhoneProtocol協(xié)議

2011-08-18 16:03:34

iPhone上傳圖片

2011-08-15 11:23:41

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

2011-08-18 15:40:20

iPhone文本切頁

2011-11-10 10:39:21

蘋果Siri

2010-11-05 13:02:58

內(nèi)存iPhone

2018-07-23 09:27:44

辦公外設(shè)

2011-08-09 09:57:59

iPhone服務(wù)器Socket

2011-08-19 11:10:31

iPhone應(yīng)用
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)