Well I had a project with my friend that was making a short cut keyboard. So I thought I can make this mobile by Simblee BLE and executable file as a Driver for it. The computer will look for the serial commutation coming from the Simblee like the phone key 0 will send as serial 0 to the computer and the computer will receive it. Executable file driver will do a Keysend event to the key you customize to your liking. If the computer application is closed all keysend and serial setup is saved via My.Settings.save.
There was a Problem I ran into....The Problem I have ran into is that to get the program to set focus on the window that I want is that you need spy++ with is only on the paid version of Visual Studios with I don't have...boo.... This make things completed. I know how to do a dll import from user32.dll to uses FindWindow and SetForegroundWindow function within the dynamic library file but if you don't know the windows child id it will not set focus on what you need. I need to know both the child windows and the parent windows handlers.
So this might not be a workable project because of one little thing..... sorry you all but I still can give you what code I have and learn a little.
The Advantage of uses this over hardware keypress with ArduinoThe Advantage of uses this program then a hardware solution to this problem is...
Pros
- The hardware is program with a preset code that you will have to rewrite the code every time you like to do different key presses.
- The Arduino Leonardo and the mini both take control of the keyboard making your keyboard useless.
- The software is Customize-able to the user up to 16 keys.
- The hardware is only sending serial data to the software.
Cons
- The software has to be set to focus to the window you want to uses this does cause a problem.
coming soon....
The Visual Basic Driver Code brake down...Imports System.IO.Ports
This is the namespacing that give you access to the SerialPort Object for a Microsoft application.
Dim sp As New SerialPort()
The Dim is a way you declaring a variable that is stored in memory in Visual Basic.Net. The Variable is sp in my case which has the New SerialPort() object pass to it. The New give you a new instance of a object.
sp.PortName = My.Settings.Port
sp.BaudRate
sp.Parity
sp.StopBits
sp.Handshake
sp.DataBits
sp.ReadTimeout
sp.Open()
sp.ReadLine()
sp.Close()
The Sp.PortName is the Parameter for the port name with hold a String Value the My.Settings.Port is setup as a User with a String type this is where the user can configure his or hers own port that need to be access within the config form. If My.Settings.Port has the string "com1" in it this will be the port name that the program will open. The User in My.Settings.Port is for read and write if you want read only you have to put Application
The sp.BaudRate = My.Settings.Baud BaudRate properties has a integer type so any variable pass to it will have to be a integer.
sp.Parity = Parity.None this are Enums (Enumeration) so each on has a value to it. The StopBit and the Handshake are also Enums types. Party can be set to None, Even, Odd, Mark or Space ranging in value to 0 being None to 4 being Space.
sp.StopBits = StopBits.One the StopBits has Vaules of None (with is not supported by the StopBits property), One, OnepointFive or Two with have Values to 0 to 3.
sp.Handshake = Handshake.None the if you working with Arduino will be set always with to None.
sp.DataBits = 8 the DataBits have a type of Interger with the vaule of 5 to 8 with arduino it well be eight.
sp.ReadTimeout = 1000 the ReadTimeout has a type of a Interger and the value that you make it have will be in milliseconds before it will throw a time out error that you can us the Try and Catch statement to give the user the right error.
sp.Open() this Method open a new Serial Port connection to the serial port that is in PortName and all its required data that is need like BaudRate, Parity, StopBits, Handshake, and DataBits.
sp.ReadLine() this is one of the six ways to read serial in Visual Baisc.net. the ReadLine Method read the data from the com port to the newline is seen. If you was using a Arduino sending Serial.println(1); the ReadLine() method will read 1 and nothing after that. Also by using ReadLine I dont have to worry about what type of encoding is in my program.
sp.Close() this closes the port you have selected.
Imports System.Runtime.InteropServices
This is the library that give me access to the User32.dll that has the functions of FindWindow and SetForegroundWindow. This give me the ability to uses the default marshaling behavior of this namespacing.
Declare Auto Function FindWindow Lib "USER32.DLL" (ByVal lpClassName As String, _ ByVal lpWindowName As String) As IntPtr
The Declare statement give you access to procedure implemented in external file like the User32.dll. This statement creates a reference to an external procedure and supplies this necessary information. It is not just limited to Microsoft DLL files but could also work with your own Dynamic Libray Files. The declare statement must be only declared in class, structure, or module.
The Auto specifies that Visual Basic should marshal strings according to.NET Framework rules based on the external name of the external procedure being declared.
The Lib is Required. Introduces a Lib
clause, which identifies the external file (DLL or code resource) that contains an external procedure.
The ByVal specifies that an argument is passed in such a way that the called procedure or property cannot change the value of a variable underlying the argument in the calling code.
The IntPtr is platform-specific type that is used to represent a pointer or a handle. In this Code the lpClassName and the lpWindowName string are the handlers of the application being found. Is is what uses the System.Runtime.InteropService library that was imported.
Declare Auto Function SetForegroundWindow Lib "USER32.DLL"_
(ByVal hWnd As IntPtr) As Boolean
The
FindWindow
function
finds the window and the SetForegroundWindow set the focus on the window you pass the handles you get from Spy++(This program is not on the free version of Visual Studio) from the FindWindow function. with this it will return a zero if not successful and a none zero if it is successful.
Dim xhandle As IntPtr = FindWindow("CalcFrame", "Calculator")
If xhandle = IntPtr.Zero Then
MsgBox("The Program you have set is not running.")
Return
End If
SetForegroundWindow(xhandle)
The
xhandle variable passes the FindWindow function with the parameters of the window name and frame you are trying to find. In this example code it is to the Calculator and the CalcFrame.
In the IF statement if the xhandle has a value of 0 it was not ruining on the computer.
The SetForegroundWindow(xhandle) passes the xhandle to the SetForgroundWindow with set the focus to that window and not to the ruining application.
The Simblee Screen Shot#include <SimbleeForMobile.h>
The Simblee will need this library to be able to talk to the SimbleeForMobile app and uses it functions and objects.
uint8_t ui_button0;
The
uint8_t type declares the ui_button0 as a unsigned char value to hold the button in the simblee.
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
SimbleeForMobile.deviceName = "MOBILE KEYPAD";
// SimbleeForMobile.advertisementData = "Keypad";
// SimbleeForMobile.domain = "gamekey.gaming.com";
// Begin Simblee UI
SimbleeForMobile.begin();
//
}
The
voidsetup()
functionwesetupthesimblee
hardware. First we setup the deviceName with can be any string you would like this will show up on the Simblee For Mobile App when it is first loaded on your phone.
The advertisementData can also be any thing you like it is also in the first load up on your phone.
The domain is for the phone cache so you can store images within this domain string that you want it to go and can be uses on any device if you put it in your program under the same name.
The SimbleeforMobile.begin Object is uses to start the mobile application just like the serial.begin starts the serial in arduino.
void loop() {
// put your main code here, to run repeatedly:
// process must be called in the loop for Simblee UI
SimbleeForMobile.process();
}
The
void loop() function is uses to start the simbleeformobile process and to get updates on button color or text update by using SimbleeForMobile.updatable, SimbleeForMobile.updateText, SimbleeForMobile.updateValue, SimbleeForMobile.updateColor, or SimbleeForMobile.updateOrigin.
void ui()
{
SimbleeForMobile.beginScreen(WHITE);
SimbleeForMobile.drawText(90,230, "KEYPAD", BLUE, 50);
ui_button0 = SimbleeForMobile.drawButton(0,300,80,"0");
SimbleeForMobile.setEvents(ui_button0, EVENT_PRESS);
SimbleeForMobile.endScreen();
}
The void ui() function setups the GUI for the end user in this function you setup the buttons, text, the screen color, or any other things you will need for the users.
The SimbleeForMobile.beginScreen() Object is uses to set up the screen it is always the first to be declared in the void ui function. It holds your screen color. and it is always has to have a SimbleeForMobile.endScreen() Object just like html has to have <body></body> tag else it will not work. Just like the body tag of html it will have to have all text, buttons, and events made within this to functions.
The SimbleeForMobile.drawText() Object is where you can put any string you like too put in it. The first parameters are where you want to place the X, and Y coordinates of your phone this is different on different mobile devices so mine might not work for yours to find you mobile screen x and y just uses this SimbleeForMobile.screenWidth and SimbleeForMobile.screenHeight with Serial.println(). The next parameter is the String you would like to uses as the text you want drew. The next parameter will be the color of the text if you want it a different color you do not need this if you want. The next parameter is the text font size this is also optional. If you want this be be update able you will have to put this in a uint8_t
type just like I did my button on the next line.
The SimbleeForMobile.drawButton(x, y, size of button, text sting) the x, and y is the same as the drawText. The size of button is where you put the size of your button. and the last parameter is the text of your button.
The SimbleeForMobile.setEvents() Object has two parameter the first is the variable that holds the objects you want to event to be for. The second parameter is what even you want. The Even can be EVENT_PRESS, EVENT_RELEASE, EVENT_POSITION or EVENT_COLOR.
void ui_event(event_t &event)
{
if (event.id == ui_button0 ){
if (event.type == EVENT_PRESS){
Serial.println(0);
}
}
The
voidui_event()
function is the start of where the GUI get it's interface for the users. It has a event reference to get the events that are called by the setEvents object when the user presses the button.
The event.id is the Object variable that you are reference in your code.
The event.type is the event that is given when the object has done something this is defined in the setEvents Object.
My thought about the Simblee by RFDigital.I have been doing things with this device when the device was the rfduino and it required that you be a android or IOS programmer to do what you need to do even know the simblee can steal be setup with a custom android app or IOS app.
At first with the simblee and the rfduino the learn curve was slightly different then just working with the arduino boards I did get the hang of it. The other problem I had was the arduino IDE not always playing nice with the software in the rfduino days not now with the simblee. It has come leaps and bounds.
I like that you have one device with BLE within it. With arduino I have to buy a BLE breakout broad then have to wire it then get the functionally of that device.
I think it is a good investment if you want to try new hardware. You can get it cheaper on mouser.com ($35) then you can on digikeys.com ($38).
Comments