Testing Sanity

The core task of software development is sanity testing.

Posted by cgp

So, now that I've got my firmware up to date, I'm ready to hookup the touchscreen to my Android device. The hardware manufacturer doesn't seem to have done any work to get it ready to work with Android, so I'm going to end up doing some of that manually. I hooked up the monitor via a powered USB hub. We hope to use it in the kitchen for the kids to keep track of chores and todo's etc. We'll see how well it ends up being used.

So, in the input Android documentation it gives you the following hint:

The input system is part of the window manager. To dump its state, run the following command:

  adb shell su -- dumpsys window >e:\shell_dump.txt 

It states you should end up with some lines that look like:

...
Event Hub State:
  BuiltInKeyboardId: -1
  Devices:
    3: tuna-gpio-keypad
...
    5: Tuna Headset Jack
...

This didn't end up being the case for me. My output ended up being mostly all about -- well, windows. (see attachment)

Getevent is very helpful

So, I dug around a little more and found Getevent, which was exactly what I was looking for. In particular, in the section "Showing Device Capabilities", there is the command:

adb shell su -- getevent -p

This gave me what I was looking for:

add device 1: /dev/input/event4
  name:     "USBest Technology SiS HID Touch Controller"
  events:
    KEY (0001): 014a 
    ABS (0003): 0000  : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                0001  : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0

So, now I knew the internal touchscreen controller on the monitor. This will provide excellent fodder for seeing if others have setup a similar controller for Android or Ubuntu etc... 

There is even more information to be had on the same page. I can get the human readable labels for event which will end up getting used if I log the output:

adb shell su -- getevent -lp /dev/input/event1

which yields:

add device 1: /dev/input/event4
  name:     "USBest Technology SiS HID Touch Controller"
  events:
    KEY (0001): BTN_TOUCH            
    ABS (0003): ABS_X                 : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                ABS_Y                 : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                ABS_Z                 : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                ABS_RX                : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                ABS_RY                : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                ABS_RZ                : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                ABS_THROTTLE          : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                ABS_RUDDER            : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                ABS_WHEEL             : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                ABS_GAS               : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                ABS_BRAKE             : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                000b                  : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                000c                  : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                000d                  : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                000e                  : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                000f                  : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                ABS_HAT0X             : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                ABS_HAT0Y             : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                ABS_HAT1X             : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                ABS_HAT1Y             : value 0, min 0, max 4095, fuzz 0, flat 0, resolution 0
                ABS_MISC              : value 0, min 0, max 255, fuzz 0, flat 0, resolution 0
                0029                  : value 0, min 0, max 255, fuzz 0, flat 0, resolution 0
                002a                  : value 0, min 0, max 255, fuzz 0, flat 0, resolution 0
                002b                  : value 0, min 0, max 255, fuzz 0, flat 0, resolution 0
                002c                  : value 0, min 0, max 255, fuzz 0, flat 0, resolution 0
                002d                  : value 0, min 0, max 255, fuzz 0, flat 0, resolution 0
                002e                  : value 0, min 0, max 255, fuzz 0, flat 0, resolution 0
                ABS_MT_SLOT           : value 0, min 0, max 255, fuzz 0, flat 0, resolution 0
                ABS_MT_TOUCH_MAJOR    : value 0, min 0, max 255, fuzz 0, flat 0, resolution 0
                ABS_MT_TOUCH_MINOR    : value 0, min 0, max 255, fuzz 0, flat 0, resolution 0
                ABS_MT_WIDTH_MAJOR    : value 0, min 0, max 10, fuzz 0, flat 0, resolution 0
                ABS_MT_WIDTH_MINOR    : value 0, min 0, max 65535, fuzz 0, flat 0, resolution 0
    MSC (0004): MSC_SCAN             
  input props:
    <none>

Most events have a label, but not everything. When I capture the output, I can see the device doing things: (take note that your device ID matches when using this commend)

adb shell su -- getevent -lt /dev/input/event4

which when I touched the screen yielded:

