27 December, 2012

You Should Know, Java XML Parsing

As Java developer you should know that:

JAXP, Java API for XML Processing, lets you use any conforming parser implementation in a standard way. The code should be much more portable, and when you realise that a specific parser has grown too old, you can replace it with another without changing a line of your code (if you do it correctly).

    Basically there are three ways of handling XML in a standard way:
  1. SAX This is the simplest API. You read/modify the XML by defining a Handler class that receives the data inside elements/attributtes when the XML gets processed in a serial way. It is faster and simpler if you only plan to read some attributes/elements and/or write some values back (your case).
  2. DOM This method creates an object tree which lets you modify/access it randomly so it is better for complex XML manipulation and handling.
  3. StAX This is in the middle of the path between SAX and DOM. You just write code to pull the data from the parser you are interested in when it is processed.

Forget about propietary APIs such as Jdom or Apache ones (i.e. Apache Xerces XMLSerializer) because will tie you to a specific implementation that can evolve in time or lose backwards compatibility, which will make you change your code in the future when you want to upgrade to a new version of Jdom or whatever parser you use. If you stick to Java standard API (using factories and interfaces) your code will be much more modular and maintenable.

    Code samples
  1. XML parsing using SaxParser with complete code

Galaxy Note 2, Quick root & flash guide

Thanks to my wife I just got one new Galaxy Note 2 as Xmas gift. It's one awesome gadget, it came with Android 4.1.1 pre-installed and it has some ugly vendor animations on it that I wanna get rid off so I'm going to root and re-frash it with a custom room (new version 4.2.1, Jelly Bean).

What is root? On many computer operating systems including Unix, Linux and Android, the root account, is a special user with complete access to all files and commands. Various names for this type of account might include, administrator, superuser, or supervisor.

In the context of Android, root access allows the user to have complete control over their device. Root access is commonly granted for developers allowing them access to all files and commands on the device.

With full root access to a device, there is potential for damage. Any user with root access is strongly cautioned to be very careful.

My previous experience with my old and rusty HTC desire tells me that xdev and android geek is the right place to go in order to find the firmware and instructions to do it without bricking my "phablet"...

How to Root Samsung Galaxy Note 2 N7100 with Odin

Rooting the device

    Required files and tools:
  1. The root & recovey package
  2. Odin

This installation has done on a clean PC - no android ADK or samsung drivers were installed before it

    The rooting process:
  1. The first thing to do is to download the root & recovery package from here.
  2. Save the file on your computer.
  3. On the same PC download Odin.
  4. Extract and install the tool.
  5. On the computer open Odin.
  6. Next, turn off the device as it must be entered in download mode.
  7. For download mode press and hold Volume Down, Center Home, and Power buttons together.
  8. When the download mode is reached, connect the Note with the computer by using its USB cable.
  9. Press Volume Up to continue and then windows will install all required drivers (SAMSUNG Mobile USB CDC Composite Device and SAMSUNG Mobile USB Modem).
  10. Once windows finishes the driver installation the “added” message should be displayed at Odin.
  11. Also, the ID:COM section should be yellow.
  12. If not, install the drivers again and then redo the above steps.
  13. Up next, on Odin, select “PDA”.
  14. Pick the unzipped downloaded file (cwm6-root-n7100.tar).
  15. Don’t make any other changes, just click on “Start”.
  16. The root process will now begin.
  17. Wait until it’s over and in the end unplug the USB cord and reboot the Note2.
  18. If the device does not boot don't panic, you will have to start the CWM, for that remove the baterry, put it back and then press and hold Volume Up, Center Home, and Power buttons together until the SAMSUNG Logo disappears.

You don't need to download and install Rom Manager into the device. You will not see the recovery image for this device into CWM because there is no official support yet. Next time you will only need to flash the recovery image (without root).

    THE Backup!!!
  1. Start the Rom Manager App then select "boot into recovery mode".
  2. Select backup, etc.
  3. reboot the device.
  4. Connect the USB cable, open the device and then copy the content of the folder clockworkmod\backup into your computer ...

