<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>引路蜂移动软件</title>
	<atom:link href="http://www.imobilebbs.com/wordpress/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.imobilebbs.com/wordpress</link>
	<description>Java ME,Blackberry,Android, iPhone,Windows Phone,MonoTouch, .Net Framework 手机软件开发</description>
	<lastBuildDate>Fri, 18 May 2012 19:49:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Android ADK USB 通信简单示例 点亮关闭LED</title>
		<link>http://www.imobilebbs.com/wordpress/?p=3063</link>
		<comments>http://www.imobilebbs.com/wordpress/?p=3063#comments</comments>
		<pubDate>Mon, 14 May 2012 05:03:08 +0000</pubDate>
		<dc:creator>guidebee</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[ADK]]></category>

		<guid isPermaLink="false">http://www.imobilebbs.com/wordpress/?p=3063</guid>
		<description><![CDATA[前面Android ADK 编程简介 介绍了ADK编程的一般步骤，这里给出一个简单的实例说明Android手机如果通过USB端口来控制LED。 所使用的Arduino 板子为Freetronics 的 EtherTen ,就一红一绿LED连接到7，8口上。如下图所示： 参考DemoKit的 Arudino 代码，为LED 驱动编写如下代码： 编写一个简单的Android应用，包含四个按钮，如下： 这里设计一个帮助类ArduinoHelper,用于和Arduino板子USB通信，这个类可以和任意的Activity绑定，因此很容易应用到你自己的代码中。参见代码下载。 有了ArduinoHelper， Android应用和Arduino板子通信就非常简单，在OnCreate 中创建ArudinoHelp 的实例， 在onResume和onDestroy 方法中调用ArduinoHelper 的对于的方法： 代码下载 &#160; &#160;]]></description>
			<content:encoded><![CDATA[<p>前面<a href="http://www.imobilebbs.com/wordpress/?p=2994">Android ADK 编程简介</a> 介绍了ADK编程的一般步骤，这里给出一个简单的实例说明Android手机如果通过USB端口来控制LED。</p>
<p>所使用的Arduino 板子为<a href="http://www.freetronics.com/products/etherten">Freetronics 的 EtherTen</a> ,就一红一绿LED连接到7，8口上。如下图所示：</p>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/05/20120514001.png"><img class="aligncenter size-full wp-image-3064" title="20120514001" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/05/20120514001.png" alt="" width="640" height="480" /></a>参考DemoKit的 Arudino 代码，为LED 驱动编写如下代码：</p>
<pre class="brush: cpp; title: ; notranslate">
#include &lt;avrpins.h&gt;
#include &lt;max3421e.h&gt;
#include &lt;usbhost.h&gt;
#include &lt;usb_ch9.h&gt;
#include &lt;Usb.h&gt;
#include &lt;usbhub.h&gt;
#include &lt;avr/pgmspace.h&gt;
#include &lt;address.h&gt;

#include &lt;adk.h&gt;

#include &lt;printhex.h&gt;
#include &lt;message.h&gt;
#include &lt;hexdump.h&gt;
#include &lt;parsetools.h&gt;

USB Usb;
USBHub hub0(&amp;Usb);
USBHub hub1(&amp;Usb);
ADK adk(&amp;Usb,&quot;Guidebee Pty Ltd.&quot;,
&quot;LedDemoKit&quot;,
&quot;DemoKit Arduino Board&quot;,
&quot;1.0&quot;,
&quot;http://www.imobilebbs.com&quot;,
&quot;0000000012345678&quot;);
uint8_t  b, b1;

#define  START_MOTOR               8
#define  STOP_MOTOR                7

#define  ERROR_INDICATOR        13

void setup();
void loop();

void init_leds()
{
pinMode(START_MOTOR, OUTPUT);
pinMode(STOP_MOTOR, OUTPUT);
digitalWrite(START_MOTOR, LOW);
digitalWrite(STOP_MOTOR, LOW);
}

void setup()
{
Serial.begin(115200);
Serial.println(&quot;\r\nADK demo start&quot;);

if (Usb.Init() == -1) {
Serial.println(&quot;OSCOKIRQ failed to assert&quot;);
while(1); //halt
}//if (Usb.Init() == -1...

init_leds();

}

void loop()
{
uint8_t rcode;
uint8_t msg[3] = { 0x00 };
Usb.Task();

if( adk.isReady() == false ) {
digitalWrite(ERROR_INDICATOR, HIGH);
return;
}else{
digitalWrite(ERROR_INDICATOR, LOW);
}
uint16_t len = sizeof(msg);
rcode = adk.RcvData(&amp;len, msg);

if(len &gt; 0) {
USBTRACE(&quot;\r\nData Packet.&quot;);
// assumes only one command per packet
if (msg[0] == 0x2) {
switch( msg[1] ) {
case 0:
USBTRACE(&quot;LED 1\r\n.&quot;);
if(msg[2]&gt;128){
digitalWrite(START_MOTOR, HIGH);
} else{
digitalWrite(START_MOTOR, LOW);
}
break;
case 1:
USBTRACE(&quot;LED 2\r\n.&quot;);
if(msg[2]&gt;128){
digitalWrite(STOP_MOTOR, HIGH);
} else{
digitalWrite(STOP_MOTOR, LOW);
}
break;
}//switch( msg[1]...
}
}//if( len &gt; 0...

msg[0] = 0x1;
delay( 10 );
}
</pre>
<p>编写一个简单的Android应用，包含四个按钮，如下：</p>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/05/20120514002.png"><img class="aligncenter size-full wp-image-3065" title="20120514002" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/05/20120514002.png" alt="" width="480" height="800" /></a>这里设计一个帮助类ArduinoHelper,用于和Arduino板子USB通信，这个类可以和任意的Activity绑定，因此很容易应用到你自己的代码中。参见代码下载。</p>
<p>有了ArduinoHelper， Android应用和Arduino板子通信就非常简单，在OnCreate 中创建ArudinoHelp 的实例， 在onResume和onDestroy 方法中调用ArduinoHelper 的对于的方法：</p>
<pre class="brush: java; title: ; notranslate">
public class ArduinoLedDemoActivity extends Activity {
/** Called when the activity is first created. */

protected ArduinoHelper mArduinoHelper;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mArduinoHelper = new ArduinoHelper(this);
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
mArduinoHelper.sendCommand(ArduinoHelper.LED_SERVO_COMMAND,
(byte) 0x1, 250);

}
});

Button button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
mArduinoHelper.sendCommand(ArduinoHelper.LED_SERVO_COMMAND,
(byte) 0x1, 1);

}
});

Button button3 = (Button) findViewById(R.id.button3);
button3.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
mArduinoHelper.sendCommand(ArduinoHelper.LED_SERVO_COMMAND,
(byte) 0x0, 250);

}
});

Button button4 = (Button) findViewById(R.id.button4);
button4.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
mArduinoHelper.sendCommand(ArduinoHelper.LED_SERVO_COMMAND,
(byte) 0x0, 1);

}
});
}

