Patch for Button module

Steven, sure.

this one is only working for about 5 button presses, after that the camera is busy and won’t work anymore :


using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerApp1
{
    public partial class Program
    {
        GT.Timer timer = new GT.Timer(2000);

        void ProgramStarted()
        {
            // Initialize event handlers here.
            // e.g. example.Pressed += new GTM.ManufacturerName.ExampleModule.EventHandler(example_Pressed);
            button.ButtonPressed +=new Button.ButtonEventHandler(button_ButtonPressed);
            button.ButtonReleased += new Button.ButtonEventHandler(button_ButtonReleased);
            camera.PictureCaptured+=new Camera.PictureCapturedEventHandler(camera_PictureCaptured);

            timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
            timer.Stop();
            Debug.Print("Ready to go");
        }

        void timer_Tick(GT.Timer timer)
        {
            if (camera.CameraReady)
            {
                Debug.Print("Camera is ready.");
                camera.TakePicture();
            }
            else
            {
                Debug.Print("Camera is busy.");
            }
        }

        void button_ButtonReleased(Button sender, Button.ButtonState state)
        {
            //throw new NotImplementedException();
        }

        void camera_PictureCaptured(GTM.GHIElectronics.Camera sender, GT.Picture picture)
        {
            display.SimpleGraphics.DisplayImage(picture, 0, 0);
        }

        void button_ButtonPressed(GTM.GHIElectronics.Button sender, GTM.GHIElectronics.Button.ButtonState state)
        {
            if (button.IsLedOn)
                timer.Stop();
            else
                timer.Start();
            
            button.ToggleLED();
        }

    }
}

and this code works fine with the camera (streaming), however the picture is full of yellow stripes, colors are partly messed up. The touch screen is fine, so my guess the camera is damaged.


using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerApp1
{
    public partial class Program
    {
Bitmap fullSize;
        Bitmap midSize;
        Bitmap halfSize;
        int testStep;
        GTM.GHIElectronics.Camera.PictureResolution FullSize = GTM.GHIElectronics.Camera.PictureResolution.Resolution320x240;
        GTM.GHIElectronics.Camera.PictureResolution MidSize = GTM.GHIElectronics.Camera.PictureResolution.Resolution176x144;
        GTM.GHIElectronics.Camera.PictureResolution HalfSize = GTM.GHIElectronics.Camera.PictureResolution.Resolution160x120;

        void ProgramStarted()
        {
            // Initialize event handlers here.
            // e.g. example.Pressed += new GTM.ManufacturerName.ExampleModule.EventHandler(example_Pressed);
            camera.CameraConnected += new GTM.GHIElectronics.Camera.CameraConnectedEventHandler(camera_CameraConnected);
            camera.BitmapStreamed += new GTM.GHIElectronics.Camera.BitmapStreamedEventHandler(camera_BitmapStreamed);
            camera.PictureCaptured += new GTM.GHIElectronics.Camera.PictureCapturedEventHandler(camera_PictureCaptured);
            button.ButtonPressed += new GTM.GHIElectronics.Button.ButtonEventHandler(button_ButtonPressed);
            fullSize = new Bitmap(FullSize.Width, FullSize.Height);
            midSize = new Bitmap(MidSize.Width, MidSize.Height);
            halfSize = new Bitmap(HalfSize.Width, HalfSize.Height);

            // Do one-time tasks here
            Debug.Print("\r\n*** Camera Test ***\r\n");
            Debug.Print("Note that this test expects a camera in socket , a display and a button in socket .");
            Debug.Print("Wait a moment...");
        }

        void camera_PictureCaptured(GTM.GHIElectronics.Camera sender, GT.Picture picture)
        {
            display.SimpleGraphics.DisplayImage(picture, 0, 0);
        }

        void button_ButtonPressed(GTM.GHIElectronics.Button sender, GTM.GHIElectronics.Button.ButtonState state)
        {
            switch (testStep)
            {
                case 0:
                    camera.StopStreamingBitmaps();
                    camera.CurrentPictureResolution = MidSize;
                    camera.StartStreamingBitmaps(midSize);
                    Debug.Print("Camera should be streaming medium sized images (176x144) to the center of the display.");
                    Debug.Print("Press button to continue.");
                    break;
                case 1:
                    camera.StopStreamingBitmaps();
                    camera.CurrentPictureResolution = HalfSize;
                    camera.StartStreamingBitmaps(halfSize);
                    Debug.Print("Camera should be streaming half sized images (160x120) to the display, above and left of center.");
                    Debug.Print("Press button to continue.");
                    break;
                case 2:
                    camera.StopStreamingBitmaps();
                    camera.CurrentPictureResolution = FullSize;
                    Debug.Print("Streaming from the camera has stopped.");
                    Debug.Print("Press the button again to take a full-sized picture.");
                    break;
                default:
                    camera.TakePicture();
                    Debug.Print("Picture taken. Press button to take another...");
                    break;
            }
            testStep++;
        }

        void camera_BitmapStreamed(GTM.GHIElectronics.Camera sender, Bitmap bitmap)
        {
            switch (testStep)
            {
                case 0:
                    display.SimpleGraphics.DisplayImage(bitmap, 0, 0);
                    break;
                case 1:
                    display.SimpleGraphics.DisplayImage(bitmap, display.Width / 2 - (uint)MidSize.Width / 2, display.Height / 2 - (uint)MidSize.Height / 2);
                    break;
                case 2:
                    display.SimpleGraphics.DisplayImage(bitmap, display.Width / 2 - (uint)HalfSize.Width, display.Height / 2 - (uint)HalfSize.Height);
                    break;
            }
        }

        void camera_CameraConnected(GTM.GHIElectronics.Camera sender)
        {
            Debug.Print("Camera test has started - camera should be streaming full size (320x240) to display");
            Debug.Print("Press button to continue.");
            testStep = 0;
            camera.CurrentPictureResolution = FullSize;
            camera.StartStreamingBitmaps(fullSize);
        }
    }
}

Ok, seems I was wrong. Uploading a jpg, colors still aren’t displayed the right way. So it seems the touch screen isn’t working.

You mean you tried to display some image (not from camera) and the colors are off? If so please contact GHI directly.

Yeah, colors are off. Hopefully it’s not the spider, just the touchscreen. I’ve contacted my reseller (waterott.com).