Upcoming SlideShare
×

# Tilting Google Maps and MissileLauncher

6,258 views
6,150 views

Published on

Gmaps and MissileLauncher hacking talk in OSDC.tw

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
6,258
On SlideShare
0
From Embeds
0
Number of Embeds
854
Actions
Shares
0
0
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Tilting Google Maps and MissileLauncher

1. 1. 傾斜 Google 地圖 ＆ 火箭発射器 宮川達彦 [email_address] Six Apart, Ltd. / 渋谷 Perl 推廣組 osdc.tw 台北 2007/04/15
2. 3. <ul><li>USB MissileLaunchers </li></ul><ul><li>by Yappo </li></ul>
3. 4. <ul><li>Now mashing up </li></ul><ul><li>With ThinkPad Tilt! </li></ul>
4. 5. <ul><li>( 公開表演 ) </li></ul><ul><li>Live Demo </li></ul>
5. 6. <ul><li>極好 ! </li></ul><ul><li>sugoi! </li></ul>
6. 7. <ul><li>如何實現 </li></ul><ul><li>How can you do that? </li></ul>
7. 9. <ul><li>發現了 2 個範例 </li></ul><ul><li>Found 2 examples: </li></ul><ul><li>C++ / Ruby </li></ul>
8. 10. C++ if( !DeviceIoControl( hFile, 0x733fc, NULL, 0, // via IOCTL(0x733fc) (void *)&AccelerometerData, 0x24, &ulRead, NULL)) throw &quot;Failed to DeviceIoControl&quot;; X = AccelerometerData.x0 + OffsetX; Y = AccelerometerData.y0 + OffsetY;
9. 11. Ruby device = Device.new ' ＼＼＼＼ . ＼＼ ShockMgr' device.open values = device.io(command, result_size).unpack(&quot;x4s*&quot;) cx = values[3] cy = values[2]
10. 12. Perl 移植 use Win32API::File; my \$file = createFile(&quot;//./ShockMgr&quot;, &quot;r ke&quot;) or die &quot;Can't get ShockMgr device&quot;; DeviceIoControl(\$file, 0x733fc, [], 0, my(\$buf), 0x24, my(\$bytes), []); my @data = unpack &quot;x4s*&quot;, \$buf;
11. 13. tilt-missile.pl (1/3) use Time::HiRes qw(sleep); use Win32::API; use Win32API::File qw(:ALL); use Win32::OLE; sub get_pos { my \$file = createFile(&quot;//./ShockMgr&quot;, &quot;r ke&quot;) or die &quot;Can't get ShockMgr device&quot;; DeviceIoControl(\$file, 0x733fc, [], 0, my(\$buf), 0x24, my(\$bytes), []); my @data = unpack &quot;x4s*&quot;, \$buf; return @data; }
12. 14. tilt-missile.pl (2/3) my @pos = get_pos; my(\$base_x, \$base_y) = @pos[3, 2]; while (my @pos = get_pos) { my \$ax = (\$pos[1] - \$base_x) / 30; my \$ay = (\$pos[0] - \$base_y) / 30; my \$command = detect_command(\$ax, \$ay); system(&quot;ctlmissile \$command&quot;) if \$command; }
13. 15. tilt-missile.pl (3/3) sub detect_command { my(\$ax, \$ay) = @_; if (abs(\$ax) >= 180 || abs(\$ay) >= 180) { return &quot;fire&quot;; } elsif (\$ax >= 80) { return &quot;right&quot;; } … }
14. 16. <ul><li>(Google 地圖実演 ) </li></ul>
15. 17. <ul><li>整合 Google 地圖 </li></ul>
16. 18. <ul><li>困難原因 : </li></ul><ul><li>Google 地圖 API </li></ul><ul><li>= JavaScript </li></ul>
17. 19. <ul><li>JavaScript </li></ul><ul><li><-> Win32 Perl </li></ul><ul><li>能成功嗎？ </li></ul>
18. 20. <ul><li>Active X ™ </li></ul>
19. 21. gmaps.html (1/2) <script language=&quot;JavaScript&quot; > function load() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById(&quot;map&quot;)); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); if (debug) document.getElementById('log').style.visibility = 'visible'; GEvent.addListener(map, &quot;dragstart&quot;, function() { dragging = 1 }); GEvent.addListener(map, &quot;dragend&quot;, function() { var center = map.getCenter(); x = center.x; y = center.y; dragging = 0; }); … map.setCenter(new GLatLng(y, x), 14); base = get_pos(1). split(/,/); </script>
20. 22. gmaps.html (2/2) <script language=&quot;PerlScript&quot; > use Win32API::File qw(:ALL); sub get_pos { my \$base = shift; my \$file = createFile(&quot;//./ShockMgr&quot;, &quot;r ke&quot;) or die &quot;Can't get ShockMgr device&quot;; DeviceIoControl(\$file, 0x733fc, [], 0, my(\$buf), 0x24, my(\$bytes), []); my @data = unpack &quot;x4s*&quot;, \$buf; return join &quot;,&quot;, (\$base ? @data[3, 2] : @data[1, 0]); } </script>