Prepare for ARDUINO
This commit is contained in:
parent
00e307cccb
commit
cb733f03f7
97
TQInterface/SerialPort.cpp
Normal file
97
TQInterface/SerialPort.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Author: Manash Kumar Mandal
|
||||
* Modified Library introduced in Arduino Playground which does not work
|
||||
* This works perfectly
|
||||
* LICENSE: MIT
|
||||
*/
|
||||
|
||||
#include "SerialPort.h"
|
||||
|
||||
SerialPort::SerialPort(char *portName)
|
||||
{
|
||||
this->connected = false;
|
||||
|
||||
this->handler = CreateFileA(static_cast<LPCSTR>(portName),
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL);
|
||||
if (this->handler == INVALID_HANDLE_VALUE){
|
||||
if (GetLastError() == ERROR_FILE_NOT_FOUND){
|
||||
printf("ERROR: Handle was not attached. Reason: %s not available\n", portName);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ERROR!!!");
|
||||
}
|
||||
}
|
||||
else {
|
||||
DCB dcbSerialParameters = {0};
|
||||
|
||||
if (!GetCommState(this->handler, &dcbSerialParameters)) {
|
||||
printf("failed to get current serial parameters");
|
||||
}
|
||||
else {
|
||||
dcbSerialParameters.BaudRate = CBR_9600;
|
||||
dcbSerialParameters.ByteSize = 8;
|
||||
dcbSerialParameters.StopBits = ONESTOPBIT;
|
||||
dcbSerialParameters.Parity = NOPARITY;
|
||||
dcbSerialParameters.fDtrControl = DTR_CONTROL_ENABLE;
|
||||
|
||||
if (!SetCommState(handler, &dcbSerialParameters))
|
||||
{
|
||||
printf("ALERT: could not set Serial port parameters\n");
|
||||
}
|
||||
else {
|
||||
this->connected = true;
|
||||
PurgeComm(this->handler, PURGE_RXCLEAR | PURGE_TXCLEAR);
|
||||
Sleep(ARDUINO_WAIT_TIME);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SerialPort::~SerialPort()
|
||||
{
|
||||
if (this->connected){
|
||||
this->connected = false;
|
||||
CloseHandle(this->handler);
|
||||
}
|
||||
}
|
||||
|
||||
int SerialPort::readSerialPort(char *buffer, unsigned int buf_size)
|
||||
{
|
||||
DWORD bytesRead;
|
||||
unsigned int toRead;
|
||||
|
||||
ClearCommError(this->handler, &this->errors, &this->status);
|
||||
|
||||
if (this->status.cbInQue > 0){
|
||||
if (this->status.cbInQue > buf_size){
|
||||
toRead = buf_size;
|
||||
}
|
||||
else toRead = this->status.cbInQue;
|
||||
}
|
||||
|
||||
if (ReadFile(this->handler, buffer, toRead, &bytesRead, NULL)) return bytesRead;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool SerialPort::writeSerialPort(char *buffer, unsigned int buf_size)
|
||||
{
|
||||
DWORD bytesSend;
|
||||
|
||||
if (!WriteFile(this->handler, (void*) buffer, buf_size, &bytesSend, 0)){
|
||||
ClearCommError(this->handler, &this->errors, &this->status);
|
||||
return false;
|
||||
}
|
||||
else return true;
|
||||
}
|
||||
|
||||
bool SerialPort::isConnected()
|
||||
{
|
||||
return this->connected;
|
||||
}
|
||||
35
TQInterface/SerialPort.h
Normal file
35
TQInterface/SerialPort.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Author: Manash Kumar Mandal
|
||||
* Modified Library introduced in Arduino Playground which does not work
|
||||
* This works perfectly
|
||||
* LICENSE: MIT
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SERIALPORT_H
|
||||
#define SERIALPORT_H
|
||||
|
||||
#define ARDUINO_WAIT_TIME 2000
|
||||
#define MAX_DATA_LENGTH 255
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
class SerialPort
|
||||
{
|
||||
private:
|
||||
HANDLE handler;
|
||||
bool connected;
|
||||
COMSTAT status;
|
||||
DWORD errors;
|
||||
public:
|
||||
SerialPort(char *portName);
|
||||
~SerialPort();
|
||||
|
||||
int readSerialPort(char *buffer, unsigned int buf_size);
|
||||
bool writeSerialPort(char *buffer, unsigned int buf_size);
|
||||
bool isConnected();
|
||||
};
|
||||
|
||||
#endif // SERIALPORT_H
|
||||
61
TQInterface/StringAdditions.cpp
Normal file
61
TQInterface/StringAdditions.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
char *trimwhitespace(char *str)
|
||||
{
|
||||
char *end;
|
||||
|
||||
// Trim leading space
|
||||
while (isspace((unsigned char)*str)) str++;
|
||||
|
||||
if (*str == 0) // All spaces?
|
||||
return str;
|
||||
|
||||
// Trim trailing space
|
||||
end = str + strlen(str) - 1;
|
||||
while (end > str && isspace((unsigned char)*end)) end--;
|
||||
|
||||
// Write new null terminator
|
||||
*(end + 1) = 0;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
char *readLine(FILE *file) {
|
||||
|
||||
if (file == NULL) {
|
||||
printf("\nError: file pointer is null.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int maximumLineLength = 128;
|
||||
char *lineBuffer = (char *)malloc(sizeof(char) * maximumLineLength);
|
||||
|
||||
if (lineBuffer == NULL) {
|
||||
printf("\nError allocating memory for line buffer.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char ch = getc(file);
|
||||
int count = 0;
|
||||
|
||||
while ((ch != '\n') && (ch != EOF)) {
|
||||
if (count == maximumLineLength) {
|
||||
maximumLineLength += 128;
|
||||
lineBuffer = (char *)realloc(lineBuffer, maximumLineLength);
|
||||
if (lineBuffer == NULL) {
|
||||
printf("\nError reallocating space for line buffer.");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
lineBuffer[count] = ch;
|
||||
count++;
|
||||
|
||||
ch = getc(file);
|
||||
}
|
||||
|
||||
lineBuffer[count] = '\0';
|
||||
if (count > 0)
|
||||
return lineBuffer;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
@ -9,123 +9,13 @@ char *throttleQuadrantCFG;
|
||||
initialization init;
|
||||
uint8_t numEngines = 0;
|
||||
|
||||
// Event to catch beginning
|
||||
static enum EVENT_ID {
|
||||
EVENT_SIM_START,
|
||||
REQUEST_SYSTEM_STATE,
|
||||
};
|
||||
|
||||
// Definitions for levers, dynamically added to SimConnect
|
||||
static enum DATA_DEFINE_ID {
|
||||
DEFINITION_AC_DATA,
|
||||
DEFINITION_LEVER_ONE,
|
||||
DEFINITION_LEVER_TWO,
|
||||
DEFINITION_LEVER_THREE,
|
||||
DEFINITION_LEVER_FOUR,
|
||||
};
|
||||
|
||||
// Request ID
|
||||
static enum REQUEST_ID {
|
||||
AC_DATA_REQUEST,
|
||||
};
|
||||
|
||||
// Struct for ac data
|
||||
struct aircraftData {
|
||||
double numEngines;
|
||||
double lowerThrottleLimit;
|
||||
};
|
||||
|
||||
// Structs for levers
|
||||
struct engineJustThrottle {
|
||||
double throttlePercent;
|
||||
};
|
||||
|
||||
struct engineThrottleAndPropeller {
|
||||
double throttlePercent;
|
||||
double propellerPercent;
|
||||
};
|
||||
|
||||
struct engineThrottleAndMixture {
|
||||
double throttlePercent;
|
||||
double mixturePercent;
|
||||
};
|
||||
|
||||
struct engineAll {
|
||||
double throttlePercent;
|
||||
double propellerPrecent;
|
||||
double mixturePercent;
|
||||
};
|
||||
|
||||
//TESTING PURPOSE
|
||||
engineJustThrottle tc;
|
||||
|
||||
char *trimwhitespace(char *str)
|
||||
{
|
||||
char *end;
|
||||
|
||||
// Trim leading space
|
||||
while (isspace((unsigned char)*str)) str++;
|
||||
|
||||
if (*str == 0) // All spaces?
|
||||
return str;
|
||||
|
||||
// Trim trailing space
|
||||
end = str + strlen(str) - 1;
|
||||
while (end > str && isspace((unsigned char)*end)) end--;
|
||||
|
||||
// Write new null terminator
|
||||
*(end + 1) = 0;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
char *readLine(FILE *file) {
|
||||
|
||||
if (file == NULL) {
|
||||
printf("\nError: file pointer is null.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int maximumLineLength = 128;
|
||||
char *lineBuffer = (char *)malloc(sizeof(char) * maximumLineLength);
|
||||
|
||||
if (lineBuffer == NULL) {
|
||||
printf("\nError allocating memory for line buffer.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char ch = getc(file);
|
||||
int count = 0;
|
||||
|
||||
while ((ch != '\n') && (ch != EOF)) {
|
||||
if (count == maximumLineLength) {
|
||||
maximumLineLength += 128;
|
||||
lineBuffer = (char *)realloc(lineBuffer, maximumLineLength);
|
||||
if (lineBuffer == NULL) {
|
||||
printf("\nError reallocating space for line buffer.");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
lineBuffer[count] = ch;
|
||||
count++;
|
||||
|
||||
ch = getc(file);
|
||||
}
|
||||
|
||||
lineBuffer[count] = '\0';
|
||||
if (count > 0)
|
||||
return lineBuffer;
|
||||
else
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
void setupDefinitions() {
|
||||
printf("\nSetting up...");
|
||||
printf("\nSetting up ... ");
|
||||
HRESULT hr;
|
||||
hr = SimConnect_ClearDataDefinition(hSimConnect, DEFINITION_LEVER_ONE);
|
||||
hr = SimConnect_ClearDataDefinition(hSimConnect, DEFINITION_LEVER_TWO);
|
||||
hr = SimConnect_ClearDataDefinition(hSimConnect, DEFINITION_LEVER_THREE);
|
||||
hr = SimConnect_ClearDataDefinition(hSimConnect, DEFINITION_LEVER_FOUR);
|
||||
hr = SimConnect_ClearDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE);
|
||||
hr = SimConnect_ClearDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO);
|
||||
hr = SimConnect_ClearDataDefinition(hSimConnect, DEFINITION_ENGINE_THREE);
|
||||
hr = SimConnect_ClearDataDefinition(hSimConnect, DEFINITION_ENGINE_FOUR);
|
||||
FILE *fp = fopen(throttleQuadrantCFG, "r");
|
||||
char * line = NULL;
|
||||
uint8_t numEngines = 0;
|
||||
@ -170,27 +60,143 @@ void setupDefinitions() {
|
||||
{
|
||||
switch (numEngines) {
|
||||
case 1:
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LEVER_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
break;
|
||||
case 2:
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LEVER_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LEVER_ONE, "GENERAL ENG THROTTLE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG THROTTLE LEVER POSITION:2", "percent");
|
||||
break;
|
||||
case 3:
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LEVER_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LEVER_ONE, "GENERAL ENG THROTTLE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LEVER_ONE, "GENERAL ENG THROTTLE LEVER POSITION:3", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG THROTTLE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_THREE, "GENERAL ENG THROTTLE LEVER POSITION:3", "percent");
|
||||
break;
|
||||
case 4:
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LEVER_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LEVER_ONE, "GENERAL ENG THROTTLE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LEVER_ONE, "GENERAL ENG THROTTLE LEVER POSITION:3", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_LEVER_ONE, "GENERAL ENG THROTTLE LEVER POSITION:4", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG THROTTLE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_THREE, "GENERAL ENG THROTTLE LEVER POSITION:3", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_FOUR, "GENERAL ENG THROTTLE LEVER POSITION:4", "percent");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (hasPropeller && !hasMixture)
|
||||
{
|
||||
switch (numEngines) {
|
||||
case 1:
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG PROPELLER LEVER POSITION:1", "percent");
|
||||
break;
|
||||
case 2:
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG THROTTLE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG PROPELLER LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG PROPELLER LEVER POSITION:2", "percent");
|
||||
break;
|
||||
case 3:
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG THROTTLE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_THREE, "GENERAL ENG THROTTLE LEVER POSITION:3", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG PROPELLER LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG PROPELLER LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_THREE, "GENERAL ENG PROPELLER LEVER POSITION:3", "percent");
|
||||
break;
|
||||
case 4:
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG THROTTLE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_THREE, "GENERAL ENG THROTTLE LEVER POSITION:3", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_FOUR, "GENERAL ENG THROTTLE LEVER POSITION:4", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG PROPELLER LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG PROPELLER LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_THREE, "GENERAL ENG PROPELLER LEVER POSITION:3", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_FOUR, "GENERAL ENG PROPELLER LEVER POSITION:4", "percent");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (!hasPropeller && hasMixture)
|
||||
{
|
||||
switch (numEngines) {
|
||||
case 1:
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG MIXTURE LEVER POSITION:1", "percent");
|
||||
break;
|
||||
case 2:
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG THROTTLE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG MIXTURE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG MIXTURE LEVER POSITION:2", "percent");
|
||||
break;
|
||||
case 3:
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG THROTTLE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_THREE, "GENERAL ENG THROTTLE LEVER POSITION:3", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG MIXTURE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG MIXTURE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_THREE, "GENERAL ENG MIXTURE LEVER POSITION:3", "percent");
|
||||
break;
|
||||
case 4:
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG THROTTLE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_THREE, "GENERAL ENG THROTTLE LEVER POSITION:3", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_FOUR, "GENERAL ENG THROTTLE LEVER POSITION:4", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG MIXTURE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG MIXTURE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_THREE, "GENERAL ENG MIXTURE LEVER POSITION:3", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_FOUR, "GENERAL ENG MIXTURE LEVER POSITION:4", "percent");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (hasPropeller && hasMixture)
|
||||
{
|
||||
switch (numEngines) {
|
||||
case 1:
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG MIXTURE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG MIXTURE LEVER POSITION:1", "percent");
|
||||
break;
|
||||
case 2:
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG THROTTLE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG PROPELLER LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG PROPELLER LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG MIXTURE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG MIXTURE LEVER POSITION:2", "percent");
|
||||
break;
|
||||
case 3:
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG THROTTLE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_THREE, "GENERAL ENG THROTTLE LEVER POSITION:3", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG PROPELLER LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG PROPELLER LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_THREE, "GENERAL ENG PROPELLER LEVER POSITION:3", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG MIXTURE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG MIXTURE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_THREE, "GENERAL ENG MIXTURE LEVER POSITION:3", "percent");
|
||||
break;
|
||||
case 4:
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG THROTTLE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_THREE, "GENERAL ENG THROTTLE LEVER POSITION:3", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_FOUR, "GENERAL ENG THROTTLE LEVER POSITION:4", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG PROPELLER LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG PROPELLER LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_THREE, "GENERAL ENG PROPELLER LEVER POSITION:3", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_FOUR, "GENERAL ENG PROPELLER LEVER POSITION:4", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_ONE, "GENERAL ENG MIXTURE LEVER POSITION:1", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_TWO, "GENERAL ENG MIXTURE LEVER POSITION:2", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_THREE, "GENERAL ENG MIXTURE LEVER POSITION:3", "percent");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ENGINE_FOUR, "GENERAL ENG MIXTURE LEVER POSITION:4", "percent");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("done!");
|
||||
}
|
||||
|
||||
// SimConnect callback
|
||||
@ -207,7 +213,7 @@ void CALLBACK MyDispatchProcTC(SIMCONNECT_RECV* pData, DWORD cbData, void *pCont
|
||||
switch (data->dwRequestID) {
|
||||
case AC_DATA_REQUEST:
|
||||
{
|
||||
printf("\Aircraft data retrieved");
|
||||
printf("Aircraft data retrieved.");
|
||||
init.maxRev = (int8_t)((aircraftData *)&data->dwData)->lowerThrottleLimit;
|
||||
numEngines = (uint8_t)((aircraftData *)&data->dwData)->numEngines;
|
||||
setupDefinitions();
|
||||
@ -234,8 +240,8 @@ void CALLBACK MyDispatchProcTC(SIMCONNECT_RECV* pData, DWORD cbData, void *pCont
|
||||
throttleQuadrantCFG = (char *)calloc(strlen(path) + 6, 1);
|
||||
strcpy(throttleQuadrantCFG, path);
|
||||
strcat(throttleQuadrantCFG, "tq.cfg");
|
||||
printf("\n%s loaded.", throttleQuadrantCFG);
|
||||
printf("\nRetrieving aicraft data...");
|
||||
printf("%s loaded.", throttleQuadrantCFG);
|
||||
printf("\nRetrieving aicraft data ... ");
|
||||
hr = SimConnect_RequestDataOnSimObject(hSimConnect, AC_DATA_REQUEST, DEFINITION_AC_DATA, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_ONCE);
|
||||
break;
|
||||
}
|
||||
@ -255,7 +261,7 @@ void CALLBACK MyDispatchProcTC(SIMCONNECT_RECV* pData, DWORD cbData, void *pCont
|
||||
case EVENT_SIM_START:
|
||||
{
|
||||
// Send this request to get the user aircraft id
|
||||
printf("\n\nRequesting loaded AC path...");
|
||||
printf("\nRequesting loaded AC path ... ");
|
||||
hr = SimConnect_RequestSystemState(hSimConnect, REQUEST_SYSTEM_STATE, "AircraftLoaded");
|
||||
}
|
||||
break;
|
||||
@ -277,7 +283,7 @@ void CALLBACK MyDispatchProcTC(SIMCONNECT_RECV* pData, DWORD cbData, void *pCont
|
||||
}
|
||||
}
|
||||
|
||||
void testThrottleControl()
|
||||
void throttleControl()
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
@ -287,8 +293,6 @@ void testThrottleControl()
|
||||
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_AC_DATA, "NUMBER OF ENGINES", "number");
|
||||
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_AC_DATA, "THROTTLE LOWER LIMIT", "percent");
|
||||
|
||||
// Set up a data definition for the throttle control
|
||||
|
||||
//hr = SimConnect_SetDataOnSimObject(hSimConnect, DEFINITION_LEVER_ONE, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(tc), &tc);
|
||||
|
||||
@ -307,7 +311,6 @@ void testThrottleControl()
|
||||
|
||||
int __cdecl _tmain(int argc, _TCHAR* argv[])
|
||||
{
|
||||
testThrottleControl();
|
||||
|
||||
throttleControl();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -149,11 +149,13 @@
|
||||
<Text Include="ReadMe.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="SerialPort.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
<ClInclude Include="targetver.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp" />
|
||||
<ClCompile Include="SerialPort.cpp" />
|
||||
<ClCompile Include="StringAdditions.cpp" />
|
||||
<ClCompile Include="TQInterface.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
||||
@ -24,12 +24,18 @@
|
||||
<ClInclude Include="targetver.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="SerialPort.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<ClCompile Include="TQInterface.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="TQInterface.cpp">
|
||||
<ClCompile Include="StringAdditions.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="SerialPort.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// TQInterface.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
||||
@ -5,8 +5,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "targetver.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#include <stdio.h>
|
||||
@ -15,6 +13,8 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "SimConnect.h"
|
||||
#include "SerialPort.h"
|
||||
#include "targetver.h"
|
||||
|
||||
#pragma comment(lib, "SimConnect.lib")
|
||||
|
||||
@ -29,3 +29,52 @@ typedef struct values {
|
||||
int8_t leverValuesInPercent[4];
|
||||
} values;
|
||||
|
||||
char *trimwhitespace(char *str);
|
||||
char *readLine(FILE *file);
|
||||
|
||||
// Event IDs
|
||||
static enum EVENT_ID {
|
||||
EVENT_SIM_START,
|
||||
REQUEST_SYSTEM_STATE,
|
||||
};
|
||||
|
||||
// Data definition IDs, engines dynamically added
|
||||
static enum DATA_DEFINE_ID {
|
||||
DEFINITION_AC_DATA,
|
||||
DEFINITION_ENGINE_ONE,
|
||||
DEFINITION_ENGINE_TWO,
|
||||
DEFINITION_ENGINE_THREE,
|
||||
DEFINITION_ENGINE_FOUR,
|
||||
};
|
||||
|
||||
// Request IDs
|
||||
static enum REQUEST_ID {
|
||||
AC_DATA_REQUEST,
|
||||
};
|
||||
|
||||
// Struct for ac data
|
||||
struct aircraftData {
|
||||
double numEngines;
|
||||
double lowerThrottleLimit;
|
||||
};
|
||||
|
||||
// Structs for engines
|
||||
struct engineJustThrottle {
|
||||
double throttlePercent;
|
||||
};
|
||||
|
||||
struct engineThrottleAndPropeller {
|
||||
double throttlePercent;
|
||||
double propellerPercent;
|
||||
};
|
||||
|
||||
struct engineThrottleAndMixture {
|
||||
double throttlePercent;
|
||||
double mixturePercent;
|
||||
};
|
||||
|
||||
struct engineAll {
|
||||
double throttlePercent;
|
||||
double propellerPrecent;
|
||||
double mixturePercent;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user