<?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>PocketMagic</title>
	<atom:link href="http://www.pocketmagic.net/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.pocketmagic.net</link>
	<description>Where Technology meets magic</description>
	<lastBuildDate>Sat, 04 Sep 2010 18:10:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Android Dynamic (no xml) Custom Adapter Listview</title>
		<link>http://www.pocketmagic.net/?p=1343</link>
		<comments>http://www.pocketmagic.net/?p=1343#comments</comments>
		<pubDate>Sat, 28 Aug 2010 17:19:14 +0000</pubDate>
		<dc:creator>Radu Motisan</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[adapter]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[listview]]></category>
		<category><![CDATA[onclick]]></category>

		<guid isPermaLink="false">http://www.pocketmagic.net/?p=1343</guid>
		<description><![CDATA[A tutorial on how to build a custom adapter for an Android Listview control, and how to catch the onClick event correctly.
Includes source code.]]></description>
			<content:encoded><![CDATA[<p>The standard controls in Android API are good, they do a decent job and are very configurable. For eg. the standard listview allows a collection of items, provides custom colors, and nice actions like the finger friendly scroll:</p>
<table cellspacing="5" cellpadding="0" border="0">
<tr>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/pocketmagic.net_customadapterexample_1.jpg"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/pocketmagic.net_customadapterexample_1-150x150.jpg" alt="pocketmagic.net_customadapterexample_1" title="pocketmagic.net_customadapterexample_1" width="150" height="150" class="alignnone size-thumbnail wp-image-1345" /></a>
</td>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/pocketmagic.net_customadapterexample_2.jpg"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/pocketmagic.net_customadapterexample_2-150x150.jpg" alt="pocketmagic.net_customadapterexample_2" title="pocketmagic.net_customadapterexample_2" width="150" height="150" class="alignnone size-thumbnail wp-image-1350" /></a></td>
</tr>
</table>
<p>The left picture is a simple listview. The right image shows what we are planning to do in this tutorial.<br />
Simple listview sample code <a href='http://www.pocketmagic.net/wp-content/uploads/2010/08/CustomAdapterExample_simple.zip'>here</a>.</p>
<p>For various purposes, we might want to enrich the look and feel of a listview, to add pictures or other controls, or to better organize the items. There are a few samples available on the Internet, but they all require a static definition of an item, using the row.xml resource. I'm showing a different approach: build the items using only Java code, this is what is called a Dynamic Listview custom adapter, so no XMLs required here.</p>
<p>The idea is to use the standard Listview control, but build a different adapter to define the items.<br />
First, let's focus on the items. Let's say we want each item to contain data regarding a network adapter. This means we'll record the name, the address , a type (maybe for wired/ wireless) . To define these details  a new class is needed: Device.java</p>
<pre class="java">&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Device <span style="color: #66cc66;">&#123;</span>
&nbsp;
	    <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> m_szDeviceName;
	    <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> m_szDeviceAddress;
	    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">int</span> m_nDeviceType;
	    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">int</span> m_nDeviceStatus;
	    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">int</span> m_nDeviceID;
&nbsp;
	    <span style="color: #000000; font-weight: bold;">public</span> Device<span style="color: #66cc66;">&#40;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> deviceName, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> deviceAddress, <span style="color: #993333;">int</span> deviceType, <span style="color: #993333;">int</span> deviceStatus, <span style="color: #993333;">int</span> deviceID <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">m_szDeviceName</span> = deviceName;
	        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">m_szDeviceAddress</span> = deviceAddress;
	        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">m_nDeviceType</span> = deviceType;
	        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">m_nDeviceStatus</span> = deviceStatus;
	        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">m_nDeviceID</span> = deviceID;
	      <span style="color: #66cc66;">&#125;</span>
&nbsp;
	    <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> getDeviceName<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> m_szDeviceName; <span style="color: #66cc66;">&#125;</span>
	    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setDeviceName<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> deviceName<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">m_szDeviceName</span> = deviceName;<span style="color: #66cc66;">&#125;</span>
&nbsp;
	    <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> getDeviceAddress<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #000000; font-weight: bold;">return</span> m_szDeviceAddress;<span style="color: #66cc66;">&#125;</span>
	    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setDeviceAddress<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> deviceAddress<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">m_szDeviceAddress</span> = deviceAddress;<span style="color: #66cc66;">&#125;</span>
&nbsp;
	    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">int</span> getDeviceType<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> m_nDeviceType; <span style="color: #66cc66;">&#125;</span>
	    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setDeviceType<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> deviceType<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">m_nDeviceType</span> = deviceType;<span style="color: #66cc66;">&#125;</span>
&nbsp;
	    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">int</span> getDeviceStatus<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> m_nDeviceStatus; <span style="color: #66cc66;">&#125;</span>
	    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setDeviceStatus<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> deviceStatus<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">m_nDeviceStatus</span> = deviceStatus;<span style="color: #66cc66;">&#125;</span>
&nbsp;
	    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">int</span> getDeviceID<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">return</span> m_nDeviceID; <span style="color: #66cc66;">&#125;</span>
	    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setDeviceID<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> deviceID<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">m_nDeviceID</span> = deviceID;<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>While Device.java defines the DATA for each listview item, we need another class to define the View of each item, meaning that we need to construct the items using standard interface components (imageviews, textviews, etc). For this, we'll be using another class, CustomAdapterView:</p>
<pre class="java">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> CustomAdapterView <span style="color: #000000; font-weight: bold;">extends</span> LinearLayout <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> CustomAdapterView<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AContext+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Context</span></a> context, Device device<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span><span style="color: #66cc66;">&#40;</span> context <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #808080; font-style: italic;">/*setOnClickListener((OnClickListener) context);
		setClickable(true);
		setFocusable(false);*/</span>
		setId<span style="color: #66cc66;">&#40;</span>device.<span style="color: #006600;">getDeviceID</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">//container is a horizontal layer</span>
		setOrientation<span style="color: #66cc66;">&#40;</span>LinearLayout.<span style="color: #006600;">HORIZONTAL</span><span style="color: #66cc66;">&#41;</span>;
		setPadding<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">6</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">//image:params</span>
		LinearLayout.<span style="color: #006600;">LayoutParams</span> Params = <span style="color: #000000; font-weight: bold;">new</span> LinearLayout.<span style="color: #006600;">LayoutParams</span><span style="color: #66cc66;">&#40;</span>LayoutParams.<span style="color: #006600;">WRAP_CONTENT</span>, LayoutParams.<span style="color: #006600;">WRAP_CONTENT</span><span style="color: #66cc66;">&#41;</span>;
		Params.<span style="color: #006600;">setMargins</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">6</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #808080; font-style: italic;">//image:itself</span>
		ImageView ivLogo = <span style="color: #000000; font-weight: bold;">new</span> ImageView<span style="color: #66cc66;">&#40;</span>context<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #808080; font-style: italic;">// load image</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>device.<span style="color: #006600;">getDeviceType</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
			ivLogo.<span style="color: #006600;">setImageDrawable</span><span style="color: #66cc66;">&#40;</span>context.<span style="color: #006600;">getResources</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getDrawable</span><span style="color: #66cc66;">&#40;</span>R.<span style="color: #006600;">drawable</span>.<span style="color: #006600;">logo1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>device.<span style="color: #006600;">getDeviceType</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>
			ivLogo.<span style="color: #006600;">setImageDrawable</span><span style="color: #66cc66;">&#40;</span>context.<span style="color: #006600;">getResources</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getDrawable</span><span style="color: #66cc66;">&#40;</span>R.<span style="color: #006600;">drawable</span>.<span style="color: #006600;">logo2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #808080; font-style: italic;">//image:add</span>
		addView<span style="color: #66cc66;">&#40;</span>ivLogo, Params<span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">//vertical layer for text</span>
		Params = <span style="color: #000000; font-weight: bold;">new</span> LinearLayout.<span style="color: #006600;">LayoutParams</span><span style="color: #66cc66;">&#40;</span>LayoutParams.<span style="color: #006600;">FILL_PARENT</span>, LayoutParams.<span style="color: #006600;">WRAP_CONTENT</span><span style="color: #66cc66;">&#41;</span>;
		LinearLayout PanelV = <span style="color: #000000; font-weight: bold;">new</span> LinearLayout<span style="color: #66cc66;">&#40;</span>context<span style="color: #66cc66;">&#41;</span>;
		PanelV.<span style="color: #006600;">setOrientation</span><span style="color: #66cc66;">&#40;</span>LinearLayout.<span style="color: #006600;">VERTICAL</span><span style="color: #66cc66;">&#41;</span>;
		PanelV.<span style="color: #006600;">setGravity</span><span style="color: #66cc66;">&#40;</span>Gravity.<span style="color: #006600;">BOTTOM</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		TextView textName = <span style="color: #000000; font-weight: bold;">new</span> TextView<span style="color: #66cc66;">&#40;</span> context <span style="color: #66cc66;">&#41;</span>;
		textName.<span style="color: #006600;">setTextSize</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span>;
		textName.<span style="color: #006600;">setTypeface</span><span style="color: #66cc66;">&#40;</span>Typeface.<span style="color: #000000; font-weight: bold;">DEFAULT</span>, Typeface.<span style="color: #006600;">BOLD</span><span style="color: #66cc66;">&#41;</span>;
		textName.<span style="color: #006600;">setText</span><span style="color: #66cc66;">&#40;</span> device.<span style="color: #006600;">getDeviceName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		PanelV.<span style="color: #006600;">addView</span><span style="color: #66cc66;">&#40;</span>textName<span style="color: #66cc66;">&#41;</span>;       
&nbsp;
		TextView textAddress = <span style="color: #000000; font-weight: bold;">new</span> TextView<span style="color: #66cc66;">&#40;</span> context <span style="color: #66cc66;">&#41;</span>;
		textAddress.<span style="color: #006600;">setTextSize</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span>;
		textAddress.<span style="color: #006600;">setText</span><span style="color: #66cc66;">&#40;</span> device.<span style="color: #006600;">getDeviceAddress</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		PanelV.<span style="color: #006600;">addView</span><span style="color: #66cc66;">&#40;</span>textAddress<span style="color: #66cc66;">&#41;</span>;    
&nbsp;
		addView<span style="color: #66cc66;">&#40;</span>PanelV, Params<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>As you can see, this class builds a nice item made out of an imageview, and two lines of text:<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/pocketmagic.net_customadapterexample_12.jpg"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/pocketmagic.net_customadapterexample_12.jpg" alt="pocketmagic.net_customadapterexample_12" title="pocketmagic.net_customadapterexample_12" width="315" height="62" class="alignnone size-full wp-image-1349" /></a></p>
<p>Now we only need to build the Custom Adapter class, that will use the CustomAdapterView private class and implement the getView method:</p>
<pre class="java">&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CustomAdapter <span style="color: #000000; font-weight: bold;">extends</span> BaseAdapter <span style="color: #808080; font-style: italic;">/*implements OnClickListener*/</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/*private class OnItemClickListener implements OnClickListener{
	    private int mPosition;
	    OnItemClickListener(int position){
	            mPosition = position;
	    }
	    public void onClick(View arg0) {
	            Log.v(&quot;ddd&quot;, &quot;onItemClick at position&quot; + mPosition);
	    }
	}*/</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> LOG_TAG = <span style="color: #ff0000;">&quot;BI::CA&quot;</span>;
    <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AContext+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Context</span></a> context;
    <span style="color: #000000; font-weight: bold;">private</span> List&lt;Device&gt; deviceList;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> CustomAdapter<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AContext+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Context</span></a> context, List&lt;Device&gt; deviceList <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">context</span> = context;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">deviceList</span> = deviceList;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">int</span> getCount<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> deviceList.<span style="color: #006600;">size</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AObject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Object</span></a> getItem<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> position<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> deviceList.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span>position<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">long</span> getItemId<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> position<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> position;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AView+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">View</span></a> getView<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> position, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AView+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">View</span></a> convertView, ViewGroup parent<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        Device device = deviceList.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span>position<span style="color: #66cc66;">&#41;</span>;
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AView+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">View</span></a> v = <span style="color: #000000; font-weight: bold;">new</span> CustomAdapterView<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">context</span>, device <span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #808080; font-style: italic;">//v.setBackgroundColor((position % 2) == 1 ? Color.rgb(50,50,50) : Color.BLACK);</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">/*v.setOnClickListener(new OnItemClickListener(position));*/</span>
        <span style="color: #000000; font-weight: bold;">return</span> v;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/*public void onClick(View v) {
            Log.v(LOG_TAG, &quot;Row button clicked&quot;);
    }*/</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>Using these resources it is trivial to build and use a listview. This code in our main example class:</p>
<pre class="java">&nbsp;
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AListView+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">ListView</span></a> ls2 = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AListView+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">ListView</span></a><span style="color: #66cc66;">&#40;</span>context<span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// clear previous results in the LV</span>
ls2.<span style="color: #006600;">setAdapter</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// populate</span>
ArrayList&lt;Device&gt; m_Devices = <span style="color: #000000; font-weight: bold;">new</span> ArrayList&lt;Device&gt;<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
Device device;
<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> i=<span style="color: #cc66cc;">0</span>;i&lt;<span style="color: #cc66cc;">10</span>;i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
   device = <span style="color: #000000; font-weight: bold;">new</span> Device<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Network Device &quot;</span>+i,<span style="color: #ff0000;">&quot;13:B4:5C:0D:AE:67&quot;</span>, i%<span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">100</span> + i<span style="color: #66cc66;">&#41;</span>;
   m_Devices.<span style="color: #006600;">add</span><span style="color: #66cc66;">&#40;</span>device<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
CustomAdapter lvAdapter =  <span style="color: #000000; font-weight: bold;">new</span> CustomAdapter<span style="color: #66cc66;">&#40;</span>context, m_Devices<span style="color: #66cc66;">&#41;</span>;
ls2.<span style="color: #006600;">setAdapter</span><span style="color: #66cc66;">&#40;</span>lvAdapter<span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Creates a simple but nice Listview:<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/pocketmagic.net_customadapterexample_2.jpg"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/pocketmagic.net_customadapterexample_2-150x150.jpg" alt="pocketmagic.net_customadapterexample_2" title="pocketmagic.net_customadapterexample_2" width="150" height="150" class="alignnone size-thumbnail wp-image-1350" /></a></p>
<h4>Get click event on Custom Adapter Listview</h4>
<p>Ok, there are a few ways of handling this.<br />
<b>Method 1</b><br />
In CustomAdapterView constructor, you make each item clickable, set an id (that you can use later to identify the item), and set a click listener (in the main class, using the context):</p>
<pre class="java">&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> CustomAdapterView<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AContext+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Context</span></a> context, Device device<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span><span style="color: #66cc66;">&#40;</span> context <span style="color: #66cc66;">&#41;</span>;
		setOnClickListener<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>OnClickListener<span style="color: #66cc66;">&#41;</span> context<span style="color: #66cc66;">&#41;</span>;
		setClickable<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
		setFocusable<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;
		setId<span style="color: #66cc66;">&#40;</span>device.<span style="color: #006600;">getDeviceID</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		...
&nbsp;</pre>
<p>Then in the main example class you catch the click event:</p>
<pre class="java">&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> onClick<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AView+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">View</span></a> v<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #993333;">int</span> cmdId = v.<span style="color: #006600;">getId</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>cmdId &gt;= <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">//first listview id</span>
		<span style="color: #993333;">int</span> nIndex = cmdId - idLV1FirstItem;
		Log.<span style="color: #006600;">i</span><span style="color: #66cc66;">&#40;</span>LOG_TAG, <span style="color: #ff0000;">&quot;LV2 click &quot;</span>+nIndex <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>This method works good, but it has a major disadvantage: 	because you've used "setClickable", the items will not show any change when clicked: they won't be drawn as "clicked". But you receive the click event.<br />
Another disadvantage is that the listview will not react to key presses (enter) on items.</p>
<p><b>Method 2</b><br />
The correct way of doing this, is to use the setOnItemClickListener method, without setClickable.</p>
<pre class="java">&nbsp;
        ...
        <span style="color: #006600;">ls2</span>.<span style="color: #006600;">setAdapter</span><span style="color: #66cc66;">&#40;</span>lvAdapter<span style="color: #66cc66;">&#41;</span>;
        ls2.<span style="color: #006600;">setOnItemClickListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> OnItemClickListener<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#123;</span>
        	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> onItemClick<span style="color: #66cc66;">&#40;</span>AdapterView&lt;?&gt; arg0, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AView+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">View</span></a> arg1,<span style="color: #993333;">int</span> arg2, <span style="color: #993333;">long</span> arg3<span style="color: #66cc66;">&#41;</span>
        	<span style="color: #66cc66;">&#123;</span>
        		Toast.<span style="color: #006600;">makeText</span><span style="color: #66cc66;">&#40;</span>getBaseContext<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">&quot;You clicked on &quot;</span>+arg2, Toast.<span style="color: #006600;">LENGTH_LONG</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">show</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    		<span style="color: #66cc66;">&#125;</span>
    	<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
        ...
&nbsp;</pre>
<p>This way you have the animation when an item is clicked, and you also get the click event. And it works with key presses as well. All in one, this is the method to use for getting click events on custom adapter listviews.</p>
<h4>Change row colors</h4>
<p>You can have one row of a color, and the next in another color to read the content easier.<br />
In CustomAdapter, method getView, simply use v.setBackgroundColor based on position:</p>
<pre class="java">&nbsp;
        v.<span style="color: #006600;">setBackgroundColor</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>position % <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #cc66cc;">1</span> ? <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AColor+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Color</span></a>.<span style="color: #006600;">GRAY</span> : <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AColor+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Color</span></a>.<span style="color: #006600;">BLACK</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>The result looks like this:<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/pocketmagic.net_customadapterexample_3.jpg"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/pocketmagic.net_customadapterexample_3-150x150.jpg" alt="pocketmagic.net_customadapterexample_3" title="pocketmagic.net_customadapterexample_3" width="150" height="150" class="alignnone size-thumbnail wp-image-1353" /></a></p>
<p>Here is the code for this tutorial:<br />
<a href='http://www.pocketmagic.net/wp-content/uploads/2010/08/CustomAdapterExample_complex.zip'>Custom Adapter Listview Source code, 57KB</a></p>
<p>Hope this helps,</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pocketmagic.net/?feed=rss2&amp;p=1343</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android NDK for Windows setup guide</title>
		<link>http://www.pocketmagic.net/?p=1332</link>
		<comments>http://www.pocketmagic.net/?p=1332#comments</comments>
		<pubDate>Tue, 24 Aug 2010 18:14:11 +0000</pubDate>
		<dc:creator>Radu Motisan</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jni]]></category>
		<category><![CDATA[native code]]></category>
		<category><![CDATA[ndk]]></category>

		<guid isPermaLink="false">http://www.pocketmagic.net/?p=1332</guid>
		<description><![CDATA[See how to configure Android NDK with Windows and build your JNI project in a few easy steps.]]></description>
			<content:encoded><![CDATA[<h4>Introduction</h4>
<p>Since most of the NDK tools are coming from the  Linux environment, that OS was my first approach in building native C applications for Android. See <a href="http://www.pocketmagic.net/?p=682">this tutorial </a>for a start.</p>
<p>However, I also needed to be able to compile JNI Android apps using the Windows environment. It proved an easy task, but there were some issues, so I decided to write this guide.</p>
<h4>Install Android NDK on Windows and use it to compile a JAVA/JNI application</h4>
<p>You will need an internet connection to install Cygwin and the Android SDK automatically from the Internet.</p>
<li><b>1) Download the Android NDK for Windows</b></li>
<p>Download <a href="http://developer.android.com/sdk/ndk/index.html">link</a>.<br />
Current version of the file is: android-ndk-r4b-windows.zip 45MB</p>
<li><b>2) Download Cygwin</b></li>
<p>Download <a href="http://www.cygwin.com/">link</a>. (<a href="http://www.cygwin.com/setup.exe">Direct Link</a>)<br />
Select the mirror you need to download from then follow the installation guide.<br />
On package selection, Open Devel category and check "make":<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/2.1.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/2.1-150x150.jpg" alt="2.1" title="2.1" width="150" height="150" class="alignnone size-thumbnail wp-image-1334" /></a><br />
I've installed it to C:\cygwin</p>
<li><b>3) Download the latest Android SDK for Windows</b></li>
<p>Download <a href="http://developer.android.com/sdk/index.html">link</a>.<br />
Current version is android-sdk_r06-windows.zip 23MB</p>
<li><b>4) Install the SDK</b></li>
<p><b>4.1) Unzip the zip content to a location on your harddisk. I choose:</b><br />
D:\work_code\android\android-sdk-windows\<br />
You will find SDK Setup.exe . Run it. I get a warning to install JAVA JDK<br />
<b>4.2) Download Java JDK</b><br />
Download <a href="http://java.sun.com/javase/downloads/">link</a>.<br />
Select platform "Windows". Current file is: jdk-6u21-windows-i586.exe (<a href=" http://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/VerifyItem-Start/jdk-6u21-windows-i586.exe?BundledLineItemUUID=MoqJ_hCxJqQAAAEq8zEHfaTT&OrderID=h6yJ_hCxd2YAAAEq5zEHfaTT&ProductID=h2iJ_hCyKS4AAAEpVrwzBGsB&FileName=/jdk-6u21-windows-i586.exe">Direct link</a>)<br />
<b>4.3) Install the Java JDK: simply run the exe . It takes a few minutes to complete.</b><br />
<b>4.4) Re-run the SDK Setup.exe from the Android SDK.</b><br />
This opens the Android SDK and AVD Manager. If you get a HTTPS Error:<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/4.5.1.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/4.5.1-150x150.jpg" alt="4.5.1" title="4.5.1" width="150" height="150" class="alignnone size-thumbnail wp-image-1337" /></a><br />
go to Settings and check the "Force https:// ..." checkbox:<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/4.5.2.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/4.5.2-150x150.jpg" alt="4.5.2" title="4.5.2" width="150" height="150" class="alignnone size-thumbnail wp-image-1338" /></a><br />
<b>4.5) Go to Available Packages</b>, select all, and press Install Selected:<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/4.6.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/4.6-150x150.jpg" alt="4.6" title="4.6" width="150" height="150" class="alignnone size-thumbnail wp-image-1339" /></a><br />
The installer will download the packages from the internet, and might prompt you to accept terms, which you must do if you want to continue with the installation. This step takes a few minutes.</p>
<li><b>5) Install the NDK</b></li>
<p><b>5.1) Unzip the NDK zip file</b>. My choice is: D:\work_code\android\android-ndk-r4b\<br />
<b>5.2) Configure Cygwin parameters</b><br />
Go to the Cygwin folder and open Cygwin.bat. It contains something like this:</p>
<pre class="cpp">&nbsp;
@echo off
&nbsp;
C:
chdir C:\cygwin\bin
&nbsp;
bash --login -i
&nbsp;</pre>
<p>Using any text editor change it to:</p>
<pre class="cpp">&nbsp;
@echo off
&nbsp;
set IS_UNIX=
set DEV_ROOT=d:/work_code/android/BlueInput
set JAVA_HOME=c:/Progra~<span style="color: #0000dd;">1</span>/Java/jdk1<span style="color: #0000dd;">.6</span>.0_21
set CLASSPATH=d:/work_code/android/BlueInput/obj
set PATH=D:/work_code/android/android-sdk-windows/tools;D:/work_code/android/android-ndk-r4b
set ANDROID_NDK_ROOT=/cygdrive/d/work_code/android-ndk-r4b
set NDK_PROJECT_PATH=/cygdrive/d/work_code/android/BlueInput
&nbsp;
C:
chdir C:\cygwin\bin
&nbsp;
bash --login -i
&nbsp;</pre>
<p>The path in the config, d:/work_code/android/BlueInput, is something I'm currently working on. Change to your Own project name. The project must be organized  as follows:<br />
A) The JNI part (the .c and .h and Android.mk files) in:<br />
d:/work_code/android/BlueInput/jni<br />
B) The JAVA part (assets,bin,gen,jni,libs,obj,res,src with the .java files) in:<br />
d:/work_code/android/BlueInput<br />
For these paths always use forward slashes.<br />
<b>5.3) Open Cygwin and browse to the NDK folder</b>, using cd <folder name> [enter] :<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/5.4.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/5.4-150x150.jpg" alt="5.4" title="5.4" width="150" height="150" class="alignnone size-thumbnail wp-image-1340" /></a><br />
cd d:/work_code/android-ndk-r4b<br />
<b>5.4) Type ./ndk-build  </b> to compile the JNI project<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/5.5.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/5.5-150x150.jpg" alt="5.5" title="5.5" width="150" height="150" class="alignnone size-thumbnail wp-image-1341" /></a><br />
The C files have been successfully built. Now using Eclipse, you can build the Java android project, and it will include the JNI part automatically. Easy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pocketmagic.net/?feed=rss2&amp;p=1332</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Webcam Surveillance with motion detection algorithm</title>
		<link>http://www.pocketmagic.net/?p=1329</link>
		<comments>http://www.pocketmagic.net/?p=1329#comments</comments>
		<pubDate>Fri, 20 Aug 2010 09:46:10 +0000</pubDate>
		<dc:creator>Radu Motisan</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.pocketmagic.net/?p=1329</guid>
		<description><![CDATA[A homemade/DIY security system using a webcam, a low power server and a surveillance software.]]></description>
			<content:encoded><![CDATA[<p><object width="640" height="505"><param name="movie" value="http://www.youtube.com/v/NEqrZQFIW24?fs=1&amp;hl=en_US&amp;color1=0x3a3a3a&amp;color2=0x999999"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/NEqrZQFIW24?fs=1&amp;hl=en_US&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object></p>
<p>To be continued.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pocketmagic.net/?feed=rss2&amp;p=1329</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WinCE Broadcom stack FindAttribute SDP_DISC_ATTTR_VAL 256Bytes limit</title>
		<link>http://www.pocketmagic.net/?p=1324</link>
		<comments>http://www.pocketmagic.net/?p=1324#comments</comments>
		<pubDate>Fri, 13 Aug 2010 16:44:58 +0000</pubDate>
		<dc:creator>Radu Motisan</dc:creator>
				<category><![CDATA[Research]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows Mobile]]></category>
		<category><![CDATA[256]]></category>
		<category><![CDATA[bluetooth]]></category>
		<category><![CDATA[broadcom]]></category>
		<category><![CDATA[SDP_DISC_ATTTR_VAL]]></category>

		<guid isPermaLink="false">http://www.pocketmagic.net/?p=1324</guid>
		<description><![CDATA[See the real limit for receiving a SDP bluetooth device attribute in the SDP_DISC_ATTTR_VAL structure for the Broadcom Bluetooth Stack.]]></description>
			<content:encoded><![CDATA[<p><b>FindAttribute()</b> is an API part of the Broadcom Bluetooth Stack SDK, that Searches the discovery record for the specified attribute ID and, if found, returns the attribute values to the caller.</p>
<p><b>Prototype</b><br />
BOOL FindAttribute (UINT16 attr_id, SDP_DISC_ATTTR_VAL *p_val);<br />
Parameters<br />
attr_id The attribute ID being searched for.<br />
p_val The location where the function should store the attribute.<br />
Returns TRUE if the attribute was found. FALSE otherwise.</p>
<p>The structure SDP_DISC_ATTTR_VAL is defined in BtIfDefinitions.h. as following:</p>
<pre class="cpp">&nbsp;
<span style="color: #339900;">#define MAX_SEQ_ENTRIES     20</span>
<span style="color: #339900;">#define MAX_ATTR_LEN        256</span>
&nbsp;
<span style="color: #0000ff;">typedef</span> <span style="color: #0000ff;">struct</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0000ff;">int</span>     num_elem;
&nbsp;
    <span style="color: #0000ff;">struct</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #339900;">#define ATTR_TYPE_INT      0       // Attribute value is an integer</span>
        <span style="color: #339900;">#define ATTR_TYPE_TWO_COMP 1       // Attribute value is an 2's complement integer</span>
        <span style="color: #339900;">#define ATTR_TYPE_UUID     2       // Attribute value is a UUID</span>
        <span style="color: #339900;">#define ATTR_TYPE_BOOL     3       // Attribute value is a boolean</span>
        <span style="color: #339900;">#define ATTR_TYPE_ARRAY    4       // Attribute value is an array of bytes</span>
&nbsp;
        <span style="color: #0000ff;">int</span>     type;
        <span style="color: #0000ff;">int</span>     len;                        <span style="color: #ff0000;">// Length of the attribute</span>
        <span style="color: #0000ff;">BOOL</span>    start_of_seq;               <span style="color: #ff0000;">// TRUE for each start of sequence</span>
        <span style="color: #0000ff;">union</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">char</span>  u8;                      <span style="color: #ff0000;">// 8-bit integer</span>
            <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">short</span> u16;                     <span style="color: #ff0000;">// 16-bit integer</span>
            <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">long</span>  u32;                     <span style="color: #ff0000;">// 32-bit integer</span>
            <span style="color: #0000ff;">BOOL</span>           b;                       <span style="color: #ff0000;">// Boolean</span>
            <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">char</span>  array<span style="color: #000000;">&#91;</span>MAX_ATTR_LEN<span style="color: #000000;">&#93;</span>;     <span style="color: #ff0000;">// Variable length array</span>
        <span style="color: #000000;">&#125;</span> val;
&nbsp;
    <span style="color: #000000;">&#125;</span> elem <span style="color: #000000;">&#91;</span>MAX_SEQ_ENTRIES<span style="color: #000000;">&#93;</span>;
&nbsp;
<span style="color: #000000;">&#125;</span> SDP_DISC_ATTTR_VAL;
&nbsp;</pre>
<p>As you can see the "array" member of the union can only take 256bytes. The SDK has a note:</p>
<blockquote><p>the structure allows for an attribute that is a sequence of up to MAX_SEQ_ENTRIES (=20), each with a value array up to MAX_ATTR_LEN (=256) bytes long. Nested sequences up to 5 levels deep are supported.</p></blockquote>
<p>Assuming you need to retrieve an attribute that is bigger then 256 bytes, the first 256 bytes will be stored in elem[i].var.array and the following bytes in &elem[i+1], &elem[i+2], and so on.<br />
Please note that the first set of 256 bytes is stored in elem[i].var.array, but for the rest, the whole elem structure is used, meaning you will have 268bytes (type, len and  start_of_seq are included).</p>
<p>A quick calculation shows you can receive an attribute consisting of an array of maximum: 256+19*268bytes.</p>
<p>Good thing there is a way of getting more then 256 bytes!</p>
<pre class="cpp">&nbsp;
BYTE *pRDData = <span style="color: #000000;">&#40;</span>BYTE *<span style="color: #000000;">&#41;</span><span style="color: #0000dd;">malloc</span><span style="color: #000000;">&#40;</span>MAX_RD_SIZE * <span style="color: #0000dd;">sizeof</span><span style="color: #000000;">&#40;</span>BYTE<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #0000dd;">memset</span><span style="color: #000000;">&#40;</span>pRDData,<span style="color: #0000dd;">0</span>,MAX_RD_SIZE * <span style="color: #0000dd;">sizeof</span><span style="color: #000000;">&#40;</span>BYTE<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
nRDSize = p_val.<span style="color: #00eeff;">elem</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #00eeff;">len</span>;
<span style="color: #0000ff;">if</span> <span style="color: #000000;">&#40;</span>nRDSize &lt; MAX_ATTR_LEN<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0000dd;">memcpy</span><span style="color: #000000;">&#40;</span>pRDData, p_val.<span style="color: #00eeff;">elem</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #00eeff;">val</span>.<span style="color: #00eeff;">array</span>, nRDSize<span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #000000;">&#125;</span>
<span style="color: #0000ff;">else</span>
<span style="color: #000000;">&#123;</span>
	BYTE nBlocks = <span style="color: #0000dd;">0</span>;
	<span style="color: #0000dd;">memcpy</span><span style="color: #000000;">&#40;</span>pRDData, p_val.<span style="color: #00eeff;">elem</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #00eeff;">val</span>.<span style="color: #00eeff;">array</span>, MAX_ATTR_LEN<span style="color: #000000;">&#41;</span>;
	nBlocks++; <span style="color: #ff0000;">//we've just copied the first block</span>
	<span style="color: #0000ff;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #0000ff;">int</span> j=<span style="color: #0000dd;">0</span>;j&lt;nRDSize / MAX_ATTR_LEN;j++<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0000dd;">memcpy</span><span style="color: #000000;">&#40;</span>pRDData + nBlocks*MAX_ATTR_LEN, &amp;p_val.<span style="color: #00eeff;">elem</span><span style="color: #000000;">&#91;</span>i+nBlocks<span style="color: #000000;">&#93;</span>, MAX_ATTR_LEN<span style="color: #000000;">&#41;</span>;
		nBlocks++; <span style="color: #ff0000;">//another block has been copied</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0000dd;">memcpy</span><span style="color: #000000;">&#40;</span>pRDData + nBlocks*MAX_ATTR_LEN, &amp;p_val.<span style="color: #00eeff;">elem</span><span style="color: #000000;">&#91;</span>i+nBlocks<span style="color: #000000;">&#93;</span>, nRDSize % MAX_ATTR_LEN<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.pocketmagic.net/?feed=rss2&amp;p=1324</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kvarts DRSB-01 Dosimeter</title>
		<link>http://www.pocketmagic.net/?p=1305</link>
		<comments>http://www.pocketmagic.net/?p=1305#comments</comments>
		<pubDate>Wed, 11 Aug 2010 20:22:56 +0000</pubDate>
		<dc:creator>Radu Motisan</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[High Voltage]]></category>
		<category><![CDATA[Nuclear]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[dosimeter]]></category>
		<category><![CDATA[geiger counter]]></category>

		<guid isPermaLink="false">http://www.pocketmagic.net/?p=1305</guid>
		<description><![CDATA[The DRSB-01 is a simple Geiger Counter device that can be used to detect normal vs. dangerous levels of ionizing radiation (gamma and beta).]]></description>
			<content:encoded><![CDATA[<p>The DRSB-01 is a Geiger Counter that gives audible (clicks) and visible indications (a green led and a red led) when  elevated levels of radioactivity are detected: ionizing gamma rays and hard beta-rays.<br />
You can use it to check the presence of ionizing radiation and get an idea on the dose (based on the frequency of clicks), but this device is not capable of doing any precise measurements.<br />
A very simple example of a radiation dosimeter, can be used to learn the basic radiation detection principles: a Geiger-Muller tube, a small power source, an inverter, and a detector circuit, connected to the led and the speaker.<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/P1070986.jpg"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/P1070986-300x225.jpg" alt="P1070986" title="P1070986" width="300" height="225" class="alignnone size-medium wp-image-1307" /></a><br />
<br></p>
<table cellspacing="0" cellpadding="5" border="1">
<tr>
<td valign="top">Scale range ambient dose rate equivalent:</td>
<td valign="top">0.003 ... 0.6 μSv/h</td>
</tr>
<tr>
<td valign="top">Range of registered energy</td>
<td valign="top">1) gamma radiation, unknown<br>2) X-ray radiation, unknown<br>3) beta radiation, unknown<br>4) alpha radiation, not detected</td>
</tr>
<tr>
<td valign="top">Time of calculations</td>
<td valign="top">Instant</td>
</tr>
<tr>
<td valign="top">Time of indication </td>
<td valign="top">continuous</td>
</tr>
<tr>
<td valign="top">Power elements</td>
<td valign="top">2 AA batteries</td>
</tr>
<tr>
<td valign="top">Overall dimensions</td>
<td valign="top">150x65x21 mm</td>
</tr>
<tr>
<td valign="top">Weight (w/o batteries)</td>
<td valign="top">0.125 KG</td>
</tr>
</table>
<p>It is bigger then my <a href="http://www.pocketmagic.net/?p=1200">Radex 1706</a> or the <a href="http://www.pocketmagic.net/?p=1104">Terra-P MKS 05</a>, but smaller then the <a href="http://www.pocketmagic.net/?p=1223">CDV 700</a> or the CDV 717.</p>
<p>The dosimeter is intended for use at temperatures from -10°C to 40 °C, relative humidity up to 80%, normal atmospheric pressure (650-800 mm Hg).  Dampness will interfere with its high voltage generating circuit.  Keep the radiation dosimeter clean and protect it from impact, dampness, and harsh environments.<br />
One set of batteries will operate the radiation dosimeter continuously for at least 100 hours under natural background radiation conditions.<br />
It came with two pages of instructions, you can see them here: <a href='http://www.pocketmagic.net/wp-content/uploads/2010/08/DRSB-01.pdf'>DRSB instructions</a>.</p>
<p>My <a href="http://www.pocketmagic.net/?p=292">uranium glass marbles</a>, give higher-than-background clicks, and the green led lights frequently:<br />
<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/G4TDucm5p50&amp;hl=en_US&amp;fs=1?color1=0x3a3a3a&amp;color2=0x999999"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/G4TDucm5p50&amp;hl=en_US&amp;fs=1?color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></p>
<p>The CHECK Source DU on the <a href="http://www.pocketmagic.net/?p=1223">CDV 700</a> casing, brings the RED led on:<br />
<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/4_l87uRMnLo&amp;hl=en_US&amp;fs=1?color1=0x3a3a3a&amp;color2=0x999999"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/4_l87uRMnLo&amp;hl=en_US&amp;fs=1?color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></p>
<p>As I said, this is a very simple Geiger Counter device. You can see the schematics here:<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/drsb.jpg"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/drsb-300x230.jpg" alt="drsb" title="drsb" width="300" height="230" class="alignnone size-medium wp-image-1319" /></a></p>
<p>I plan to add a Microcontroller and an LCD to "enhance" this dosimeter. But more on that later!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pocketmagic.net/?feed=rss2&amp;p=1305</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache won&#8217;t start &#8211; Skype to blame!</title>
		<link>http://www.pocketmagic.net/?p=1298</link>
		<comments>http://www.pocketmagic.net/?p=1298#comments</comments>
		<pubDate>Tue, 10 Aug 2010 10:25:01 +0000</pubDate>
		<dc:creator>Radu Motisan</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[port 80 conflict]]></category>
		<category><![CDATA[skype]]></category>

		<guid isPermaLink="false">http://www.pocketmagic.net/?p=1298</guid>
		<description><![CDATA[Skype opens the TCP port 80 for unknown purposes. It doesn't ask for user's permission. This "feature" however creates problems when running legitimate software like an apache server. Think twice when installing "bells and whistles" software like Skype, Messengers, and others.]]></description>
			<content:encoded><![CDATA[<p>From time to time I use a local Apache/php server. Now my idea was to design a function to compute a score for a particular text string based on an algorithm I'm designing. This score would help decide whether the text is a valid human Name, or is just a spam-bot nickname. </p>
<p>Currently I have <a href="http://www.wampserver.com/en/">WAMP </a>installed. Extremely lightweight application, this package brings everything you together: apache, php, mysql and a nice control panel interface.</p>
<p>I was surprised to see the server will not start. Also the status ICON was showing that the server is off, despite my attempts of restarting it. All I was getting in my browser was an empty page. But the browser seemed to be connecting to something (no connection error):<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/skype2.jpg"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/skype2-150x150.jpg" alt="skype2" title="skype2" width="150" height="150" class="alignnone size-thumbnail wp-image-1299" /></a></p>
<p>Intrigued since I was aware of no "server" running on my machine, I used netstat to see a list of open ports and the PIDs of the processes using them: </p>
<pre class="cpp">&nbsp;
netstat -anop TCP
&nbsp;</pre>
<p>Here are the results:<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/skype.jpg"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/skype-300x91.jpg" alt="skype" title="skype" width="300" height="91" class="alignnone size-medium wp-image-1302" /></a></p>
<p>As you can see Skype was holding the port 80 open! Why? How? I never acknowledged this when I installed Skype! So I quit Skype and probably will be uninstalling it too. For now, no more Skype Autostart, that's for sure. </p>
<p>Killing Skype solves the problem immediately:<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/skype4.jpg"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/skype4-150x150.jpg" alt="skype4" title="skype4" width="150" height="150" class="alignnone size-thumbnail wp-image-1303" /></a></p>
<p>You draw the conclusion. It would be a good idea to think twice when installing "bells and whistles" software like Skype, Messengers, and others.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pocketmagic.net/?feed=rss2&amp;p=1298</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Homemade mini-itx server</title>
		<link>http://www.pocketmagic.net/?p=1277</link>
		<comments>http://www.pocketmagic.net/?p=1277#comments</comments>
		<pubDate>Sun, 08 Aug 2010 16:30:07 +0000</pubDate>
		<dc:creator>Radu Motisan</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[case]]></category>
		<category><![CDATA[mini-itx]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.pocketmagic.net/?p=1277</guid>
		<description><![CDATA[See how to build a case for a mini-itx computer board. A lot of processing power in a tiny box.]]></description>
			<content:encoded><![CDATA[<p>I had an unused mini-itx motherboard, left from my Perseus-2 robot project:<br />
http://www.pocketmagic.net/?p=520</p>
<p>The specs are:<br />
Mini ITX D201GLY2 motherboard<br />
1.3GHz Celeron CPU<br />
512MB RAM<br />
IDE2CF and CF2SDCard adaptors for a 2GB SDCard based DOC (disk on chip)<br />
M2-ATX DC-DC PC power supply 160W,  so I can power the board using 12-24V DC.</p>
<p>The idea was to build a case and add a big 320GB harddrive. See what I managed to come up with:</p>

<a href='http://www.pocketmagic.net/?attachment_id=1279' title='IMG_8184'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8184-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8184" /></a>
<a href='http://www.pocketmagic.net/?attachment_id=1280' title='IMG_8185'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8185-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8185" /></a>
<a href='http://www.pocketmagic.net/?attachment_id=1281' title='IMG_8186'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8186-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8186" /></a>
<a href='http://www.pocketmagic.net/?attachment_id=1282' title='IMG_8187'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8187-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8187" /></a>
<a href='http://www.pocketmagic.net/?attachment_id=1283' title='IMG_8188'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8188-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8188" /></a>
<a href='http://www.pocketmagic.net/?attachment_id=1284' title='IMG_8189'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8189-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8189" /></a>
<a href='http://www.pocketmagic.net/?attachment_id=1285' title='IMG_8190'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8190-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8190" /></a>
<a href='http://www.pocketmagic.net/?attachment_id=1286' title='IMG_8191'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8191-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8191" /></a>
<a href='http://www.pocketmagic.net/?attachment_id=1287' title='IMG_8192'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8192-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8192" /></a>
<a href='http://www.pocketmagic.net/?attachment_id=1288' title='IMG_8193'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8193-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8193" /></a>
<a href='http://www.pocketmagic.net/?attachment_id=1289' title='IMG_8194'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8194-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8194" /></a>
<a href='http://www.pocketmagic.net/?attachment_id=1290' title='IMG_8195'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8195-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8195" /></a>
<a href='http://www.pocketmagic.net/?attachment_id=1291' title='IMG_8196'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8196-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8196" /></a>
<a href='http://www.pocketmagic.net/?attachment_id=1292' title='IMG_8197'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8197-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8197" /></a>
<a href='http://www.pocketmagic.net/?attachment_id=1293' title='IMG_8198'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8198-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8198" /></a>
<a href='http://www.pocketmagic.net/?attachment_id=1294' title='IMG_8199'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8199-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8199" /></a>
<a href='http://www.pocketmagic.net/?attachment_id=1295' title='IMG_8200'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8200-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8200" /></a>
<a href='http://www.pocketmagic.net/?attachment_id=1278' title='IMG_8201'><img width="150" height="150" src="http://www.pocketmagic.net/wp-content/uploads/2010/08/IMG_8201-150x150.jpg" class="attachment-thumbnail" alt="" title="IMG_8201" /></a>

<p>The server works good, for various purposes, from file storage to permanent internet clients, and the connectivity is easily assured with a USB-WLAN card. To administrate it I use a VNC software.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pocketmagic.net/?feed=rss2&amp;p=1277</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Peltier thermo-electric cooler</title>
		<link>http://www.pocketmagic.net/?p=1269</link>
		<comments>http://www.pocketmagic.net/?p=1269#comments</comments>
		<pubDate>Sun, 08 Aug 2010 12:22:47 +0000</pubDate>
		<dc:creator>Radu Motisan</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[cold]]></category>
		<category><![CDATA[peltier]]></category>
		<category><![CDATA[TEC]]></category>
		<category><![CDATA[thermo electric cooler]]></category>

		<guid isPermaLink="false">http://www.pocketmagic.net/?p=1269</guid>
		<description><![CDATA[Use a Peltier cooler and electricity of pump heat and freeze water.]]></description>
			<content:encoded><![CDATA[<p>"The thermoelectric effect is the direct conversion of temperature  differences to electric voltage and vice versa. A thermoelectric device creates a voltage when there is a different temperature on each side. Conversely when a voltage is applied to it, it creates a temperature difference (known as the Peltier effect). At atomic scale (specifically, charge carriers), an applied temperature gradient causes charged carriers in the material, whether they are electrons or electron holes, to diffuse from the hot side to the cold side, similar to a classical gas that expands when heated; hence, the thermally induced current.</p>
<p>This effect can be used to generate electricity, to measure temperature, to cool objects, or to heat them or cook them. Because the direction of heating and cooling is determined by the sign of the applied voltage, thermoelectric devices make very convenient temperature controllers." <a href="http://en.wikipedia.org/wiki/Thermoelectric_effect">Source</a>.</p>
<p>I  recently got a 150W peltier element on Ebay:<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/P1030979.jpg"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/P1030979-150x150.jpg" alt="P1030979" title="P1030979" width="150" height="150" class="alignnone size-thumbnail wp-image-1270" /></a><br />
The parameters are:<br />
- Operating voltage: 0 - 15V DC<br />
- Current: 0 - 10 Amps<br />
- Temperature interval: -60°C to 180°C </p>
<p>This device works like a heat pump: it has two sides, the cold and the hot. Between these sides there are several thermo couples. All those thermo couples are interconnected and to the two wires that comes out. If voltage is applied, the heat is transferred from the cold side to the hot one.</p>
<p>The device does not "generate" heat nor cold, it just transfers heat. It is also called a thermo-electric cooler or TEC for short.</p>
<p>Because of the internal proximity, a part of the pumped heat can radiate back to the cold side. So the temperature difference is limited. Sometimes it can reach a temperature difference of 80 degrees Celsius.</p>
<p>As indicated in the datasheet, when applying DC 12V, one side becomes cold and one very hot, but the heat radiates and in a few moments the side that should be cold receives heat as well.<br />
To maintain the cold side, the heat must be evacuated from the TEC hot side.<br />
Theoretically with an ideal heat-evacuation system, I should be able to bring the cold side down to -60°C (room temperature ~ 22°C - 80°C ~= -60°C).</p>
<p>So for a start, I've added a heatsink:</p>
<table cellspacing="0" cellpadding="5" border="0">
<tr>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/P1030980.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/P1030980-150x150.jpg" alt="P1030980" title="P1030980" width="150" height="150" class="alignnone size-thumbnail wp-image-1271" /></a></td>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/P1030985.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/P1030985-150x150.jpg" alt="P1030985" title="P1030985" width="150" height="150" class="alignnone size-thumbnail wp-image-1272" /></a></td>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/08/P1030986.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/08/P1030986-150x150.jpg" alt="P1030986" title="P1030986" width="150" height="150" class="alignnone size-thumbnail wp-image-1273" /></a></td>
</tr>
</table>
<p>I've also used Thermal Grease for a better thermal contact of the TEC and the heatsink.</p>
<p>To improve the results even further, the heatsink has been merged in a volume of cold water. By doing so , the lowest temperature I got was -3.0°C, and I was able to instantly freeze a few drops of water placed directly on the cold side of the TEC. See this video, I've added a thermometer to observe the temperature evolution:<br />
<object width="640" height="505"><param name="movie" value="http://www.youtube.com/v/6Jpo41Fh1tA&amp;hl=en_US&amp;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/6Jpo41Fh1tA&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pocketmagic.net/?feed=rss2&amp;p=1269</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WinCE Bluetooth Broadcom stack &#8216;Not a valid Pocket PC application&#8217; Error</title>
		<link>http://www.pocketmagic.net/?p=1261</link>
		<comments>http://www.pocketmagic.net/?p=1261#comments</comments>
		<pubDate>Thu, 22 Jul 2010 11:49:30 +0000</pubDate>
		<dc:creator>Radu Motisan</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows Mobile]]></category>
		<category><![CDATA[bluetooth]]></category>
		<category><![CDATA[broadcom]]></category>
		<category><![CDATA[critical error]]></category>
		<category><![CDATA[IsStackServerUp]]></category>

		<guid isPermaLink="false">http://www.pocketmagic.net/?p=1261</guid>
		<description><![CDATA[Some details on the 'Not a valid Pocket PC application' error resulting from calling the IsStackServerUp API in Windows Mobile Bluetooth Broadcom stack applications.]]></description>
			<content:encoded><![CDATA[<p>The current Windows Mobile Bluetooth Broadcom stack SDK comes with two libs that can be used:<br />
BtSdkCE50.lib and BtSdkCE30.lib</p>
<p>The BtSdkCE50 is compiled for THUMB while BtSdkCE30 is for ARM.</p>
<p>You'll need BtSdkCE50 if you're planning to use:<br />
GetBTWCEVersionInfo, AddServiceName, SetSecurityLevel and other APIs.</p>
<p>So because of the need to use these functions it is almost compulsory to link your Bluetooth application with parameter machine:THUMB . Unless you can go with what BtSdkCE30 has to offer, only.</p>
<p>An even bigger issue is with a set of functions, out of which I've identified: IsDeviceConnectable and IsStackServerUp. Simply calling any of these , results in "Not a valid Pocket PC application" critical error message, before the application has any chance to start:<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/Wince-Broadcom-Stack-error-1.jpg"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/Wince-Broadcom-Stack-error-1-150x150.jpg" alt="Wince Broadcom Stack error 1" title="Wince Broadcom Stack error 1" width="150" height="150" class="alignnone size-thumbnail wp-image-1263" /></a></p>
<p>It makes no difference if only BtSdkCE30 or BtSdkCE50 or both are included. For some reason the resulting linked code is invalid. This behavior has been tested on several Windows Mobile devices, ranging from WM4.0 to WM6.5.</p>
<p>The code that results in this error is plain simple:<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/Wince-Broadcom-Stack-error-2.jpg"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/Wince-Broadcom-Stack-error-2-300x46.jpg" alt="Wince Broadcom Stack error 2" title="Wince Broadcom Stack error 2" width="300" height="46" class="alignnone size-medium wp-image-1264" /></a></p>
<p>Not sure how to fix this, and unfortunately despite the high popularity of the Broadcom stack among newer devices, there is little documentation available to developers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pocketmagic.net/?feed=rss2&amp;p=1261</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Victoreen CDV700 6B Dosimeter Mod (Audio/BNC Connector)</title>
		<link>http://www.pocketmagic.net/?p=1223</link>
		<comments>http://www.pocketmagic.net/?p=1223#comments</comments>
		<pubDate>Tue, 20 Jul 2010 16:46:06 +0000</pubDate>
		<dc:creator>Radu Motisan</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[High Voltage]]></category>
		<category><![CDATA[Nuclear]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[audio mod]]></category>
		<category><![CDATA[bnc mod]]></category>
		<category><![CDATA[cdv700]]></category>
		<category><![CDATA[dosimeter]]></category>
		<category><![CDATA[geiger counter]]></category>

		<guid isPermaLink="false">http://www.pocketmagic.net/?p=1223</guid>
		<description><![CDATA[The CDV700 dosimeter variant 6B (newer) and a few mods to improve functionality: audio connector and bnc connector.]]></description>
			<content:encoded><![CDATA[<p><a href="http://stores.ebay.com/bnkesales">I got a nice CDV700</a> today, the newer model that uses 4xLR20 (D) 1.5V Batteries . </p>
<blockquote><p>"CD-V700 radiation survey meter is a sensitive low-range instrument that can be used to measure gamma radiation and detect  beta radiation. It is recommended for (1) monitoring of personnel, food and water when used in a shielded facility or an area of low radiation background, and (2) follow-up monitoring or areas for human habitation and food production. The instrument is also used in training programs where low radiation dose rates are encountered. "</p></blockquote>
<p><em>(From Radiological Defense Planning & Operations Guide SM-11.23.2 Revised March 1967)</em></p>
<p>The case was a bit scratched, but checking the Counter with the left side Radioactive source, showed 0.22mR/h on the 10X Scale meaning 2.2mR/h, so good to see it is still calibrated and working correctly.<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070802.jpg"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070802-150x150.jpg" alt="P1070802" title="P1070802" width="150" height="150" class="alignnone size-thumbnail wp-image-1224" /></a><br />
The emissions of the Check Source were double checked with a modern <a href="http://www.pocketmagic.net/?p=1200">Radex 1706 dosimeter</a>, details that can be seen in the picture above 2.46uSv = 0.246mR (because 1mRem = 10uSv).</p>
<p>Good thing to have a Radioactive Check Source, however I prefer to keep dangerous things away, so my idea was to cover the Check Source area with a Lead Shield. <a href="http://www.orau.org/ptp/collection/civildefense/checksources.htm">An online article</a>, indicated the check source for this model (Victoreen CDV700 6B) is Depleted Uranium and the emissions are as follows:</p>
<blockquote><p>
Depleted uranium consists primarily of the radionuclides uranium-238 (with a half-life of 4.5 billion years), thorium-234 (with a half-life of 24 days), and protactinium-234m (with a half-life of one minute). There is also a small quantity of uranium-235 present (about 2% of the activity of the U-238), and an even smaller quantity of uranium-234. Like a Ra DEF source, a DU source emits two beta particles for every alpha. The most prominent gamma rays emitted by DU are at 63 keV (thorium-234), 93 keV (thorium-234), 186 keV (uranium-235) and 1001 keV (protactinium-234m).</p></blockquote>
<p>At 5 cm away, the DU source still produces a 0.20uSV indication on the Radex 1706, that would be 0.1mRem.<br />
Should see if the radiant energy calculations correspond to these numbers.<br />
<a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/CDV700-RD1706.jpg"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/CDV700-RD1706-150x150.jpg" alt="CDV700 RD1706" title="CDV700 RD1706" width="150" height="150" class="alignnone size-thumbnail wp-image-1227" /></a><br />
<br><br></p>
<h4>Shielding the Check Source</h4>
<p>I want the Check Source but only for  a few tests. So I decided to cover it with a Lead Shield. First, I had to melt a few small pieces of Lead and have everything in a nice plate shape, good to put in front of the DU.<br />
I used a small aluminum foil  recipient to host the melted lead (since aluminum has a higher melting point) , my butane torch (that can give > 1000° C) and a screw driver to mix the content:</p>
<table cellspacing="0" cellpadding="5" border="0">
<tr>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070810.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070810-150x150.jpg" alt="P1070810" title="P1070810" width="150" height="150" class="alignnone size-thumbnail wp-image-1229" /></a></td>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070811.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070811-150x150.jpg" alt="P1070811" title="P1070811" width="150" height="150" class="alignnone size-thumbnail wp-image-1230" /></a></td>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070813.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070813-150x150.jpg" alt="P1070813" title="P1070813" width="150" height="150" class="alignnone size-thumbnail wp-image-1231" /></a></td>
</tr>
<tr>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/snapshot20100720185536.jpg"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/snapshot20100720185536-150x150.jpg" alt="snapshot20100720185536" title="snapshot20100720185536" width="150" height="150" class="alignnone size-thumbnail wp-image-1233" /></a></td>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/DSC_0004.jpg"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/DSC_0004-150x150.jpg" alt="DSC_0004" title="DSC_0004" width="150" height="150" class="alignnone size-thumbnail wp-image-1234" /></a></td>
<td></td>
</tr>
</table>
<p>I placed this Lead Shield over the Check Source area and the radiation was completely blocked.</p>
<h4>The Audio Connector Mod</h4>
<p>The CDV700 6B has a built in audio connector, but it is old and unusable. So I took it off and simply connected a modern 3.5mm audio jack so I could plug in any headset currently available.</p>
<table cellspacing="0" cellpadding="5" border="0">
<tr>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070825.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070825-150x150.jpg" alt="P1070825" title="P1070825" width="150" height="150" class="alignnone size-thumbnail wp-image-1238" /></a></td>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070826.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070826-150x150.jpg" alt="P1070826" title="P1070826" width="150" height="150" class="alignnone size-thumbnail wp-image-1239" /></a></td>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070827.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070827-150x150.jpg" alt="P1070827" title="P1070827" width="150" height="150" class="alignnone size-thumbnail wp-image-1240" /></a></td>
</tr>
</table>
<p>And it works! <img src='http://www.pocketmagic.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h4>The BNC Connector Mod</h4>
<p>The Geiger Muller probe is connected to the CDV 700 via a coaxial cable. However this cable is directly connected to the device and cannot be unplugged.<br />
My idea was to add a BNC connector so I could disconnect the probe or connect other probes easy.<br />
After removing the cable, directly soldered to the circuit board of the CDV700, I had to drill a hole and force-insert the BNC connector. On the loose cable I added the corresponding connector as well.<br />
Here's the result:</p>
<table cellspacing="0" cellpadding="5" border="0">
<tr>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070829.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070829-150x150.jpg" alt="P1070829" title="P1070829" width="150" height="150" class="alignnone size-thumbnail wp-image-1241" /></a></td>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070833.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070833-150x150.jpg" alt="P1070833" title="P1070833" width="150" height="150" class="alignnone size-thumbnail wp-image-1242" /></a></td>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070835.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070835-150x150.jpg" alt="P1070835" title="P1070835" width="150" height="150" class="alignnone size-thumbnail wp-image-1243" /></a></td>
</tr>
</table>
<p>A quick test shows there are no signal losses and everything runs good as before.</p>
<p><br><br></p>
<h4>The result</h4>
<table cellspacing="0" cellpadding="5" border="0">
<tr>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070842.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070842-150x150.jpg" alt="P1070842" title="P1070842" width="150" height="150" class="alignnone size-thumbnail wp-image-1244" /></a></td>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070846.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070846-150x150.jpg" alt="P1070846" title="P1070846" width="150" height="150" class="alignnone size-thumbnail wp-image-1245" /></a></td>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070847.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070847-150x150.jpg" alt="P1070847" title="P1070847" width="150" height="150" class="alignnone size-thumbnail wp-image-1246" /></a></td>
</tr>
</table>
<p>The last picture shows the CDV717 , a Huge dosimeter based on a ionization chamber, that is unfortunately calibrated for enormous amounts of radiation , making it useless for my experiments. Someone said the CDV717 actually measures how dead you already are, a good joke indeed.</p>
<p>The schematics for the CDV700 and a few circuit pics are attached below:</p>
<table cellspacing="0" cellpadding="5" border="0">
<tr>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070815.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070815-150x150.jpg" alt="P1070815" title="P1070815" width="150" height="150" class="alignnone size-thumbnail wp-image-1250" /></a></td>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070816.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070816-150x150.jpg" alt="P1070816" title="P1070816" width="150" height="150" class="alignnone size-thumbnail wp-image-1251" /></a></td>
<td><a href="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070817.JPG"><img src="http://www.pocketmagic.net/wp-content/uploads/2010/07/P1070817-150x150.jpg" alt="P1070817" title="P1070817" width="150" height="150" class="alignnone size-thumbnail wp-image-1252" /></a></td>
</tr>
</table>
<p>According to <a href="http://radiation.fallout.cz/htm/700.htm">this source</a>:</p>
<blockquote><p>Various ,,6993" Geiger-Müller Tubes were used in the CD V-700 (Anton, Lionel, Victoreen, EON). Only the Chatham CD V-700 model 3 uses an Amperex 85NB / 6980. These GM tubes need 900 Volts to work and they are filled with Halogen gas. Instrument accuracy on any of its three ranges is within ± 10% of the true dose rate from Cobalt 60 gamma radiation. This accuracy is maintained throughout a temperature range of -28° C to +51° C, and  at altitudes from sea level to 7600 meters. The CD V-700 used also a headset (4000 Ohm) for audible detection of radiation. The newest models produced were the 6Bs</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.pocketmagic.net/?feed=rss2&amp;p=1223</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
