Back Light Dimming Mini210/S

NothinRandom
If you've had the chance to mess around with this board in wince, then you
might have noticed the free apps that came with the board. One of them is
the backlight dimminng function...which uses pwm to dim the back light. I
like this feature because it allows you to control the backlight
brightness. Does anyone have a clue how to do this in C#? If you've done so
and are willing to share, that would be nice. If not, some pointers would
do me just fine. Thanks ahead!

NothinRandom
Hello everyone,

Since everyone is so enthused about sharing their work, I thought I should
do as well. If you would like to control the backlight on the
Tiny/Mini210/S or the Tiny/Mini6410 in wince via your application, here's
how you can do it:

All you have to do is call up the class (i.e BackLight.intensity = 50).
This will change the brightness to 50%, which is 127/255 since it's an 8bit
PWM driver that drives the backlight. Enjoy! Make sure to change namespace
to fit into your program if you don't want to include using test1;

using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;

namespace test1
{
    class BackLight
    {
        static string B11 = "BrightnessOfLCD";//"BacklightCurrentLevel";
        static string KEY_NAME = "ControlPanel\\Backlight";
        static int percentage = 50; //default in %

        public static int intensity
        {
            get { return percentage; }
            set { changeBL(value); }
        }

        /// <summary>
        /// change backlight from off to on<->0-255<->0-100%
        /// </summary>
        /// <param name="input">0-255</param>
        /// <returns></returns>
        static int changeBL(int input)
        {
            if (input < 0 || input > 100) //idiot proofing
                input = 50;
            percentage = input * 255 / 100;
            RegistryKey key = Registry.CurrentUser.CreateSubKey(KEY_NAME);
            key.SetValue(B11, percentage);
            key.Close();
            SendEvent("BackLightChangeEvent");
            percentage = input;
            return input;
        }

        [DllImport("CoreDll.dll")]
        private static extern IntPtr CreateEvent(string lpEventAttributes,
bool bManualReset, bool bInitialState, string lpName);

        [DllImport("CoreDll.dll")]
        private static extern Int32 EventModify(IntPtr hEvent,
EventModification mod);

        [DllImport("CoreDll.dll")]
        private static extern Int32 CloseHandle(IntPtr h);

        private enum EventModification
        {
            Pulse = 1,
            Reset = 2,
            Set = 3
        }

        static void SendEvent(string evtName)
        {
            IntPtr evt = CreateEvent(null, false, true, evtName);
            if (evt == IntPtr.Zero) throw new
InvalidOperationException("Failed to create event");
            try { EventModify(evt, EventModification.Pulse); }
            finally { CloseHandle(evt); }
        }
    }
}

Dave McLaughlin
Thanks for sharing. 

The original lack of replies to your first post may be because only a few
are using WinCE on their Mini210. I am using Android myself but it is nice
to see someone taking the time to post back on their original posting and
offering their thoughts and ideas.

Cheers
Dave...

NothinRandom
Hi Dave,

I really would like to develop with android, but I find that the gui part
is way too cumbersome. Also, serial ports in Android is way tougher to
manage than say C#; especially when you make an array of serial ports. I
guess when there exists a good designer for android, then I'll start
programming.

dezso
Thanks for sharing a WinCE code.

NothinRandom
No problemo! I'm working on other libraries as well. I guess I can share a
few more with you guys.

Dezso
Any chance you working on RS485 :) or maybe OneWire com on gpio

NothinRandom
RS485 using gpio? That would be inefficient I think. I would use the serial
TTL from the board to one of these:

http://www.andahammer.com/minirs23/
or
http://www.andahammer.com/univrs23/

Then use one of these to convert from ttl to half/full duplex:
http://www.usconverters.com/index.php?main_page=index&cPath=65 

I started working on 1-wire. You can use the one written for Arduino, then
use one of FriendlyArm's gpio example and call that port using the Arduino
library. Or you can wait until I finalize the library and fully optimize it
:)

NothinRandom
Forgot. You can use this chip:
http://datasheets.maximintegrated.com/en/ds/DS2480B.pdf and just run it off
from your serial port. Just remember to lower the output voltage of Tx of
the IC down to 3V-3.3V (going back to arm board) via a voltage divider.

Dezso
Definitely I donnot want to rum rs485 on gpio, that was for OneWire. 
But if you can make a class to drop in to any project than call something
like RS485_send(data, id) or something like that.......
I do have max3485 already

NothinRandom
Dezso,

By using the DS2480B, you can just use your existing serial code. No need
to write a library at all. This might be quicker for you.

Dezso
I see now, going to order some.

Nitin
Thanks alot NothinRandom.
It works great.
Can u guide me to read Buttons using C# only?