Thursday, November 24, 2011

Changing platform and results

I was getting a little tired of the little 8 bit microcontrollers and all their limitations so I started searching for a new (powerful) platform. So, what to search for? Because I've worked in the past only with Atmel chips (with some few exceptions) I started looking on the Atmel site on the AVR32 and ARM solutions. After a little discussion with some other people, I decided to start working with ARM chips so I began searching for developing tools (debuggers, programmers, compilers) to see if this would be cost effective. 
In my search I stumbled upon some great arm developing platforms from GHI Electronics that support .NET micro framework. I worked a little with .NET micro framework in the past (a very small project at school) and it seemed pretty great. Well, this modules are light years from great. You can event run unmanaged native code via RLP if you need real time capabilities and everything else you need is there, in the SDK. You can just start working on what you want to do.





After some researching I decided to go with the EMX module (cost causes) and build a custom PCB that will host an ethernet, USB host/device and SD card connectors, a 4.3" 480x272 LCD screen with touch panel and a VS1053 decoder.

Everything works well until now but can't get the LCD to work with my EMX module (still working on it).

So, my first project will be a big (huge) upgrade on the music player and it will not be only a music player. It will have mail capabilities (check/send/notify new mails POP3/SMTP with TLS/SSL connections), some internet services (RSS news/weather/NTP), music playback (from SD, online radio, USB mass storage devices). I was also thinking of adding support for USB 3G modems (when ethernet is not available) but this will be for a later release. Maybe add even bluetooth support for remote controlling.

So, until I get my development board up and running (with the LCD screen), I'm working on an UI library which will be available (with source code) after I finish it. It supports styles (only changing colors for the controls - also user can create custom styles and controls), multiple desktops (with transition effects fade and slide currently), some controls (will need to implement some more), the TextBoxes can have string validators to restrict the entered data, the virtual keyboard will have multiple formats (currently has only qwerty but it will have a numeric only mode).

Here is a little video with the progress (it's made in the emulator). I have no idea how it would work on the EMX but hope I'll test it soon.




And this is all the code neede (except the weather control).



//initial weather place
const string initialPlace = "Timisoara";

//create a new Yahoo! Weather Provider
YWeatherProvider yProvider = new YWeatherProvider();

//use the default desktop
Desktop desktop = DesktopManager.Instance.DefaultDesktop;
//suspend refreshing
desktop.Suspended = true;

//create a weather control and add it on the desktop (centered)
WeatherControl wControl = new WeatherControl(yProvider.WeatherCondition, 0, 40);
wControl.X = (desktop.Width - wControl.Width) / 2;
desktop.AddChild(wControl);

//create text box for weather place
TextBox txtWeatherPlace = new TextBox(string.Empty, 5, 5, 150, 25) { Validator = (s) => s.Trim().Length != 0 };
//watch for text changed
txtWeatherPlace.TextChanged += (newPlace, valid) =>
{
    string nPlace = newPlace.Trim();
    //if the new place is different
    if (yProvider.Place != nPlace.ToLower())
    {
        //disable the textbox
        txtWeatherPlace.Enabled = false;
        //disable the weather control
        wControl.Enabled = false;
        //get the weather in a new Thread
        new Thread(new ThreadStart(() =>
            {
                //set the weather place and get the new weather
                if (yProvider.SetWeatherPlace(nPlace)) yProvider.GetWeather();
                //set the weather condition in the WeatherControl
                wControl.WeatherCondition = yProvider.WeatherCondition;
                //enable the textbox
                txtWeatherPlace.Enabled = true;
                //enable the weather control
                wControl.Enabled = true;
            })).Start();
    }
};
desktop.AddChild(txtWeatherPlace);

//two available predefined styles
Style styleDark = new Mp.Ui.Styles.StyleDark(), styleLight = new Mp.Ui.Styles.StyleLight();

//create change style buton; set the tag as the current style
TextButton chStyle = new TextButton("Style", txtWeatherPlace.ScreenRight + 5, 5, 60, 25) { Tag = true };
chStyle.ButtonPressed += (s) =>
{
    DateTime t1= DateTime.Now;
    desktop.Suspended = true;
    bool v = (bool)((TextButton)s).Tag; 
    StyleManager.CurrentStyle = v ? styleDark : styleLight; 
    s.Tag = !v; 
    wControl.WeatherCondition = yProvider.WeatherCondition;
    desktop.Suspended = false;
    Debug.Print((DateTime.Now - t1).Milliseconds.ToString());
};
desktop.AddChild(chStyle);

//set the text to trigger a get on the weather
txtWeatherPlace.Text = initialPlace;

//re-enable refreshing
desktop.Suspended = false;
Thread.Sleep(Timeout.Infinite);


Any questions, suggestions or recommendations are welcomed.

No comments:

Post a Comment