@Override
public void onDestroy() {
super.onDestroy();
mArduinoHelper.onDestroy();
}

@Override
public void onResume() {
super.onResume();
mArduinoHelper.onResume();
}

}
</pre>
<p>代码<a href="http://www.imobilebbs.com/download/arduino/ArduinoLedDemo.zip">下载</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.imobilebbs.com/wordpress/?feed=rss2&#038;p=3063</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android ApiDemos示例解析(205):Graphics-&gt;OpenGL ES-&gt;Translucent GLSurfaceView</title>
		<link>http://www.imobilebbs.com/wordpress/?p=3057</link>
		<comments>http://www.imobilebbs.com/wordpress/?p=3057#comments</comments>
		<pubDate>Fri, 04 May 2012 03:50:29 +0000</pubDate>
		<dc:creator>guidebee</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[OpenGL ES]]></category>
		<category><![CDATA[教程]]></category>

		<guid isPermaLink="false">http://www.imobilebbs.com/wordpress/?p=3057</guid>
		<description><![CDATA[本例介绍使用透明背景绘制OpenGL 图形。步骤如下： 1. 对于Activity使用透明主题 &#60;activity android:name=”.graphics.TranslucentGLSurfaceViewActivity” android:label=”Graphics/OpenGL ES/Translucent GLSurfaceView”   android:theme=”@style/Theme.Translucent” android:configChanges=”keyboardHidden&#124;orientation&#124;screenLayout&#124;screenSize&#124;smallestScreenSize”&#62; &#60;intent-filter&#62; &#60;action android:name=”android.intent.action.MAIN” /&#62; &#60;category android:name=”android.intent.category.SAMPLE_CODE” /&#62; &#60;/intent-filter&#62; &#60;/activity&#62; 2. 使用8888 (RGBA) 格式，Alpha通道是显示透明图形必需的。 3. 为GLSurfaceView指定Alpha通道 4. 为绘制的图行背景为颜色（0，0，0，0） &#160;]]></description>
			<content:encoded><![CDATA[<p>本例介绍使用透明背景绘制OpenGL 图形。步骤如下：</p>
<p>1. 对于Activity使用透明主题</p>
<p>&lt;activity android:name=”.graphics.TranslucentGLSurfaceViewActivity”<br />
android:label=”Graphics/OpenGL ES/Translucent GLSurfaceView”<br />
<strong><span style="color: #0000ff;">  android:theme=”@style/Theme.Translucent”</span></strong><br />
android:configChanges=”keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize”&gt;<br />
&lt;intent-filter&gt;<br />
&lt;action android:name=”android.intent.action.MAIN” /&gt;<br />
&lt;category android:name=”android.intent.category.SAMPLE_CODE” /&gt;<br />
&lt;/intent-filter&gt;<br />
&lt;/activity&gt;</p>
<p>2. 使用8888 (RGBA) 格式，Alpha通道是显示透明图形必需的。</p>
<pre class="brush: java; title: ; notranslate">
// We want an 8888 pixel format because that's required for
// a translucent window.
// And we want a depth buffer.
mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
</pre>
<p>3. 为GLSurfaceView指定Alpha通道</p>
<pre class="brush: java; title: ; notranslate">
mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
</pre>
<p>4. 为绘制的图行背景为颜色（0，0，0，0）</p>
<pre class="brush: java; title: ; notranslate">
gl.glClearColor(0,0,0,0);
</pre>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/05/20120504001.png"><img class="aligncenter size-full wp-image-3058" title="20120504001" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/05/20120504001.png" alt="" width="480" height="800" /></a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.imobilebbs.com/wordpress/?feed=rss2&#038;p=3057</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android ApiDemos示例解析(204):Graphics-&gt;OpenGL ES-&gt;Frame Buffer Object</title>
		<link>http://www.imobilebbs.com/wordpress/?p=3051</link>
		<comments>http://www.imobilebbs.com/wordpress/?p=3051#comments</comments>
		<pubDate>Thu, 03 May 2012 14:59:08 +0000</pubDate>
		<dc:creator>guidebee</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[OpenGL ES]]></category>
		<category><![CDATA[教程]]></category>

		<guid isPermaLink="false">http://www.imobilebbs.com/wordpress/?p=3051</guid>
		<description><![CDATA[Frame Buffer 对象的概念可以参见前面文章Android OpenGL ES 开发教程(23)：FrameBuffer。 简单的和2D图像类比，Frame Buffer 如果 对应到二维图形环境中，就是一个2D的内存数组空间，缺省情况为屏幕的显存，也可以创建Offscreen 内存空间，此时Frame Buffer 可以是一个二维数组，数组每个元素代表一个像素颜色。 对于三维图形来说，除了需要代表颜色的二维数组（Color Buffer），还需要深度二维数组（Depth Buffer) 或遮罩数组(Stencil Buffer)，因此在OpenGL 中的Frame Buffer为上述Color Buffer,Depth Buffer,Stencil Buffer 的集合。如果手机具有GPU，其缺省的Frame Buffer也是3D屏幕显示区域。 通过Opengl ES扩展支持，应用程序也可以创建内存中的Frame Buffer对象（不用于屏幕显示）。通过这种应用程序创建的FrameBuffer对象，OpenGL应用可以将图像显示输出重新定向到这个非屏幕显示用FrameBuffer对象中，类似于二维图形绘制中常用的Offscreen 技术。 和缺省的屏幕显示FrameBuffer一样，由应用程序创建的FrameBuffer对象也是由Color Buffer, Depth Buffer和Stencil Buffer(可选）的集合组成。这些Buffer在FrameBuffer对象中可以称为FrameBuffer-attachable 图像，FrameBuffer定义了一些接入点(Attachment Point)可以用于连接（Attach）这些Buffer数组。 OpenGL ES定义了两种FrameBuffer-attachable 图像，Texture 和 renderbuffer &#8230; <a href="http://www.imobilebbs.com/wordpress/?p=3051">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Frame Buffer 对象的概念可以参见前面文章<a href="http://www.imobilebbs.com/wordpress/?p=2308">Android OpenGL ES 开发教程(23)：FrameBuffer</a>。</p>
<p>简单的和2D图像类比，Frame Buffer 如果 对应到二维图形环境中，就是一个2D的内存数组空间，缺省情况为屏幕的显存，也可以创建Offscreen 内存空间，此时Frame Buffer 可以是一个二维数组，数组每个元素代表一个像素颜色。</p>
<p>对于三维图形来说，除了需要代表颜色的二维数组（Color Buffer），还需要深度二维数组（Depth Buffer) 或遮罩数组(Stencil Buffer)，因此在OpenGL 中的Frame Buffer为上述Color Buffer,Depth Buffer,Stencil Buffer 的集合。如果手机具有GPU，其缺省的Frame Buffer也是3D屏幕显示区域。</p>
<p>通过Opengl ES扩展支持，应用程序也可以创建内存中的Frame Buffer对象（不用于屏幕显示）。通过这种应用程序创建的FrameBuffer对象，OpenGL应用可以将图像显示输出重新定向到这个非屏幕显示用FrameBuffer对象中，类似于二维图形绘制中常用的Offscreen 技术。</p>
<p>和缺省的屏幕显示FrameBuffer一样，由应用程序创建的FrameBuffer对象也是由Color Buffer, Depth Buffer和Stencil Buffer(可选）的集合组成。这些Buffer在FrameBuffer对象中可以称为FrameBuffer-attachable 图像，FrameBuffer定义了一些接入点(Attachment Point)可以用于连接（Attach）这些Buffer数组。</p>
<p>OpenGL ES定义了两种FrameBuffer-attachable 图像，Texture 和 renderbuffer ，简单的可以将Texture  理解为Color buffer 或是2D图像，render buffer 对应于depth buffer。</p>
<p>下图表示了Texture , Renderbuffer 对象和 Frame Buffer 对象之间的关系：</p>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/05/gl_fbo01.png"><img class="aligncenter size-full wp-image-3052" title="gl_fbo01" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/05/gl_fbo01.png" alt="" width="380" height="278" /></a></p>
<p>但把Texture 和 Render Buffer 链接到FrameBuffer这些接入点(ATTACHMENT)之后，之后所有OpenGL绘图指令的输出结果就写入到这些内存Buffer中，而非缺省屏幕显示。</p>
<p>不同的Android设备支持的OpenGL ES扩展可能有所不同，因此如果需要使用应用创建FrameBuffer对象前需要检查手机是否支持Framebuffer扩展，本例使用</p>
<pre class="brush: java; title: ; notranslate">
private boolean checkIfContextSupportsExtension(GL10 gl, String extension) {
 String extensions = &quot; &quot; + gl.glGetString(GL10.GL_EXTENSIONS) + &quot; &quot;;
 // The extensions string is padded with spaces between extensions, but not
 // necessarily at the beginning or end. For simplicity, add spaces at the
 // beginning and end of the extensions string and the extension string.
 // This means we can avoid special-case checks for the first or last
 // extension, as well as avoid special-case checks when an extension name
 // is the same as the first part of another extension name.
 return extensions.indexOf(&quot; &quot; + extension + &quot; &quot;) &gt;= 0;
}
</pre>
<p>使用FrameBuffer的基本步骤如下：</p>
<p>1. 使用glGenFramebuffersOES创建FrameBuffer对象</p>
<pre class="brush: java; title: ; notranslate">
int[] framebuffers = new int[1];
gl11ep.glGenFramebuffersOES(1, framebuffers, 0);
framebuffer = framebuffers[0];
</pre>
<p>2. 创建好FrameBuffer后，必须绑定FrameBuffer到OpenGL中，</p>
<pre class="brush: java; title: ; notranslate">
gl11ep.glBindFramebufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, framebuffer);
</pre>
<p>第一个参数类型必须为GL_FRAMEBUFFER_OES，第二个参数为FrameBuffer的ID。如果Id为0，表示绑定到缺省的屏幕FrameBuffer。</p>
<p>绑定之后，后续的OpenGL绘制结果就从定向到FrameBuffer中，而不是显示到屏幕上。</p>
<p>3， 使用glGenRenderbuffersOES创建RenderBuffer</p>
<pre class="brush: java; title: ; notranslate">
int depthbuffer;
int[] renderbuffers = new int[1];
gl11ep.glGenRenderbuffersOES(1, renderbuffers, 0);
depthbuffer = renderbuffers[0];
</pre>
<p>4. 和FrameBuffer类似，创建RenderBuffer对象，也需要绑定到OpengL库中</p>
<pre class="brush: java; title: ; notranslate">
gl11ep.glBindRenderbufferOES(GL11ExtensionPack.GL_RENDERBUFFER_OES, depthbuffer);
</pre>
<p>5. 给renderBuffer 分配内存。</p>
<p>创建的renderBuffer 本身不含有内存空间，因此必须给它分配内存空间，这是通过glRenderbufferStorageOES来实现的。</p>
<pre class="brush: java; title: ; notranslate">
gl11ep.glRenderbufferStorageOES(GL11ExtensionPack.GL_RENDERBUFFER_OES,
 GL11ExtensionPack.GL_DEPTH_COMPONENT16, width, height);
</pre>
<p>第二个参数为创建的RenderBuffer的内部格式类型。</p>
<p>6. 创建Texture对象，可以参见<a href="http://www.imobilebbs.com/wordpress/?p=2979">Android ApiDemos示例解析(200):Graphics-&gt;OpenGL ES-&gt;Textured Triangle</a>。</p>
<p>7. 在创建好FrameBuffer，Texture和renderBuffer对象之后，需要把Texture,RenderBuffer对象和FrameBuffer中对应的Attachment Point链接起来。</p>
<p>链接Texture对象</p>
<pre class="brush: java; title: ; notranslate">
gl11ep.glFramebufferTexture2DOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES,
 GL11ExtensionPack.GL_COLOR_ATTACHMENT0_OES, GL10.GL_TEXTURE_2D,
 targetTextureId, 0);
</pre>
<p>链接renderBuffer 对象</p>
<pre class="brush: java; title: ; notranslate">
l11ep.glFramebufferRenderbufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES,
 GL11ExtensionPack.GL_DEPTH_ATTACHMENT_OES,
 GL11ExtensionPack.GL_RENDERBUFFER_OES, depthbuffer);
</pre>
<p>来看一下本例的onDrawFrame方法</p>
<pre class="brush: java; title: ; notranslate">
private static final boolean DEBUG_RENDER_OFFSCREEN_ONSCREEN = false;

public void onDrawFrame(GL10 gl) {
 checkGLError(gl);
 if (mContextSupportsFrameBufferObject) {
 GL11ExtensionPack gl11ep = (GL11ExtensionPack) gl;
 if (DEBUG_RENDER_OFFSCREEN_ONSCREEN) {
 drawOffscreenImage(gl, mSurfaceWidth, mSurfaceHeight);
 } else {
 gl11ep.glBindFramebufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, mFramebuffer);
 drawOffscreenImage(gl, mFramebufferWidth, mFramebufferHeight);
 gl11ep.glBindFramebufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, 0);
 drawOnscreen(gl, mSurfaceWidth, mSurfaceHeight);
 }
 } else {
 // Current context doesn't support frame buffer objects.
 // Indicate this by drawing a red background.
 gl.glClearColor(1,0,0,0);
 gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
 }
}
</pre>
<p>本例在创建的FrameBuffer中绘制立方体，其绘图指令和例子<a href="http://www.imobilebbs.com/wordpress/?p=3023">Android ApiDemos示例解析(203):Graphics-&gt;OpenGL ES-&gt;GLSurfaceView</a>一样。但其显示结果存放在mFramebuffer中（可以通过将DEBUG_RENDER_OFFSCREEN_ONSCREEN设为True看到FrameBuffer的内容）。然后将mFramebuffer显示的内存作为<a href="http://www.imobilebbs.com/wordpress/?p=2979">Triangle的材质绘制三角形</a>。</p>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/05/20120503001.png"><img class="aligncenter size-full wp-image-3055" title="20120503001" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/05/20120503001.png" alt="" width="360" height="640" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.imobilebbs.com/wordpress/?feed=rss2&#038;p=3051</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android 自动控制生产线</title>
		<link>http://www.imobilebbs.com/wordpress/?p=3044</link>
		<comments>http://www.imobilebbs.com/wordpress/?p=3044#comments</comments>
		<pubDate>Fri, 27 Apr 2012 12:34:14 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.imobilebbs.com/wordpress/?p=3044</guid>
		<description><![CDATA[在前面Android ADK 编程简介介绍过使用Android NDK可以通过Arduino Board 实现一个自动控制系统，今天和同事一起设计了一个“生产线”（具体用途这里就不说了），先上个图片。 中间是从IKEA买的圆等和餐桌上用的转盘：-）。经过几个小时的忙活，这个系统原型基本达到设计要求。]]></description>
			<content:encoded><![CDATA[<p>在前面<a href="Android ADK 编程简介">Android ADK 编程简介</a>介绍过使用Android NDK可以通过Arduino Board 实现一个自动控制系统，今天和同事一起设计了一个“生产线”（具体用途这里就不说了），先上个图片。</p>
<p style="text-align: center;"><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/201204270011.png"><img class="aligncenter size-full wp-image-3047" title="20120427001" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/201204270011.png" alt="" width="778" height="584" /></a></p>
<p style="text-align: left;">中间是从IKEA买的圆等和餐桌上用的转盘：-）。经过几个小时的忙活，这个系统原型基本达到设计要求。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.imobilebbs.com/wordpress/?feed=rss2&#038;p=3044</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>本博客支持android,iphone,iPad 显示</title>
		<link>http://www.imobilebbs.com/wordpress/?p=3038</link>
		<comments>http://www.imobilebbs.com/wordpress/?p=3038#comments</comments>
		<pubDate>Thu, 26 Apr 2012 15:45:12 +0000</pubDate>
		<dc:creator>guidebee</dc:creator>
				<category><![CDATA[手机平台]]></category>
		<category><![CDATA[技术文章]]></category>

		<guid isPermaLink="false">http://www.imobilebbs.com/wordpress/?p=3038</guid>
		<description><![CDATA[借助于WPTouch ，本博客在移动设备上有更美观的显示，有兴趣的朋友可以使用您的手机或平板电脑登录本博客:-)]]></description>
			<content:encoded><![CDATA[<p>借助于WPTouch ，本博客在移动设备上有更美观的显示，有兴趣的朋友可以使用您的手机或平板电脑登录本博客:-)</p>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/20120426003.png"><img class="aligncenter size-full wp-image-3039" title="20120426003" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/20120426003.png" alt="" width="727" height="640" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.imobilebbs.com/wordpress/?feed=rss2&#038;p=3038</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android ApiDemos示例解析(203):Graphics-&gt;OpenGL ES-&gt;GLSurfaceView</title>
		<link>http://www.imobilebbs.com/wordpress/?p=3023</link>
		<comments>http://www.imobilebbs.com/wordpress/?p=3023#comments</comments>
		<pubDate>Thu, 26 Apr 2012 13:50:48 +0000</pubDate>
		<dc:creator>guidebee</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[OpenGL ES]]></category>
		<category><![CDATA[教程]]></category>

		<guid isPermaLink="false">http://www.imobilebbs.com/wordpress/?p=3023</guid>
		<description><![CDATA[这个例子是使用OpenGL ES绘图最简单的例子，说明如何使用GLSerfaceView，前面的例子Android OpenGL ES 开发教程(6)：GLSurfaceView 已经详细说明了，本篇不再具体描述。几何图形顶点定义参见Android OpenGL ES 开发教程(8)：基本几何图形定义，颜色定义参见Android OpenGL ES 开发教程(20)：颜色Color。 本例对应的类文件为Cube.java ,CubeRenderer.java ,GLSurfaceViewActivity.java 。 Cube 类定义了一个立方体，要注意的是本例使用GL_FIXED，而非GL_FLOAT, GL_FIXED 表示16.16 定点浮点数，GL_FIXED 的0&#215;10000 相当于GL_FLOAT 的1.0 对应的代码如下： CubeRenderer 通过坐标变换的方式绘制两个立方体， 下图为当mAngle=45 度时显示结果：]]></description>
			<content:encoded><![CDATA[<p>这个例子是使用OpenGL ES绘图最简单的例子，说明如何使用GLSerfaceView，前面的例子<a href="http://www.imobilebbs.com/wordpress/?p=1889">Android OpenGL ES 开发教程(6)：GLSurfaceView</a> 已经详细说明了，本篇不再具体描述。几何图形顶点定义参见<a href="http://www.imobilebbs.com/wordpress/?p=1938">Android OpenGL ES 开发教程(8)：基本几何图形定义</a>，颜色定义参见<a href="http://www.imobilebbs.com/wordpress/?p=2087">Android OpenGL ES 开发教程(20)：颜色Color</a>。</p>
<p>本例对应的类文件为Cube.java ,CubeRenderer.java ,GLSurfaceViewActivity.java 。</p>
<p>Cube 类定义了一个立方体，要注意的是本例使用GL_FIXED，而非GL_FLOAT, GL_FIXED 表示16.16 定点浮点数，GL_FIXED 的0&#215;10000 相当于GL_FLOAT 的1.0</p>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/20120426001.png"><img class="aligncenter size-full wp-image-3024" title="20120426001" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/20120426001.png" alt="" width="429" height="308" /></a></p>
<p>对应的代码如下：</p>
<pre class="brush: java; title: ; notranslate">
int one = 0x10000;
int vertices[] = {
 -one, -one, -one,
 one, -one, -one,
 one, one, -one,
 -one, one, -one,
 -one, -one, one,
 one, -one, one,
 one, one, one,
 -one, one, one,
};

int colors[] = {
 0, 0, 0, one,
 one, 0, 0, one,
 one, one, 0, one,
 0, one, 0, one,
 0, 0, one, one,
 one, 0, one, one,
 one, one, one, one,
 0, one, one, one,
};

byte indices[] = {
 0, 4, 5, 0, 5, 1,
 1, 5, 6, 1, 6, 2,
 2, 6, 7, 2, 7, 3,
 3, 7, 4, 3, 4, 0,
 4, 7, 6, 4, 6, 5,
 3, 0, 1, 3, 1, 2
};
</pre>
<p>CubeRenderer 通过<a href="http://www.imobilebbs.com/wordpress/?p=1530">坐标变换</a>的方式绘制两个立方体，</p>
<pre class="brush: java; title: ; notranslate">
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0, 0, -3.0f);
gl.glRotatef(mAngle, 0, 1, 0);
gl.glRotatef(mAngle*0.25f, 1, 0, 0);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

mCube.draw(gl);

gl.glRotatef(mAngle*2.0f, 0, 1, 1);
gl.glTranslatef(0.5f, 0.5f, 0.5f);

mCube.draw(gl);
</pre>
<p>下图为当mAngle=45 度时显示结果：</p>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/20120426002.png"><img class="aligncenter size-full wp-image-3025" title="20120426002" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/20120426002.png" alt="" width="360" height="640" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.imobilebbs.com/wordpress/?feed=rss2&#038;p=3023</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android ApiDemos示例解析(202):Graphics-&gt;OpenGL ES-&gt;Cube Map</title>
		<link>http://www.imobilebbs.com/wordpress/?p=3012</link>
		<comments>http://www.imobilebbs.com/wordpress/?p=3012#comments</comments>
		<pubDate>Tue, 24 Apr 2012 01:28:53 +0000</pubDate>
		<dc:creator>guidebee</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[OpenGL ES]]></category>
		<category><![CDATA[教程]]></category>

		<guid isPermaLink="false">http://www.imobilebbs.com/wordpress/?p=3012</guid>
		<description><![CDATA[Cube Map，中文可以翻译成立方环境映射，下面是摘自维基百科的说明： 立方反射映射是用立方映射使得物体看起来如同在反射周围环境的一项技术。通常，这通常使用户外渲染中使用的 skybox 完成。尽管由于反射物周围的物体无法在结果中看到，所以这并不是一个真正的反射，但是通常仍然可以达到所期望的效果。 通过确定观察物体的向量就可以进行立方映射反射，照相机光线在照相机向量与物体相交的位置按照曲面法线方向进行反射，这样传到立方图（cube map）取得纹素(texel)的反射光线在照相机看来好像位于物体表面，这样就得到了物体的反射效果。 简单的讲，就是你把一个具有金属反射特性的茶壶放在一个房间中，茶壶的金属表面会反射房间的场景，Cube Map就是解决如何将场景（环境）的内容显示在茶壶的表面，如下图所示： 本例使用环面（Torus）做为反射的表面，在OpenGL ES中任何3D物体，最终都是通过三角形来构造的，本例代码generateTorusGrid 和Grid对象用来构造环面的顶点坐标。具体算法有兴趣的可以自行研究（需要有立体几何的知识，这里不详细解释）。 Cube map技术说到底就是用一个虚拟的立方体(cube)包围住物体，眼睛到物体某处的向量eyevec经过反射（以该处的法线为对称轴），反射向量reflectvec射到立方体上，就在该立方体上获得一个纹素了（见下图）。明显，我们需要一个类似天空盒般的6张纹理贴在这个虚拟的立方体上。按CUBE MAPPING原意，就是一种enviroment map，因此把周围场景渲染到这6张纹理里是“正统”的。也就是每次渲染时，都作一次离线渲染，分别在每个矩形中心放置相机“拍下”场景，用FBO渲染到纹理，然后把这张纹理作为一个cube map对象的六纹理之一。这样即使是动态之物也能被映射到物体表面了（虽然缺点是不能映射物体自身的任何部分）。 本例使用的六张图为res/raw 目录下的 skycubemap0 &#8212; skycubemap5 ,如下图所示 使用Cube Map，首先要检测设备是否支持Cube Map 材质，本例使用以下代码检测设备是否支持Cube Map。 Cube Map （使用6张图），处调用设置Cube Map外，其基本使用步骤类似于普通材质的使用。本例使用资源，其设置Cube Map的基本步骤如下： 1. 调入图像资源 2. 绑定材质 函数generateCubeMap返回一个Texture的ID，在OpenGL ES中使用材质时，需要绑定材质 这样就给环面物体添加了环境材质，显示结果如下：]]></description>
			<content:encoded><![CDATA[<p>Cube Map，中文可以翻译成<a href="http://zh.wikipedia.org/wiki/%E5%8F%8D%E5%B0%84%E8%B4%B4%E5%9B%BE">立方环境映射</a>，下面是摘自维基百科的说明：</p>
<p><strong>立方反射映射</strong>是用立方映射使得物体看起来如同在反射周围环境的一项技术。通常，这通常使用户外渲染中使用的 skybox 完成。尽管由于反射物周围的物体无法在结果中看到，所以这并不是一个真正的反射，但是通常仍然可以达到所期望的效果。</p>
<p>通过确定观察物体的向量就可以进行立方映射反射，<strong>照相机光线</strong>在照相机向量与物体相交的位置按照曲面法线方向进行反射，这样传到立方图（cube map）取得纹素(texel)的<strong>反射光线</strong>在照相机看来好像位于物体表面，这样就得到了物体的反射效果。</p>
<p>简单的讲，就是你把一个具有金属反射特性的茶壶放在一个房间中，茶壶的金属表面会反射房间的场景，Cube Map就是解决如何将场景（环境）的内容显示在茶壶的表面，如下图所示：</p>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/silverteapot_stpeters.jpg"><img class="aligncenter size-full wp-image-3013" title="silverteapot_stpeters" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/silverteapot_stpeters.jpg" alt="" width="220" height="165" /></a></p>
<p>本例使用<a href="http://zh.wikipedia.org/wiki/%E7%8E%AF%E9%9D%A2">环面</a>（Torus）做为反射的表面，在OpenGL ES中任何3D物体，最终都是通过三角形来构造的，本例代码generateTorusGrid 和Grid对象用来构造环面的顶点坐标。具体算法有兴趣的可以自行研究（需要有立体几何的知识，这里不详细解释）。</p>
<p>Cube map技术说到底就是用一个虚拟的立方体(cube)包围住物体，眼睛到物体某处的向量eyevec经过反射（以该处的法线为对称轴），反射向量reflectvec射到立方体上，就在该立方体上获得一个纹素了（见下图）。明显，我们需要一个类似天空盒般的6张纹理贴在这个虚拟的立方体上。按CUBE MAPPING原意，就是一种enviroment map，因此把周围场景渲染到这6张纹理里是“正统”的。也就是每次渲染时，都作一次离线渲染，分别在每个矩形中心放置相机“拍下”场景，用FBO渲染到纹理，然后把这张纹理作为一个cube map对象的六纹理之一。这样即使是动态之物也能被映射到物体表面了（虽然缺点是不能映射物体自身的任何部分）。</p>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/cubemap.png"><img class="aligncenter size-full wp-image-3015" title="cubemap" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/cubemap.png" alt="" width="414" height="329" /> </a>本例使用的六张图为res/raw 目录下的 skycubemap0 &#8212; skycubemap5 ,如下图所示</p>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/20120422001.png"><img class="aligncenter size-full wp-image-3016" title="20120422001" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/20120422001.png" alt="" width="561" height="399" /></a>使用Cube Map，首先要检测设备是否支持Cube Map 材质，本例使用以下代码检测设备是否支持Cube Map。</p>
<pre class="brush: java; title: ; notranslate">
private boolean checkIfContextSupportsCubeMap(GL10 gl) {
return checkIfContextSupportsExtension(gl, &quot;GL_OES_texture_cube_map&quot;);

}

/**
* This is not the fastest way to check for an extension, but fine if
* we are only checking for a few extensions each time a context is created.
* @param gl
* @param extension
* @return true if the extension is present in the current context.
*/
private boolean checkIfContextSupportsExtension(GL10 gl, String extension) {
String extensions = &quot; &quot; + gl.glGetString(GL10.GL_EXTENSIONS) + &quot; &quot;;
// The extensions string is padded with spaces between extensions, but not
// necessarily at the beginning or end. For simplicity, add spaces at the
// beginning and end of the extensions string and the extension string.
// This means we can avoid special-case checks for the first or last
// extension, as well as avoid special-case checks when an extension name
// is the same as the first part of another extension name.
return extensions.indexOf(&quot; &quot; + extension + &quot; &quot;) &gt;= 0;
}
</pre>
<p>Cube Map （使用6张图），处调用设置Cube Map外，其基本使用步骤类似于普通材质的使用。本例使用资源，其设置Cube Map的基本步骤如下：</p>
<p>1. 调入图像资源</p>
<pre class="brush: java; title: ; notranslate">
if (mContextSupportsCubeMap) {
int[] cubeMapResourceIds = new int[]{
R.raw.skycubemap0, R.raw.skycubemap1, R.raw.skycubemap2,
R.raw.skycubemap3, R.raw.skycubemap4, R.raw.skycubemap5};
mCubeMapTextureID = generateCubeMap(gl, cubeMapResourceIds);
}

....

private int generateCubeMap(GL10 gl, int[] resourceIds) {
checkGLError(gl);
int[] ids = new int[1];
gl.glGenTextures(1, ids, 0);
int cubeMapTextureId = ids[0];
gl.glBindTexture(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP, cubeMapTextureId);
gl.glTexParameterf(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP,
GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP,
GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);

for (int face = 0; face &lt; 6; face++) {
InputStream is = getResources().openRawResource(resourceIds[face]);
Bitmap bitmap;
try {
bitmap = BitmapFactory.decodeStream(is);
} finally {
try {
is.close();
} catch(IOException e) {
Log.e(&quot;CubeMap&quot;, &quot;Could not decode texture for face &quot; + Integer.toString(face));
}
}
GLUtils.texImage2D(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0,
bitmap, 0);
bitmap.recycle();
}
checkGLError(gl);
return cubeMapTextureId;
}
</pre>
<p>2. 绑定材质</p>
<p>函数generateCubeMap返回一个Texture的ID，在OpenGL ES中使用材质时，需要绑定材质</p>
<pre class="brush: java; title: ; notranslate">
gl.glActiveTexture(GL10.GL_TEXTURE0);
checkGLError(gl);
gl.glEnable(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP);
checkGLError(gl);
gl.glBindTexture(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP, mCubeMapTextureID);
checkGLError(gl);
GL11ExtensionPack gl11ep = (GL11ExtensionPack) gl;
gl11ep.glTexGeni(GL11ExtensionPack.GL_TEXTURE_GEN_STR,
GL11ExtensionPack.GL_TEXTURE_GEN_MODE,
GL11ExtensionPack.GL_REFLECTION_MAP);
checkGLError(gl);
gl.glEnable(GL11ExtensionPack.GL_TEXTURE_GEN_STR);
checkGLError(gl);
gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_DECAL);
...
mGrid.draw(gl);
...
gl.glDisable(GL11ExtensionPack.GL_TEXTURE_GEN_STR);
</pre>
<p>这样就给环面物体添加了环境材质，显示结果如下：</p>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/20120422002.png"><img class="aligncenter size-full wp-image-3017" title="20120422002" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/20120422002.png" alt="" width="480" height="800" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.imobilebbs.com/wordpress/?feed=rss2&#038;p=3012</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>引路蜂地图应用GNavigator完整源码</title>
		<link>http://www.imobilebbs.com/wordpress/?p=3002</link>
		<comments>http://www.imobilebbs.com/wordpress/?p=3002#comments</comments>
		<pubDate>Thu, 19 Apr 2012 14:35:33 +0000</pubDate>
		<dc:creator>guidebee</dc:creator>
				<category><![CDATA[地图开发]]></category>
		<category><![CDATA[地图开发包]]></category>

		<guid isPermaLink="false">http://www.imobilebbs.com/wordpress/?p=3002</guid>
		<description><![CDATA[GNavigator是 曾经发布在Nokia Ovi Store的Java ME应用，基本使用到了引路蜂地图API的所有功能，尽管这是一个基于LWUIT的应用，使用Java语言开发，其它平台也可以参考这个应用的代码。 总代码量大约为24000行，其中纯代码为12000行。 几个用户界面如下： 包括导航演示（可以连接GPS） 代码下载 ,用户手册 ，为Netbean 项目。 如果您喜欢本博客，希望捐赠本站，请点击右方的捐赠按钮，或点击下面按钮，谢谢您的支持！]]></description>
			<content:encoded><![CDATA[<p>GNavigator是 曾经发布在Nokia Ovi Store的Java ME应用，基本使用到了<a href="http://www.imobilebbs.com/wordpress/?page_id=6">引路蜂地图API</a>的所有功能，尽管这是一个基于<a href="http://www.imobilebbs.com/wordpress/?page_id=28">LWUIT</a>的应用，使用Java语言开发，其它平台也可以参考这个应用的代码。</p>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/GNavigator.png"><img class="size-full wp-image-3003 alignnone" title="GNavigator" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/GNavigator.png" alt="" width="981" height="473" /></a></p>
<p>总代码量大约为24000行，其中纯代码为12000行。</p>
<p><a class="aligncenter size-full wp-image-3004" title="source"><img class="aligncenter size-full wp-image-3004" title="source" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/source.png" alt="" width="403" height="468" /></a></p>
<p>几个用户界面如下：</p>
<p><img class="aligncenter" title="gnavigator" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2011/01/navigation.png" alt="" width="757" height="316" /></p>
<p>包括导航演示（可以连接GPS）</p>
<p><img class="aligncenter" title="GPS" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2011/01/20110129010.png" alt="" width="500" height="666" /></p>
<p>代码<a href="http://www.imobilebbs.com/download/lwuit/Navigator.rar">下载</a> ,<a href="http://www.imobilebbs.com/download/lwuit/GNavigator.pdf">用户手册</a> ，为Netbean 项目。</p>
<p><span style="color: #ff0000;"><strong>如果您喜欢本博客，希望捐赠本站，请点击右方的捐赠按钮，或点击下面按钮，谢谢您的支持！</strong></span></p>
<div style="text-align:center">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="GSUSXN2XUKNCA">
<input type="image" src="https://www.paypal.com/zh_HK/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_AU/i/scr/pixel.gif" width="1" height="1"><br />
</form>
<p />
<a href="https://me.alipay.com/guidebee" target="_blank"><img src="http://www.imobilebbs.com/wordpress/alipay.png" alt="Donate!" /></a>
 </div>
]]></content:encoded>
			<wfw:commentRss>http://www.imobilebbs.com/wordpress/?feed=rss2&#038;p=3002</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android ADK 编程简介</title>
		<link>http://www.imobilebbs.com/wordpress/?p=2994</link>
		<comments>http://www.imobilebbs.com/wordpress/?p=2994#comments</comments>
		<pubDate>Thu, 19 Apr 2012 04:07:18 +0000</pubDate>
		<dc:creator>guidebee</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[ADK]]></category>

		<guid isPermaLink="false">http://www.imobilebbs.com/wordpress/?p=2994</guid>
		<description><![CDATA[前面已经说过Android SDK ，NDK， APK， 现在有来了个ADK， 这么多K:-). 那么什么是ADK，ADK是Android Open Accessory Development Kit 的缩写。使用ADK使得不支持USB Host功能的Android设备也可以和其它USB设备交互。比如使用Android手机来控制步进电机，条码扫描仪，机器人等。 Android 设备支持各种各样的USB设备，即可以以USB Host模式工作，也可以以USB Accessory 模式工作： 从Android 3.1 (API Level 12) 开始Andriod平台开始支持USB Accessory 和 Host 工作模式，Google也通过附加库的方式中Android 2.3.4 (API Level 10) 支持USB Accessory 和Host 工作模式。 注意:对USB Host或Accessory 模式的支持最终取决于设备硬件，和平台OS的版本无关，比如Sumsung Galaxy &#8230; <a href="http://www.imobilebbs.com/wordpress/?p=2994">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>前面已经说过Android SDK ，NDK， APK， 现在有来了个ADK， 这么多K:-). 那么什么是ADK，ADK是Android Open Accessory Development Kit 的缩写。使用ADK使得不支持USB Host功能的Android设备也可以和其它USB设备交互。比如使用Android手机来控制步进电机，条码扫描仪，机器人等。</p>
<p>Android 设备支持各种各样的USB设备，即可以以USB Host模式工作，也可以以USB Accessory 模式工作：</p>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/usb-host-accessory.png"><img class="aligncenter size-full wp-image-2995" title="usb-host-accessory" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/usb-host-accessory.png" alt="" width="563" height="363" /></a></p>
<p>从Android 3.1 (API Level 12) 开始Andriod平台开始支持USB Accessory 和 Host 工作模式，Google也通过附加库的方式中Android 2.3.4 (API Level 10) 支持USB Accessory 和Host 工作模式。</p>
<p>注意:对USB Host或Accessory 模式的支持最终取决于设备硬件，和平台OS的版本无关，比如Sumsung Galaxy Nexus 同时支持USB Host或Accessory 模式而Sumsung Nexus S 只支持USB Accessory 模式，尽管两种手机都采用了ICS 4.0.4平台。</p>
<p>本例介绍如何使用ADK 通过<a href="http://www.arduino.cc/en/Main/software">Arduino</a> 连接QRCode Scanner 通过ADK 和Android应用通信。</p>
<p>其硬件连接图如下：</p>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/IMG_20120419_111122.jpg"><img class="aligncenter size-full wp-image-2996" title="IMG_20120419_111122" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/IMG_20120419_111122.jpg" alt="" width="545" height="727" /></a>其中Arduino 控制板采用的<a href="http://www.freetronics.com/products/usbdroid">Freetronics的UsbDroid控制板</a>（和Arduino兼容），QRCode Scanner(工作中USB HID模式）。</p>
<p>由于手机的USB需要和Usb Hub 连接，因此本例需要<a href="http://www.imobilebbs.com/wordpress/?p=2964">Android 不通过USB数据线调试的方法</a>。</p>
<p>本例没有采用http://developer.android.com/guide/topics/usb/adk.html 中介绍的软件和USB_Host_Sheild 库，是以为这个库不支持Usb Hub，需要将上图中连接Usb Hub的线直接连到手机，这样就无法再连接QR Code Scanner了。不过基本步骤是一致的。</p>
<p>1. 下载<a href="http://arduino.cc/en/Guide/HomePage">Ardunio软件</a>和对应的USB库。</p>
<p>目前Ardunio的版本为1.0，如果你想使用Google 网站上的例子，你需要使用023版本。为方便起见，你可以从本站<a href="http://www.imobilebbs.com/download/arduino/arduino-1.0.rar">下载</a>软件和USB库（支持USB Hub功能），其中USB库为<a href="http://www.circuitsathome.com/">Circuits @Home</a> 提供。</p>
<p>2. 下载 对应的Android实例应用，本例使用<a href="http://www.imobilebbs.com/download/arduino/ArduinoTerminal.rar">Arduino terminal </a></p>
<p>3. 将firmware 安装到Arduino 控制板上。</p>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/20120419004.png"><img class="aligncenter size-full wp-image-2997" title="20120419004" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/20120419004.png" alt="" width="549" height="616" /></a>本例使用adk 中adk-barcode 示例。其代码如下，可以<a href="http://www.circuitsathome.com/mcu/exchanging-data-between-usb-devices-and-android-phone-using-arduino-and-usb-host-shield">参见</a></p>
<pre class="brush: cpp; title: ; notranslate">
/**/
/* A sketch demonstrating data exchange between two USB devices
- a HID barcode scanner and ADK-compatible Android phone */
/**/
#include &lt;avrpins.h&gt;
#include &lt;max3421e.h&gt;
#include &lt;usbhost.h&gt;
#include &lt;usb_ch9.h&gt;
#include &lt;Usb.h&gt;
#include &lt;usbhub.h&gt;
#include &lt;avr/pgmspace.h&gt;
#include &lt;address.h&gt;

#include &lt;adk.h&gt;

#include &lt;hidboot.h&gt;

USB Usb;
USBHub Hub1(&amp;Usb);
USBHub Hub2(&amp;Usb);
HIDBoot&lt;HID_PROTOCOL_KEYBOARD&gt; Keyboard(&amp;Usb);

ADK adk(&amp;Usb,&quot;Circuits@Home, ltd.&quot;,
&quot;USB Host Shield&quot;,
&quot;Arduino Terminal for Android&quot;,
&quot;1.0&quot;,
&quot;http://www.circuitsathome.com&quot;,
&quot;0000000000000001&quot;);

class KbdRptParser : public KeyboardReportParser
{

protected:
virtual void OnKeyDown    (uint8_t mod, uint8_t key);
virtual void OnKeyPressed(uint8_t key);
};

void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{
uint8_t c = OemToAscii(mod, key);

if (c)
OnKeyPressed(c);
}

/* what to do when symbol arrives */
void KbdRptParser::OnKeyPressed(uint8_t key)
{
const char* new_line = &quot;\n&quot;;
uint8_t rcode;
uint8_t keylcl;

if( adk.isReady() == false ) {
return;
}

keylcl = key;

if( keylcl == 0x13 ) {
rcode = adk.SndData( strlen( new_line ), (uint8_t *)new_line );
}
else {
rcode = adk.SndData( 1, &amp;keylcl );
}

Serial.print((char) keylcl );
Serial.print(&quot; : &quot;);
Serial.println( keylcl, HEX );
};

KbdRptParser Prs;

void setup()
{
Serial.begin(115200);
Serial.println(&quot;\r\nADK demo start&quot;);

if (Usb.Init() == -1) {
Serial.println(&quot;OSCOKIRQ failed to assert&quot;);
while(1); //halt
}//if (Usb.Init() == -1...

Keyboard.SetReportParser(0, (HIDReportParser*)&amp;Prs);

delay( 200 );
}

void loop()
{
Usb.Task();
}
</pre>
<p>这里的ADK与Google提供的<a href="http://developer.android.com/guide/topics/usb/adk.html">示例</a>稍有不同，但大同小异。</p>
<p>4. 在手机上运行Arduino terminal (这不是必须的），当将USB线连接到手机时，会自动触发这个应用。这是因为：</p>
<p>Firmware中使用ADK定义</p>
<p>ADK adk(&amp;Usb<strong>,”<span style="color: #000080;">Circuits@Home, ltd.”</span></strong>,<br />
“<span style="color: #000080;"><strong>USB Host Shield</strong></span>“,<br />
“Arduino Terminal for Android”,<br />
“<span style="color: #000080;"><strong>1.0&#8243;</strong>,</span><br />
“http://www.circuitsathome.com”,<br />
“0000000000000001&#8243;);</p>
<p>和Arduino terminal 的broadcast receiver 定义对应：</p>
<p>&lt;activity android:name=”.StartServiceActivity” android:label=”@string/starter_app_name”<br />
android:launchMode=”singleInstance” android:theme=”@android:style/Theme.NoDisplay”<br />
android:excludeFromRecents=”true”&gt;</p>
<p>&lt;intent-filter&gt;<br />
&lt;action android:name=”android.hardware.usb.action.USB_ACCESSORY_ATTACHED” /&gt;<br />
&lt;/intent-filter&gt;</p>
<p>&lt;meta-data android:name=”android.hardware.usb.action.USB_ACCESSORY_ATTACHED”<br />
<span style="color: #000080;"> android:resource=”@xml/accessory_filter”</span> /&gt;<br />
&lt;/activity&gt;</p>
<p>xml/accessory_filter.xml 的定义如下：</p>
<p>&lt;resources&gt;</p>
<p><span style="color: #000080;">&lt;usb-accessory manufacturer=”Circuits@Home, ltd.” model=”USB Host Shield” version=”1.0&#8243;</span> /&gt;<br />
&lt;/resources&gt;</p>
<p>对于你自己的例子，你可以使用你自己定义的名称，只有保证这几个值在firmware 和Android应用中定义的值一致即可。</p>
<p>运行结果如下：</p>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/20120419005.png"><img class="aligncenter size-full wp-image-2998" title="20120419005" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/20120419005.png" alt="" width="480" height="800" /></a>Arduino 编程并不复杂，只要会C语言即可，可以参见arduino-1.0 中的reference文档。Usb_host C库可以参考libraries/felis_USB_Host_Shield 的头文件。</p>
<p>注:通过这种连接方法，可以连接USB照相机，GPS， 步进电机等各种外设，可以实现使用Android来自动控制等。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.imobilebbs.com/wordpress/?feed=rss2&#038;p=2994</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android ApiDemos示例解析(201):Graphics-&gt;OpenGL ES-&gt;Compressed Texture</title>
		<link>http://www.imobilebbs.com/wordpress/?p=2988</link>
		<comments>http://www.imobilebbs.com/wordpress/?p=2988#comments</comments>
		<pubDate>Thu, 19 Apr 2012 00:45:06 +0000</pubDate>
		<dc:creator>guidebee</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[OpenGL ES]]></category>

		<guid isPermaLink="false">http://www.imobilebbs.com/wordpress/?p=2988</guid>
		<description><![CDATA[本例和上例Android ApiDemos示例解析(200):Graphics-&#62;OpenGL ES-&#62;Textured Triangle 非常类似，所不同的是调用图像（Texture）的方法不同。 本例介绍如何使用ETC1 压缩格式的图像，一种方式是从资源文件中读取ETC1格式的图像作为三角形的材质（本例使用res.raw 中的androids.pkm文件），一种是通过代码动态创建ETC1格式的图像。 android.opengl 包中的 ETC1, ETCUtil, ETCUtil.ETC1Texture 用来支持ETC1格式的压缩格式图像，简单的讲，可以把android.pkm 当做android.png ，所不同的是两种图像压缩方法不同。 使用ETC1 图像作为Texture的基本方法如下：]]></description>
			<content:encoded><![CDATA[<p>本例和上例<a href="http://www.imobilebbs.com/wordpress/?p=2979">Android ApiDemos示例解析(200):Graphics-&gt;OpenGL ES-&gt;Textured Triangle</a> 非常类似，所不同的是调用图像（Texture）的方法不同。</p>
<p>本例介绍如何使用<a href="http://en.wikipedia.org/wiki/Ericsson_Texture_Compression">ETC1</a> 压缩格式的图像，一种方式是从资源文件中读取ETC1格式的图像作为三角形的材质（本例使用res.raw 中的androids.pkm文件），一种是通过代码动态创建ETC1格式的图像。 <a href="http://developer.android.com/reference/android/opengl/package-summary.html">android.opengl</a> 包中的 ETC1, ETCUtil, ETCUtil.ETC1Texture 用来支持ETC1格式的压缩格式图像，简单的讲，可以把android.pkm 当做android.png ，所不同的是两种图像压缩方法不同。</p>
<p>使用ETC1 图像作为Texture的基本方法如下：</p>
<pre class="brush: java; title: ; notranslate">
InputStream input = getResources().openRawResource(R.raw.androids);
...
ETC1Util.loadTexture(GLES10.GL_TEXTURE_2D, 0, 0,
GLES10.GL_RGB, GLES10.GL_UNSIGNED_SHORT_5_6_5, input);
</pre>
<p><a href="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/20120419001.png"><img class="aligncenter size-full wp-image-2989" title="20120419001" src="http://www.imobilebbs.com/wordpress/wp-content/uploads/2012/04/20120419001.png" alt="" width="975" height="800" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.imobilebbs.com/wordpress/?feed=rss2&#038;p=2988</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.imobilebbs.com @ 2012-05-21 23:22:41 -->
