Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!

Working with Sensors, Devices and Platform Services in your C++ applications

All of our modern PCs, Smartphones, Tablets and other devices include more than just a screen, keyboard, mouse, memory, and storage. The devices We use include sensors for location, orientation, acceleration, ambient light, etc. My Samsung Slate Series 7 is a hybrid or “2 for 1” device that is both a desktop PC and a Tablet. It includes two cameras and accelerometer. Even if they don’t include a GPS or other hardware sensor, our programs can use APIs to find the location from known Internet access points.  Some smartphones and tablets include two camera devices.  PCs for some time have had both a built-in microphone and a line-input jack. Different operating systems and hardware platforms provide different services:  Windows and Mac support menus, dialogs and mice, most include support for a canvas for low level drawing, a GPU (at least one or more) is available for higher performance 2D and 3D graphics, earlier versions of iOS did not provide a cut/copy/paste clipboard, server side systems may not provide a screen service, and there are many other services that we may or not have access to for C++ applications we build that need to run on different platforms.  What is a C++ developer supposed to do build applications that can run on a variety of systems and platforms?  The choices are varied and include using platform APIs, querying the hardware directly, adding conditional compilation to source code, and other methods.

Having access to a robust component framework that provides start-of-the-art components, classes and interfaces that do the work for you, greatly improves your ability to build applications for a wider arrange of systems.  C++Builder XE4 allows you to query for services, devices and sensors to know what your application can use.  FM, the component framework from Embarcadero Technologies, provides everything a C++ developer needs to query devices, count the number of sensors, and know which services are available for application use.  FM itself uses the same sensor, device and platform services to know how to initialize itself on each of the target platforms.  What sensors, device and services are supported for C++ application development? Let’s take a look at each of the three in more detail.


FM’s support for sensors is organized into sensor categories:


  • Location


  • Environmental


  • Motion


  • Orientation


  • Mechanical


  • Electrical


  • Biometric


  • Light


  • Scanner

The sensor category definition in System.Sensors.hpp is:

TSensorCategory : unsigned char { Location, Environmental, Motion, Orientation, Mechanical, Electrical, Biometric, Light, Scanner }

For each sensor category there are many possible sensor types including:


  • TLocationSensorType : unsigned char { GPS, Static, Lookup, Triangulation, Broadcast, DeadReckoning, Other };


  • TEnvironmentalSensorType : unsigned char { Temperature, AtmosphericPressure, Humidity, WindSpeed, WindDirection };


  • TMotionSensorType : unsigned char { Accelerometer1D, Accelerometer2D, Accelerometer3D, MotionDetector, Gyrometer1D, Gyrometer2D, Gyrometer3D, Speedometer };


  • TOrientationSensorType : unsigned char { Compass1D, Compass2D, Compass3D, Inclinometer1D, Inclinometer2D, Inclinometer3D, Distance1D, Distance2D, Distance3D };


  • TElectricalSensorType : unsigned char { Voltage, Current, Capacitance, Resistance, Inductance, ElectricalPower, Potentiometer };


  • TMechanicalSensorType : unsigned char { BooleanSwitch, BooleanSwitchArray, MultiValueSwitch, Force, Scale, Pressure, Strain };


  • TBiometricSensorType : unsigned char { HumanPresence, HumanProximity, Touch };


  • TLightSensorType : unsigned char { AmbientLight };


  • TScannerSensorType : unsigned char { RFID, Barcode };


In your C++ code you can get a count of the identified sensors, sensor name, sensor category and type, sensor state and more.



Once you know which sensors are available in your application you can chose to use the FM components and classes directly in your applications.  You can also query to ensure that a specific sensor is available for your application to use.  When you build your applications for Windows and Mac in C++Builder XE4 you’ll have easy access to all of the sensors available on each of your target systems.

In this next article, learn about how you can convert int to char C++ in this article about String Operations.


How many cameras do your PCs, Smartphones and Tablets have?  How many audio inputs does you application have access to?  You use use FM’s support for device managers to be able to use them in your applications.  Each FM based application includes a default device manager.  The Device Manager interfaces will give you the device name, media type of the device (audio/video), the device state and other information about specific devices.  You can query and filter for specific device media types or iterate through the collection of devices to find the ones your application is looking for.



The following C++ code snippet lists the audio and video capture devices available to your application.



The following C++ code snippet shows you how to support a system with one or two video cameras (like my Samsung Slate Series 7).



Platform Services

Each target platform comes with its support for different application and user interface paradigms.  These platform services can include, but are not limited to, the following types of services:


  • Application Service


  • Dialog Service


  • Canvas Service


  • Context Service


  • Locale Service


  • Clipboard Service


  • Cursor Service


  • Device Service


  • Drag and Drop Service


  • Hide App Service


  • Mouse Service


  • Screen Service


  • Style Service


  • Style HiRes Service


  • System Font Service


  • Text Service


  • Virtual Keyboard Service


  • Menu Service


  • Window Service


  • Window Border Service


  • Timer Service

In your C++ applications you can query whether a service is available on a target platform. If the service is available, use the native platform service or provide your own or a third party alternative.  For Windows and Mac development it is safe to assume that there is a mouse, menu, dialog and clipboard.  As your C++ applications move beyond the desktop, you may not have a dialog or menu service, but you can probably assume that there will be a virtual keyboard service.

Using the SupportsPlatformService method will return true or false if the service is available to your application.  The second method will return the service so that you can use it in your code.



Here is a FM based C++ code snippet that lets you test to see if there is a virtual keyboard service available to your application and uses it:



Using Devices, Sensors and Platform Services in your Applications

I’ve written blog posts and created videos that show C++ developers how to work with sensors, devices and platform services.  Take a look at the following links for additional information.











As C++ developers move beyond the desktop, the same component framework will take you and your code to new platforms, devices, embedded applications and beyond.

From Scooter Software, this Beyond Compare download on the next article will allow you and your organization to compare and reconcile files or system drives in a more agile manner.

Next, find out how you can convert String to Int C++ in this article about Modern C++ Software.

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.