[     396.439831] EV_MSC       MSC_SCAN             000d0042            
[     396.439846] EV_KEY       BTN_TOUCH            DOWN                
[     396.439880] EV_ABS       ABS_X                00000639            
[     396.439897] EV_ABS       ABS_Y                0000086a            
[     396.439910] EV_MSC       MSC_SCAN             000d0042            
[     396.439913] EV_KEY       BTN_TOUCH            UP                  
[     396.439929] EV_ABS       ABS_Z                0000000c            
[     396.439940] EV_ABS       ABS_RX               00000004            
[     396.439968] EV_ABS       002a                 000000ff            
[     396.439976] EV_ABS       ABS_RY               0000ffff            
[     396.439984] EV_ABS       ABS_RZ               0000ffff            
[     396.440009] EV_ABS       002b                 000000ff            
[     396.440023] EV_ABS       ABS_THROTTLE         0000ffff            
[     396.440044] EV_ABS       ABS_RUDDER           0000ffff            
[     396.440070] EV_ABS       002c                 000000ff            
[     396.440080] EV_ABS       ABS_WHEEL            0000ffff            
[     396.440089] EV_ABS       ABS_GAS              000000ff            
[     396.440125] EV_ABS       ABS_BRAKE            0000ffff            
[     396.440138] EV_ABS       000b                 0000ffff            
[     396.440158] EV_ABS       002e                 000000ff            
[     396.440168] EV_ABS       000c                 0000ffff            
[     396.440178] EV_ABS       000d                 0000ffff            
[     396.440203] EV_ABS       000e                 0000ffff            
[     396.440216] EV_ABS       000f                 0000ffff            
[     396.440237] EV_ABS       ABS_MT_TOUCH_MAJOR   00000004            

