Moto Q Flashlight

Overview:

Moto Q Flashlight allows the user to control the state of the camera flash. It has three modes of operation: Normal, Strobe, and Morse Code. The application consists of a Win32 DLL written in Visual C++ that exposes the native API (see below) to control the camera flash and a GUI written in Visual C#.

The GUI was my first attempt at a Visual C# application and the DLL was my first attempt at Visual C++ so bear with me if you run across any issues. Big thanks to Marko with MOTODEV who showed me how to use the DeviceIoControl API with the flash.

I tested the application on my Moto Q and Microsoft Device Emulator. If you like this program or have any questions please leave a comment below.

Download:

Download version 0.1 (Binary .cab)
Download version 0.1 (Binary .zip)
Download version 0.1 (Source)

Installation:

Copy the executable or CAB to your Windows Mobile device and launch from the file manager.

Requirements:

Microsoft .NET Compact Framework 2.0

Changelog:

0.1 - August 29, 2007

  • Initial release

Native Code Example:

// Thanks again to Marko with Developer Technical Services at MOTODEV (www.motodev.com).
// This code would not be possible without him and is, for the most part, his work.
//
// I have added comments to the function to help other developers understand how to use
// the camera flash on the Moto Q (maybe other Windows Mobile Devices too?).

#include <winioctl.h>
#include <cs.h>
#include <csmedia.h>

//Public variables
HANDLE hCam = INVALID_HANDLE_VALUE;

BOOL CloseCameraHandle()
{
  if (!CloseHandle(hCam))
  {
    return FALSE;
  }
  else
  {
    hCam = INVALID_HANDLE_VALUE;
    return TRUE;
  }
}

BOOL DisableFlash()
{
  //OpenCameraHandle() should be called before disabling the flash
  //Should call CloseCameraHandle() after calling DisableFlash()
  CSPROPERTY_CAMERACONTROL_S InputBuffer;
  CSPROPERTY_CAMERACONTROL_S OutputBuffer;
  ULONG DataLength = sizeof(CSPROPERTY_CAMERACONTROL_S);
  ULONG ReturnedLength; // Number of bytes returned in output buffer 

  InputBuffer.Property.Set = PROPSETID_VIDCAP_CAMERACONTROL; 
  InputBuffer.Property.Id = CSPROPERTY_CAMERACONTROL_FLASH;
  InputBuffer.Property.Flags = CSPROPERTY_TYPE_SET;
  InputBuffer.Flags = CSPROPERTY_CAMERACONTROL_FLAGS_MANUAL;
  InputBuffer.Value = 0;  //1==flash on, 0==flash off  

  if (!DeviceIoControl(hCam, IOCTL_CS_PROPERTY, &InputBuffer, DataLength, &OutputBuffer, DataLength, &ReturnedLength, NULL))
  {
    return FALSE;
  }
  else
  {
    return TRUE;
  }
}

BOOL EnableFlash()
{
  //OpenCameraHandle() should be called before enabling the flash
  //Don’t call CloseCameraHandle() until you’ve called DisableFlash
  CSPROPERTY_CAMERACONTROL_S InputBuffer;
  CSPROPERTY_CAMERACONTROL_S OutputBuffer;
  ULONG DataLength = sizeof(CSPROPERTY_CAMERACONTROL_S);
  ULONG ReturnedLength; // Number of bytes returned in output buffer 

  InputBuffer.Property.Set = PROPSETID_VIDCAP_CAMERACONTROL; 
  InputBuffer.Property.Id = CSPROPERTY_CAMERACONTROL_FLASH;
  InputBuffer.Property.Flags = CSPROPERTY_TYPE_SET;
  InputBuffer.Flags = CSPROPERTY_CAMERACONTROL_FLAGS_MANUAL;
  InputBuffer.Value = 1;  //1==flash on, 0==flash off  

  if (!DeviceIoControl(hCam, IOCTL_CS_PROPERTY, &InputBuffer, DataLength, &OutputBuffer, DataLength, &ReturnedLength, NULL))
  {
    return FALSE;
  }
  else
  {
    return TRUE;
  }
}

BOOL OpenCameraHandle()
{
  //Only needs to be called once until CloseCameraHandle() is called
  HANDLE hTemp = CreateFile(TEXT("CAM1:"), GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

  if (hTemp == INVALID_HANDLE_VALUE)
  {
    return FALSE;
  }
  else
  {
    hCam = hTemp;
    return TRUE;
  }
}

One Response to “Moto Q Flashlight”

  1. Free Motorola Q Flashlight - Motorola Q - Hello Moto Q Forums Says:

    [...] Moto Q Flashlight | CharltonFamily.net It’s great, and better than paying 5 dollars for the pocketflashlight program. [...]

Leave a Reply

You must be logged in to post a comment.