1 Brief
This Experiment on punch in air has completed the first part, get to know what I have. It can be easy using Serial Tool like Putty to test this Gesture sensor Kits.
I choose to build my own windows drive so that I can customize the function and gesture of my own. But I have an unexpected long office-leave for over 6 weeks. The schedule is disrupted. Hence, part of the unfinished work is listed in this blog.
2 The windows Drive
There are several choices for Serial Drive in Windows 10 with different to and pro. Finally, I use native Windows drive, "window.h", there are enough documents on Microsoft website for detail. Just like all peripherals, create the thread for port, buffing the data, then destroy the thread after used.
/* * Windows Serial Port for Windows API * * Copyright (c) 2016 Ondrej Sterba <osterba@inbox.com> */ #ifndef SERIALPORT___H #define SERIALPORT___H #include <windows.h> #define SERIALPORT_INTERNAL_TIMEOUT 100 class TSerialPort { private: HANDLE m_portHandle; HANDLE m_workingThread; DWORD m_workingThreadId; int m_timeoutMilliSeconds; int m_maxPacketLength; void (*m_OnDataReceivedHandler)(const unsigned char* pData, int dataLength); void (*m_OnDataSentHandler)(void); CRITICAL_SECTION m_criticalSectionRead; CRITICAL_SECTION m_criticalSectionWrite; int __ReadBuffer(unsigned char* pData, int dataLength, int timeOutMS=-1); int __WriteBuffer(const unsigned char* pData, int dataLength); public: TSerialPort(); ~TSerialPort(); int GetMaxTimeout(); void* GetDataReceivedHandler(); void* GetDataSentHandler(); bool Open(int comPortNumber, int baudRate, int timeoutMS=1000); bool OpenAsync( int comPortNumber, int baudRate, void (*OnDataReceivedHandler)(const unsigned char* pData, int dataLength), void (*OnDataSentHandler)(void), int timeoutMS=100 ); void Close(); bool IsOpen(); int ReadBuffer(unsigned char* pData, int dataLength, int timeOutMS=-1); int WriteBuffer(const unsigned char* pData, int dataLength); int ReadLine(char* pLine, int maxBufferSize, int timeOutMS=-1); int WriteLine(char* pLine, bool addCRatEnd=true); }; DWORD WINAPI SerialPort_WaitForData( LPVOID lpParam ); #endif
Use of the windows serial drive API make the design clear as my main(),
#include "SerialPort.hpp"" #include <stdio.h> int main(int argc, char* argv[]) { char response[64]; TSerialPort com1; com1.Open(3, 9600, 1000); while(1) { com1.WriteLine("050010"); com1.ReadLine(response, sizeof(response)); printf("Response: %s\r\n", response); Sleep(1000); } com1.Close(); return 0; }
This demo use COM1 as default serial port, the serial port can be scanned and probed. when MAX25405 is plugged.
Then parse the contend of the serial port to get what the gesture is.
3 Integrated in Game Engine
I have built one simple out-of-box game with Godot Engine. It can be controlled with keyboard and mouse at same time. With the Gesture sensor kit added, there are third choice of input. The new hardware integration mechanism in Godot is GDNative C++. With customized bottom API code, such as my serial driver under windows.h, the game can use new hardware.
There is also choices of other game engine like Epic, Unreal, Unity, etc., they both work well. But need proper skill and commercial license.
4 Things to do.
The MAX25405 is definitely great design and balance the cost and performance. The use of MAX25405 in game is just one typical application, there are other affordable choices in entry control and simple Men-Machine interface. It would be interesting if I can make it.
Slow progress makes the experiment cease half-way. Quite a lot of functions yet not to be validated. I shall share the progress in later projects.