Last, fixing permissions ...

    A few usefull links:
  1. Android USB Drivers For Windows OS
  2. How To Carrier Unlock Samsung Galaxy Note 2 Permanently

13 December, 2012

You should know

As architect you should know that:

CPU Bound means the rate at which process progresses is limited by the speed of the CPU. A task that performs calculations on a small set of numbers, for example multiplying small matrices, is likely to be CPU bound.

I/O Bound means the rate at which a process progresses is limited by the speed of the I/O subsystem. A task that processes data from disk, for example, counting the number of lines in a file is likely to be I/O bound.

Memory bound means the rate at which a process progresses is limited by the amount memory available and the speed of that memory access. A task that processes large amounts of in memory data, for example multiplying large matrices, is likely to be Memory Bound.

"Cache bound" means the rate at which a process progress is limited by the amount and speed of the cache available. A task that simply processes more data than fits in the cache will be cache bound.

I/O Bound would be slower than Memory Bound would be slower than Cache Bound would be slower than CPU Bound.

The solution to being I/O bound isn't necessarily to get more Memory. In some situations, the access algorithm could be designed around the I/O, Memory or Cache limitations. See Cache Oblivious Algorithms.

The Amdahl's law states that "The speedup of a program using multiple processors in parallel computing is limited by the time needed for the sequential fraction of the program."

17 July, 2012

AllWinnwer A10 Based Tablets

If you are looking for one cheap android ICS based tablet I would recommend this one below. It's does not came with Bluetooth nor 3G embedded but you can "easily" reflash this guy in order to add the support drivers you need.

I bought mine one eBay by 100 bucks with shipping, it's a real bargain. Where I live the usual "well know" brands are twice or more this price. I bought this guy just to stop to reflash and install code into my HTC desire - it's not a good idea to use your main cell phone to test this kind of stuff right? I don't need a US600 paper weight!

Be warned thought: there are lots and lots of versions of tablets using this microcontroller and It's almost impossible to identify all of then. I liked mine very much but I can't say who is the brand behind mine (even on the package there is no brand name nor label). Well, it's okay, it works and the material is really good for the price that I payed, to be honest it's better than what I was expecting.