(I didn't include everything, but I did attach it.)

So, this was the first indication I had that the monitor was working at all. Up until this point, I hadn't seen Android react to me touching the screen. When I saw this I tried a lot more monkeying around with the screen. I managed to get the Android to show me some type of hover event when I placed all 10 fingers on the device. It wasn't centered on my fingers either. I thought maybe it needed calibration but after installing a couple of Android calibration apps I was unable to make any additional headway.

So, currently I'm reading about Touch Devices and Input Device Configuration Files and digging into why it seems what is being touched on the screen isn't mapping into the OS. I'm sure there will also be some googling of the "USBest Technology SiS HID Touch Controller" as well. I think I've seen some remarks with regards to this controller being used with other tablets, so this can't be too exotic. 

Digging into the details of hardware on Android is surprisingly easy. I'm impressed that I can pull up as much information as I can about various devices and even OS state so easily. I guess a lot of my success probably has to do with the generic nature of USB as much as the nature of Android though. Looking forward to digging in further and figuring out this hang up though.

 

Posted by cgp

So, I recently bought one of these android devices:

http://www.amazon.com/gp/product/B00AZR1TG2/ref=oh_details_o00_s00_i00?ie=UTF8&psc=1

  • Android 4.2 Jelly Bean, RK3188 Quad-core 1.6GHz CPU Cortex-A9 (28nm), 2G DDR3 RAM / 8G Flash
  • Standard HDMI Female, 3.5mm headset jack (mic embedded), Micro USB, USB and SD card
  • Wi-Fi 802.11b/g/n, Bluetooth, DLNA, Miracast
  • Includes 5V 2A charger

It was $75, not too shabby. (they no longer sell them) They have a website:

http://www.timingpower.com/android-mini-pc-rk3188

I bought it along with a Hannspree (aka, Hanns-G) 10 point touchscreen monitor. It was built for Windows 8, but I figured, hey, I can probably figure out how to get it working with Android, and if not, no big thing, I'll just hook up to Ubuntu or something.Decent monitor.

I of course installed the Android SDK.I didn't use the early access preview. It's useful for verifying different things.

First Impressions

I've never really mucked around with Android much at all. I don't have a smartphone ($80 a month for a capped, no tethered data+phone plan? Forget it) So, keep that in mind when you read this. I am however a developer and have 20 years of experience looking at electronics, so, I'm not a complete buffoon either.

First thing is that it was pretty exciting getting the device to boot. Mine showed the Linux penguins on boot. I didn't expect that, I've never seen that on phones, and it only reinforced something I hadn't realized. Android is very much Linux underneath. I thought it was a very, very thin Linux layer supporting the Java JVM or something, but the world seems a lot simpler now that I see it's pretty much "Linux", and with what appears to be a Linux window manager running Java apps in windows (the widgets). "Rooting" is nothing more than using the root user. I'm still a little confused as to how that user context is invoked and when, but it's becoming more clear. 

Physical Connection and Drivers

During this process, when you are connecting the device, make sure you are connecting to the small USB port (aka, the "OTG" port) on the RK3188 device.

I needed to update to the latest firmware for the device from timing power. First, I installed the ADB driver:

http://adbdriver.com/

If this doesn't work for you, I think the following might:

http://www.cnx-software.com/2013/11/08/simplified-method-to-install-rockchip-usb-drivers-in-windows-xp78/

I'm a little confused by the end result of both of these installers, and since I ran them both I really can't tell which was the "correct one". The end result is a generic looking windows type device driver that indicates that it was written in 2010. It is possible that there are two pieces to the driver, and the rockchip piece which is newer isn't reflected in the device driver listing.

The instructions from Timing power have you run through some Chinese based installer, which was a little confusing and I believe unnecessary. After that, you're going to want to update the ini file which specifies the device ID. This file should have been installed with the ADB driver.

It will be under ~/.android\adb_usb.ini. Add a single line:

0x2207

to the file. If you've installed the device driver correctly, you can find the correct device ID for any device by looking under the Device Manager, under Android Phone, and under the properties for dialog the "Android Composite ADB Interface". In that properties dialog, look under details. select the "Hardware IDs", and you'll see an entry like 

USB\VID_2207&PID_0006&REV_0222

The portion after VID_, is the part that you enter into the ADB ini file with the "0x" prefix. It's not really entered in INI file format, but whatever.

I think I restarted the Android device (replugged it in at this point) I also made sure that USB debugging was turned on in Settings on the RK3188.

In any case, you should be able to run 

adb devices

from the SDK (sdk/platform-tools) and get back:

List of devices attached
V8GCU6JBJL      device

Updating to the Latest Version of Firmware

So, the next thing would be to update to the latest version of the firmware found at:

http://www.timingpower.com/rk3188-support

There's a new one as of Jan. 10th, (Beta). I used the November 2013 version, which was the 1080p version that I really wanted.

Download the batch tool found on the timingpower page. The batch tool listed on the timing power page is a fine tool, if a little crude. When run it will open a window that displays 8 or so boxes at the bottom which represent recognized, connected Android devices. They are usually uncolored/blank. 

To get them to recognize, as described by the documents on timingpower, I needed to click the little black button on the inside of the case. What wasn't precisely clear was that I needed to click the little black button at the same time I was plugging it in. This was fairly tricky given that you're already nervous about holding a sharp (likely metal) pointy thing against an exposed PCB. A couple of times I nearly scraped the back of the board while trying to reset it. But then again, I'm clumsy. I do however suspect that someone simply forgot to carve out the pinhole for the reset button when they were designing the case for the device.

Aaaaanyway. So, when I did that hamfisted power reset, the batch update tool filled in a box as green and ready to update. The update was pretty smooth. By default, the "firmware" update roots the device. I'm not sure why this is considered firmware really. I think it's installed a whole new OS. 400mb is basically replacing everything from what I can tell. But I am new to this.

I ran root anyway. I used the tools described at the following place:

http://howto.cnet.com/8301-11310_39-57608195-285/how-to-easily-root-an-android-device/

Nothing really seems to happen. I think all the rooting magic happens with specific applications that are run as root. For later.

Now we'll dig into the details of how I'm going to try and figure out how to get the HT231HPBU (aka,  23inch touch screen to work -- if at all!)

Posted by cgp
  1. Astrobiologists Find Ancient Fossils in Fireball Fragments - I'm sure that there are a million ways 'till Tuesday that these fragments could have been contaminated, even to the point that this could be in fact a rock that's returning to earth from an earlier ejection off of earth's surface? Maybe that's a question for Reddit's ask science.

Further Reading

11 Feb 2013
Posted by cgp

Something I should probably read up on sometime:

  1. O-notation considered harmful (use Analytic Combinatorics instead) - There are many more numerous examples of where practical application does not align with the use of O-notation. Also, detailed analysis of algorithmic performance just takes too long to be useful in practice most of the time. So what other options do we have ?

    There is a better way. An emerging science called “Analytic Combinatorics” pioneered by Robert Sedgewick and the late Philippe Flajolet over the past 30 years with the first (and only) text appearing in 2009 called Analytic Combinatorics. This approach is based on the scientific method and provides an accurate and more efficient way to determine the performance of algorithms(and classify them correctly). It even makes it possible to reason about an algorithms’ performance based on real-world input. It also allows for the generation of random data for a particular structure or structures, among other benefits.

Java Dynamic Proxies

20 Jan 2012
Posted by cgp

Dynamic proxies are one of those topics along with Reflection (to a lesser extent) that seem like magic in Java. They exist outside of the safe, procedural oriented nature of the language and add useful complexity and color to an otherwise dull language.

What are Dynamic Proxies exactly? Dynamic Proxies allow you to run custom code before, after, (or before and after) other pieces of code. For example:

class Blah {
  public void myMethod() { System.out.println("I ran!"); }
}

Say I wanted the above method to run before every call to Math.cos(). So, I would extend a new class from the Proxy class and tell it to intercept calls to Math.cos(). The I could tell it that instead of calling Math.cos() call my code instead. In my Proxy class, I would have the option of calling the original function or not.

Buzzword Bingo

Essentially, we have created a "logger" for Math.cos. Logging is frequently referred to as a "cross cutting concern". I point this out now to perhaps trigger recognition that one of the chief reasons to use Dynamic Proxies is to insert code around methods in an independent fashion without affecting the original code. Dynamic Proxies are basically what AOP frameworks like SpringAOP and Guice use under the hood to provide their functionality. (psst!

Typical use cases for Dynamic Proxies:

Rules and Limitations, more to follow

There are rules and limitations to doing the above, but for today, we'll leave it at that.

Posted by cgp

I would like to document my experience installing and using GWT. Very quick background: I used GWT way back in 2007. I even reported a bug that I didn't follow up on Sad.

I'm using Eclipse 3.6. I first tried using the update site but it timed out on the spectacular number of .jar files that it tried to pull down. (after a solid two hours of downloading) Typical of Eclipse and java, seemingly uncomplicated simple things (downloading a set of files) is difficult and error prone.

I recommend using the "download method"for installation which comes in at a hefty 160mb zip file. (but the single file downloads in a browser in less than a couple minutes for those of you with decent connections)

Installation from the zip files seems like a breeze, but the designer fails to show. I'm able to do some things like kick off the "Google Development Mode" server. For a Eclipse noob like me, it's not clear why the designer fails to show. The FAQ provides a hint:

The most important piece missing from some Eclipse distributions is the Eclipse PDE (Plug-in Development Environment). You can correct this problem by launching Eclipse and selecting Help > Software Updates. Select The Eclipse Project updates from the list of sites and select the "Eclipse Plug-in Development Environment" to install.

So, why then isn't it one of the checked requirements? I found a description of how to install PDE but don't have any more time to check this out. (much time wasted in the original two attempts to install from the Eclipse Update site)

TIL launch4j

24 Jun 2011
Posted by cgp

I always wondered what people use to create windows executables for Java apps. Launch4j is a pretty good option. It's free for commercial use, and is open source itself. The interface is a little clunky and takes some getting used to, but it does the job and has plenty of options:

  1. Maven AND Ant integration
  2. Splash screens
  3. Set JVM options via a config file

For me I needed to identify the process name. I'm surprised I hadn't found this sooner.