Blame |
Last modification |
View Log
| RSS feed
/*
* *****MoteCtrl*****
* written by AndreasB (aka Alpin)
*
* lets you control your MikroKopter with a Wiimote!
*
*
* Copyright December 2008
*
* Credits & Thx:
* - Holger & Ingo for the MikroKopter Project (www.mikrokopter.de)
* - ExternalControl implementation of the FlightControl
* - Ligi for RIDDIM, proof of external control concept
* - Documentation of the MK's SerialProtocol (www.mikrokopter.de/ucwiki/en/SerialProtocol)
* - Michael Laforest for the wiiuse API (www.wiiuse.net)
*
*
* http://www.mikrokopter.de/ucwiki/en/MoteCtrl
*/
/*
*****Use at your own risk! No warranty. Only for private usage.*****
#LICENSE: Released under the GNU General Public License Version 2 or
(at your option) a later version of this license.
For further details see <www.gnu.org/licenses/>.
#DISCLAIMER: Use this project at your own risk!
No warrenty.
Only for private usage.
***** See READ_ME_FIRST.txt for further details about MoteCtrl *****
*/
/*
Compiler & Linker Porperties:
Set "Character Set"-CompilerFlag to "Not Set" or "Multi Byte Character Set" to
avoid Errors about Windows API functions that can handle Unicode paramters.
In Visual Studio: Properties of Project -> Configuration Properties -> General
*/
/*
When compiling, don't forget to link wiiuse.lib (interface to the wiiuse.dll)
In Visual Studio: Copy wiiuse.lib & wiiuse.dll to project directory.
Afterwards: Properties of Project -> Configuration Properties -> Linker
-> Input -> add "wiiuse.lib" to additional dependencies
*/
/*
To avoid problems with dependencies on other windows machines, link the used
windows DLLs statically to the project.
In Visual Studio: Properties of Project -> Config. Properties -> C/C++
-> Code Generation -> set "Runtime Library" to Multi-Threaded (/MT)
*/
/*Main.c merges all the resources provided by the header files to a functional
program. The follwing "includes" include all the needed and used headers (which
provide the resources, like fuctions, wrappers, structs, etc. main.c uses)
*/
/**********Main Header*********/
//OS libs:
#include <windows.h> //Windows API, for API macros, constants, etc. (like stdlib.h)
#include <stdio.h> //Standard I/O (printf for instance)
//MoteCtrl libs:
#include "pc_serial_port.h" //interface with a PC's serial port
#include "fc_comm.h" //encode & send data to FlightControl
#include "wiimote.h" //interface with the wiimote connected via Bluetooth
//#include "main.h"
//Pretty Text output: (==fun ;)
void prettyText
(char* string
) {
int printed
;
int i
;
//pretty text output:
printed
= printf("*****%s", string
);
for (i
=0;i
<(65-printed
);i
++) {
printf("*");
}
printf("\n");
}
int main
(int argc
, char* argv
[]) {
//temps & counters
int tmp
;
int tmp1
;
//int i;
//Print title:
printf("\n"); prettyText
("*"); printf("*v0.1\n"
"*\t****MoteCtrl**** written by Alpin\n"
"*\tlets you control your MikroKopter with a Wiimote!\n*\n");
prettyText
("*"); printf("\n");
//**********Serial COM Port init & config:
prettyText
("COM Port init");
printf("Serial COM Port you want to use to connect to the MikroKopter\n"
"(only type the number then hit enter):\n");
scanf_s
("%d", &tmp
); //read a decimal from terminal
tmp1
= init_com_port
(tmp
); //initialize & config COM port tmp
//init_com_port returned successfull?
if( tmp1
== EXIT_FAILURE
) {
printf("\n***COM%i Initilizaition/Configuration failed\n\n", tmp
);
prettyText
("COM Port Init FAILED!");
printf("exiting MoteCtrl...\n");
Sleep
(1000);
return EXIT_FAILURE
;
}
else { prettyText
("Init & config of COM DONE!"); printf("\n\n"); }
//**********Wiimote init & config:
prettyText
("Wiimote Init");
Sleep
(1000);
tmp
= init_wiimote
(); //initialize wiimote
//was init_wiimote successfull?
if (tmp
== EXIT_FAILURE
) {
prettyText
("Wiimote Init FAILED!");
printf("exiting MoteCtrl...\n");
Sleep
(1000);
return EXIT_FAILURE
;
}
else { prettyText
("Wiimote Init DONE!"); printf("\n\n"); }
/* Does not work yet:
if(mote[0]->exp.type == EXP_NUNCHUK) {printf("Nunchuck plugged in!"); }
else { printf("No Nunchuck extension found!"); }
*/
/***********Main: reading acc-values of wiimote, sending them as external-
control data to the MikroKopter's FlightControl: */
/* This is the Core of MotionCtrl, since it transfers the Wiimote data via the
external control srtuct and the serial protocol encoding to the
FlightCtrl.*/
//Initialize entire ExternControl-struct with zeros
SecureZeroMemory
(&ExternControl
, sizeof(struct str_ExternControl
));
//Activate the ExternalControl
//gas = 0; //init gas value
ExternControl.
Config = 1;
//Main loop, "virtual" polling the wiimote events:
while (1) {
//wiiuse_poll returns the number of wiimotes, at which an event occured:
if (wiiuse_poll
(mote
, MAX_WIIMOTES
)) {
switch (mote
[0]->event
) { //what type of event happened?
case WIIUSE_EVENT
:
//a generic event occured!
/*Call function, which does the following: transferring
the wiimote data to the ExternalControl struct: */
handle_event
(mote
[0]);
//Send the (by handle_event) updated ExternControl struct
//to the FlightCtrl:
SendOutData
('b', 1, (unsigned char *) &ExternControl
, sizeof(struct str_ExternControl
));
break;
default:
break;
}
}
}
/* Some early tests
muh:
i=0;
while (1) {
//externcon typedeffen
SendOutData('b', 1, (unsigned char *) &ExternControl, sizeof(struct str_ExternControl));
//i++;
}
//sendStringToCom("#bR@T\r",6); //send reset
i=0;
while(i<255) {
tmp = getCharFromCom(&b);
if (tmp) {
printf("%c", b);
i++;
}
}
goto muh;
*/
return EXIT_SUCCESS
;
}