I saw this very same microcontroller in one Set Top Box on deal extreme (for those whom doesn't know deal extreme is one ebay/china online seller/importer kinda of store, usually the same stuff that you see on dx you can get from ebay or on china, like the original Set Top Box here). I don't know mandarin but I do know that this Set Top Box has more power than the Raspberry Pi and cost so so 100 bucks on ebay ...

So, if you are, like me, interested on installing, flashing and trying some new roms I would recommend:

  1. The Tablet that I bought on ebay
  2. Windows 32 / 64 ADB Drivers
  3. List of tablets powered by Allwinner A10 processor
  4. Allwinner A10 General FAQ (non tablet specific)
  5. Hack A10 Devices
  6. xDev Tutorial, Build AOSP Android 2.3.7 for Allwinner A10 tablets
  7. Some pre-compiled roms to your AllWinner A10 based tablet
  8. Open Source Firmware for the Mele A1000

04 July, 2012

CMS war

Who is the best CMS out there? This is a common question without a simple answer. I just can say that a CMS is like a car - you can choose whatever you want based on your personal taste.

  1. CMS Comparison: Joomla vs. Drupal vs. WordPress
  2. How to Select a Web Content Management System

01 July, 2012

Creating foam models using Google SketchUp

The first plugin you must have is the "unfold" plugin. As the name implies this plugin flatten a 3d object in a way were you will be able to cut the foam and fold it again into the 3d base object!

The second plugin that you must have is the belzier plugin. Sketchup came with just one simple arc tool and it's not enough to the most of the plans that you can grab on the internet.

  1. YouTube, Unfold plugin use
  2. FullFuse_PART_1.wmv
  3. FullFuse_PART_2.wmv
  4. FullFuse_PART_3.wmv
  5. Profili
  6. E-Voo, Brazilian Aeromodelism site
  7. Mini tutorial: 2D to 3D using the free app Google SketchUp
  8. Google SketchUp Toolbar Series: Rotate
  9. Flattery plugin
  10. 9 Sketchup tips for better 3d modelling

3d modeling using paper folding tools

You read it right: there are hope for simple guys like you and me (or anyone whom still wants to keep up in line with your own wife, your social life and that huge list of 3d projects that you wanna make).

Well, cutting off the crap chat the hint is named Pepakura. In plain english: this fantastic tool convert your 3d model to paper craft models. Yes, you can get your sketchup models and bring then to life! I'm just doing some tests with some foamy airplane models ...

No biggie deal you might say hum? Just take a look on the links below and you will change your mind, believe-me!

  1. Pepakura Tutorial, fiber glass Halo helmet
  2. Iron Man 2 Costume, part I
  3. Iron Man 2 Costume, part II
  4. Alternative to Fiberglass Resin on Pepakura Parts Method
  5. PaperCraft Low Polygon Self Portrait
  6. Much more on youtube!

28 June, 2012

Extra 300 LX Project

The best project online - all documented, awesome stuff, click here Project Extra, Mike Hurley.

I'm not Mike Hurley and I don't have his experience and skill to build this marvelous model.

I did just got a few sketchup drawings into the web in order to cut and paste one Extra using depron sheet.

18 June, 2012

Another Home Brew Quadcopter

Under construction ...

    Some useful links
  1. AeroQuad
  2. MultiWII
  3. AeroQuad SVN Repository
  4. Is this sensor board supported? Cheap chinese 9dof
  5. Hardware Assembly Mini Shield v1.0
  6. What is Degrees of Freedom
  7. Wikipedia, Degrees of Freedom

FS TH9X Common mods

A compilation of the most common and useful Turnigy/FS TH9X/Eurgle mods ...

So this is more one blog with Turnigy mods?

- Yes and no: I'm mostly writing it in order to register my work on my own radio mods and decided to share my experience okay? So I decided to compile the most common mods ...

For my own experience the most difficult part of any of these mods below is that you can get crazy with the amount of info that is available: most part of it is spreaded over a lot of forums with lots and lots of pages to read, it's easy to get insecure with this amount of technical stuff.

1. ISP Programming Cable

Medium mod. This mod is the most common mod and it's required if you do intend to change the default factory firmware that came installed on the stock radio. There are a few videos on youtube teaching how to install this ISP cable but you will spend much more time trying to understand the German/Pollack/Whatever guy's accent than wiring the cables.

The ISP cable (in-system programmer) is a common cable in the AVR microcontrollers world, you do use it to load programs (firmware compiled code, hex files) into the microcontroller.

If you do have any experience with microcontrollers (uC) or any Arduino gadget you will most probably already have the knowledge required to install this cable just looking at the pictures below.

As far as I know, up to today, the FS TH9X main board has two main versions. You can recognize it looking for the extra pad close to the SCK pin - if your board does have this pad your board is version 2, if it hadn't it's version 1.

PCB v2, note the pad close to the SCK pin
The ISP connector wiring
The ISP connector cable
External view of the ISP connector
  1. YouTube, Turnigy 9x flash upgrade wiring how to-part 1 of 3
  2. YouTube, Turnigy 9x flash upgrade wiring how to-part 2 of 3
  3. YouTube, Turnigy 9x flash upgrade wiring how to-part 3 of 3
  4. 9xForums, Flashing your 9x - Hardware

2. Firmware update

Easy mod. After the mod #1 you will be able to change the firmware that came installed on your stock radio - why would you add one ISP cable if not to change the uC "software"?

One warning regarding those 20 bucks ARVISP MKII clone programmers on ebay: most probably you will face some issues trying to establish communication with the radio uC (it's caused by the capacitor that is wired on the RST pin - I saw a few guys recommending to remove this capacitor but I didn't fell comfortable with this approach). After some huge amounts of coffee I gave up with my clone programmer and then I tried with my Bus Pirate v3b (the Bus Pirate took 30 painful minutes to write and another 30 minutes to read the firmware but it worked!).

  1. 9xForums, Flashing your 9x - Software
  2. 9xForums, How to flash your 9x Using Eepe
  3. Using your arduino to program a Turnigy 9X transmitter

3. Battery JST connector

Easy mod. Just change the 3 pins mini jst connector by a male jst connector.

A set with 10 pieces costs less than one dollar at Hobby King.

The JST connector
A 3S lipo battery (11v)

4. 2-cells or 3-cells battery

Medium mod. There are two main versions of this mod: This one (really well written in 2008 by RC Model Reviews) assumes that you will always use a 2-cell LiPo battery. This other adds a switch to let you choose between the 2 available options.

I did mine using one of those voltage selector switches that I got from one old pc power supply and fixed it at the bottom of my radio. This switch and this position is much more secure - you will never bump accidentally on it.

Even if you do already have one 3S lipo I would recommend you to buy the TrustFire pack or a 2S (7.4v) LOW DISCHARGE lipo.

The 3S/2S switch (on the left)
External view of the 2S/3S switch

5. LCD Backlight

Easy mod. This mod is actually a kit that came ready to be used: open your radio, disconnect the cable that attaches the front into the back case, connect this very same cable into the backlight male connector and then connect the opposite side of the backlight cable into the radio where the original cable was installed before.

As always Murphy's law is still present: The "recommended" backlight position will block the menu buttons and the positive and negative wires are too short to let you rotate it to the left. I just got those wires out and rewired a longer pair and added a little connector to make my life easier.

  1. HobbyKing, Backlight LCD kit (5 bucks)
  2. Installation
  3. YouTube, Backlight control configuration

6. LCD Backlight auto turn on/off

Easy mod. After you do install the LCD Backlight kit you will notice that it's always turned on (yes, you read it right, the LCD is ALWAYS TURNED ON). You can easily add a switch to turn it on or off but how about doing it automatically? This mod will automatically turn the backlight on whenever you do press a button and will turn it off after a few seconds without use.

You will need a BS170 transistor to install this mod but you can use a simple 2N3904 PNP transistor instead (the 2N3906 NPN doesn't work - it will invert the on/off signals).

  1. HobbyKing, Backlight mod
  2. YouTube, Backlight Installation turn on the youtube Transcribe Audio - just for fun ...
The LCD Backlight moded

7. Piezo Speaker with Haptic Feedback

Medium mod. This mod is cosmetic but it's useful and cool - I do hate that buzzer that came with the original stock radio.

For those whom doesn't know the difference between one buzzer and one piezo speaker let me try to resume: the buzzer is only capable to make noise and the piezo speaker can be driven by a uC in order to make cool sounds.

There are a few components to solder and you do must pay close attention into the polarity indication on the capacitor and on the diode. For the BOM (bill of materials or parts list) you can easily grab all of them on eBay with china prices. You can also get the piezo from almost any old wireless telephone and the vibration motor can be get from any broken iPhone.

  1. 9xForums

8. JR module with selection

Medium mod. This mod is, IMHO, the most useful one - it will enable your radio to use one JR TX module.

Why would you need this mod?

  1. The JR brand is much more reliable
  2. The JR TX has a lot of compatible RX models (micro, 3.3v, etc). I could find only one RX for the fly sky (the very same one that came with the radio)
  3. The JR module has fail safe
  4. The JR module has longer range
  5. The JR module has much better interference resistance

There are, basically, 3 ways to install this mod. At first I was really confused with these options and then, after some reading, I realized that they are almost the same thing as I describe below:

  1. FrSky V8HT 2.4Ghz DIY Module kit
  2. This kit is nothing more than one internal version of the JR TX module followed by the required 6v voltage regulator, a switch, a little PCB with one red led and one button to do the RX bind.

    YouTube, Installing the FrSky 2.4GHz DIY Module kit

  3. FrSky DHT 8ch DIY Telemetry Compatible Transmitter Module kit
  4. This kit is almost the same kit described on the item 1 above but with telemetry (this kit will require the FrSky telemetry mod below OR an external DHT system).

  5. FrSky DJT 2.4Ghz Combo Pack for JR w/ Telemetry Module & V8FR-II RX
  6. This option only adds a switch and a 6v voltage regulator in order to attach the JR TX module. I do prefer this option just because it's simpler and use the TX module as it should be used (with the internal version you end up with the TX slot empty).

    This option requires the normal JR TX module and it also requires the 2-cells mod installed.

    Warning: the second picture, where it shows only two connected pins, is not the final mod - it's just a partial to show the pin 4 isolated from GND. After you do change the pin 4 solder all pins back.

      Just in case here is the Turnigy TX module pinout, the 78L06 wiring and my color schema:
    1. Pin 1 - ANT
    2. Pin 2 - GND (C - blue)
    3. Pin 3 - + (I - green)
    4. Pin 4 - GND (O - yellow, 6v when ON for the JR TX module)
    5. Pin 5 - PPM

    Another warning: after you do install this mod you will have to remember to change the JR/Turnigy switch before you do change the module or you will burn it! And yes, never change the module or the switch with the radio turned on. You can isolate the pin 4 in the TX Module in the same way you did in the TX - see FlySky Module mod to make this change just for precaution.

9. DSM2 module

Hard mod. This mod is expensive - you do need to buy one DSM2 TX in order to grab its internal RF module ...

  1. 9x Full Mod DSM2/X
  2. Hacks & Mods - DSM2 mod
  3. 9xForum - DSM for dummys
  4. 9xForum - How to modify your 9x to the DSM protocol

10. LP4/LP5 module

Medium mod. Same as the DSM2 mod this is one expensive mod.

11. FrSky Telemetry

Hard mod. This is THE MOD, IMHO this is the most difficult and you will require advanced ninja skills to solder two close microcontroller wires.

9x Full Mod Telemetry

How to modify your 9x to support telemetry

12. SD Card ...

The RadioClone firmware requires this mod - the RadioClone code (the hex file) is so huge that it let the radio with memory space for only one model. RadioClone uses the SD Card to save and restore models in order to reduce this limitation.

I'm still looking for a reference for this mod. There is a SD Card mod on the RadioClone forum however the author mention that it's still experimental. I'm not sure if it is because of any firmware limitation OR because of the size of the code that it's required to support this SD Card (SPI/Fat) anyway it should be simple - at least on arduino it's simple as I saw 6 months ago when I got one of those ebay SD Card modules and wired it up and put it to work in less than 2 hours.

Link to the SD Card PRO

Link to the home brew SD Card interface

Seems that ONLY the RadioClone firmware does have SD Card support ...

Some less common mods

  1. 9xForum, Trainer port resistor fix
  2. YouTube, Trainer port resistor fix
  3. er9x, How to set up 16ch Tx
  4. 9xForum, Wireless Trainer System

A Few Links

  1. 9xForums, FS-TH9x Schematics and FCC papers
  2. Gruvin 9x Reference data
  3. TX module pin-out
  4. YouTube, Er9x Template Servo Test (Servo Teste)
  5. ER9X Hacks
  6. er9x mods
  7. Gruvin9x Custom PCB
  8. ERSKY9X Custom PCB
  9. Turnigy 9X Replacement Board, under development?
  10. 3.3v location
  11. Using a DSM2 Module from the Spektrum DX5 Radio
  12. T9X mod to use Flysky module, Frysky module and DSMX module

Coming not so soon ...

Someday, only god knows when, I'll try the mods 9, 10 and 11.

01 May, 2012

Low Cost Arduino LCD module, 3 pins

For those who are looking for a ready to use Arduino LCD module here goes my 5 cents to the open source community.

This module was based on the work published on ArduinoShiftRegLCD's site. The original layout has two sides but it can be easily converted into a single side layout just using simple jump wires at the bottom side.

    Parts list:
  1. M74HC595
  2. 1 x 16 pins female header
  3. 2 x 2 pins male headers
  4. 1 x 10k resistor
  5. 1 x 100nF capacitor (104)

top bottom

Project files here (github account required).

Feel free to leave your comment.

24 April, 2012

Syntax Highlighting with Blogger Engine 2

CraftyFella's already wrote some awesome hints about how to setup and use Alex Gorbatchev's SyntaxHighlighter javascript libray and I'm not used to beat dead horses but there is still one good hint he missed: THEMES.

It's really easy, just add the css file in your template and be happy my friend!

By the way, anyone knows how to setup this css theme to use different colors on odd and even lines?

23 April, 2012

Android issues with WebView.loadData and WebView.getContentHeight

If you tried the suggested code at Stack Overflow on Gingerbread you will see that it still doesn't work when using loadData or loadDataWithBaseURL. The proposed code only works when using the loadUrl - at least it didn't worked on my HTC Desire nor the 2.3.3 Emulator.

In the Andromedev blog you will see one possible solution using the android javascript bridge but I'm not still convinced that this is the best approach to take. Even if you do decide that it's the best approach you will face one bug already reported on Issue 12987 that affects any javascript bridged call on Gingerbread.

Right know I'm developing one pager fragment that uses one webView to display simple html texts and I had disabled the javascript support to try to keep the memory usage low. With the proposed solution I'll have to turn it on again and pray that my user don't use the gingerbread version ...

Well, the point is: IF you are using the WebView.loadUrl AND you are not on gingerbread you don't need to worry, you just need to write a listener - the onPageFinished and all height and width methods will work as expected.

However the code below still doesn't work! The java script bridge call the code in the JavaScriptInterface but the height is not there yet ...

/**
 * To use the webView embedded in another view (not full screen).
 */
public class EmbeddedWebView2 extends WebViewClient {

   private static final String P_MIMETYPE     = "text/html";
   private static final String P_ENCODING     = "utf-8";
   private static final String LOG_TAG        = "EmbeddedWebClientView2";
   private static final String JS_BRIDGE      = "JSB";
   private static final String JS_CONTENTSIZE = "javascript:window." + JS_BRIDGE + ".setContentSize(" + //
                                                    "document.getElementsByTagName('html')[0].scrollHeight," + //
                                                    "document.getElementsByTagName('html')[0].scrollWidth" + //
                                                    ");";

   @Override
   public void onPageFinished(WebView webView, String url) {

      super.onPageFinished(webView, url);

      WebSettings webSettings = webView.getSettings();
      webSettings.setJavaScriptEnabled(true);
      webView.addJavascriptInterface(new JavaScriptInterface(), JS_BRIDGE);
      webView.loadUrl(JS_CONTENTSIZE);
   }

   public static void loadData(WebView webView, String data) {

      webView.setWebViewClient(new EmbeddedWebView2());

      WebSettings webSettings = webView.getSettings();
      webSettings.setSavePassword(false);
      webSettings.setSaveFormData(false);
      webSettings.setJavaScriptEnabled(true);
      webSettings.setUseWideViewPort(false);

      final String dataHtml = "" + data + "";
      webView.loadData(dataHtml, P_MIMETYPE, P_ENCODING);
   }

   public static void loadDataWithBaseURL(WebView webView, String baseUrl, String data) {

      webView.setWebViewClient(new EmbeddedWebView2());

      WebSettings webSettings = webView.getSettings();
      webSettings.setSavePassword(false);
      webSettings.setSaveFormData(false);
      webSettings.setJavaScriptEnabled(true);
      webSettings.setUseWideViewPort(false);

      final String dataHtml = "" + data + "";
      webView.loadDataWithBaseURL(baseUrl, dataHtml, P_MIMETYPE, P_ENCODING, null);
   }

   /**
    * getHeight, getContentHeight and getMeasuredHeight are ONLY updated when
    * using loadUrl that's why we need this guy. 
    * 
    * TODO: wait a fix for ISSUE 12987 on gingerbread.
    */
   public class JavaScriptInterface {

      private int height, width;

      public void getContentSize(String sHeight, String sWidth) {

         if (sHeight != null) {
            width = Integer.parseInt(sHeight);
            Log.d(LOG_TAG, "Result from javascript, height = " + height);
         }
         if (sWidth != null) {
            width = Integer.parseInt(sWidth);
            Log.d(LOG_TAG, "Result from javascript, width = " + width);
         }
      }
   }
}

18 April, 2012