#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <string>
#define WINVER 0x0500
#include <windows.h>
#include <fstream>
#define CHECK_WALABOT_RESULT(result, func_name) \
{ \
if (result != WALABOT_SUCCESS) \
{ \
unsigned int extended = Walabot_GetExtendedError(); \
const char* errorStr = Walabot_GetErrorString(); \
std::cout << std::endl << "Error at " __FILE__ << ":" \
<< std::dec << __LINE__ << " - " \
<< func_name << " result is 0x" << std::hex \
<< result << std::endl; \
\
std::cout << "Error string: " << errorStr << std::endl; \
\
std::cout << "Extended error: 0x" << std::hex \
<< extended << std::endl << std::endl; \
\
std::cout << "Press enter to continue ..."; \
std::string dummy; \
std::getline(std::cin, dummy); \
return; \
} \
}
int gFlag = 0;
const double gDeltaY = 0.6;
const int gSampleSizeWindow = 6;
int gCleanSampleSize = 0;
int gRestTime = 300;
bool GotPositive(double YposSorted[])
{
for (int k = 0; k < gCleanSampleSize; k++)
{
if (YposSorted[k] > 0)
{
return true;
}
}
return false;
}
bool GotNegative(double YposSorted[])
{
for (int k = 0; k < gCleanSampleSize; k++)
{
if (YposSorted[k] < 0)
{
return true;
}
}
return false;
}
double* SortYposArray(double YposArray[])
{
double YposSorted[gSampleSizeWindow];
for (int k = 0; k < gSampleSizeWindow; k++)
{
if (YposArray[k] < 617)
{
YposSorted[gCleanSampleSize] = YposArray[k];
gCleanSampleSize++;
}
}
return YposSorted;
}
int GetScore(double YposSorted[])
{
int score = 0;
for (int k = 1; k < gCleanSampleSize; k++)
{
if ((YposSorted[k] - YposSorted[k - 1])<gDeltaY)
{
score++;
}
else if ((YposSorted[k] - YposSorted[k - 1])>gDeltaY)
{
score--;
}
}
return score;
}
void PageFlip(double YposArray[])
{
double *YsortedPointer;
YsortedPointer = SortYposArray(YposArray);
double YposSorted[gSampleSizeWindow];
for (int k = 0; k < gCleanSampleSize; k++)
{
YposSorted[k] = *(YsortedPointer + k);
}
if (GotNegative(YposSorted) == true && GotPositive(YposSorted) == true)
{
int Score = GetScore(YposSorted);
int CurrentCleanSampleSize = gCleanSampleSize;
gCleanSampleSize = 0;
if (Score > 0 && Score > (CurrentCleanSampleSize / 2.5))
{
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = 0x22;
ip.ki.dwFlags = 0;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
gFlag = 0;
Sleep(gRestTime);
}
else if (Score < 0 && abs(Score) >(CurrentCleanSampleSize / 2.5))
{
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = 0x21;
ip.ki.dwFlags = 0;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
gFlag = 0;
Sleep(gRestTime);
}
else
{
return;
}
}
else
{
gCleanSampleSize = 0;
return;
}
}
double GetYposOfClosestTarget(
SensorTarget *targets,
int numTargets)
{
int ClosestTargetIndex = 0;
double SizeOfClosestTargetYZ = sqrt(pow(targets[0].yPosCm, 2) + pow(targets[0].zPosCm, 2));
for (int k = 1; k < numTargets; k++)
{
double SizeOfTargetYZ = sqrt(pow(targets[k].zPosCm, 2) + pow(targets[k].yPosCm, 2));
if (SizeOfTargetYZ< SizeOfClosestTargetYZ)
{
ClosestTargetIndex = k;
SizeOfClosestTargetYZ = SizeOfTargetYZ;
}
}
return targets[ClosestTargetIndex].
yPosCm;
}
{
if (numTargets > 1)
{
return GetYposOfClosestTarget(targets, numTargets);
}
else if (numTargets == 1)
{
}
else
{
return 617;
}
}
void FlipPages_SampleCode()
{
double calibrationProcess;
int numTargets;
double YposArray[gSampleSizeWindow];
double rArenaMin = 10.0;
double rArenaMax = 40.0;
double rArenaRes = 5.0;
double thetaArenaMin = -20.0;
double thetaArenaMax = 20.0;
double thetaArenaRes = 10.0;
double phiArenaMin = -45.0;
double phiArenaMax = 45.0;
double phiArenaRes = 5.0;
double threshold = 8.0;
CHECK_WALABOT_RESULT(res, "Walabot_SetSettingsFolder");
CHECK_WALABOT_RESULT(res, "Walabot_ConnectAny");
CHECK_WALABOT_RESULT(res, "Walabot_SetProfile");
CHECK_WALABOT_RESULT(res, "Walabot_SetArenaR");
CHECK_WALABOT_RESULT(res, "Walabot_SetArenaTheta");
CHECK_WALABOT_RESULT(res, "Walabot_SetArenaPhi");
CHECK_WALABOT_RESULT(res, "Walabot_SetThreshold");
CHECK_WALABOT_RESULT(res, "Walabot_SetDynamicImageFilter");
CHECK_WALABOT_RESULT(res, "Walabot_Start");
CHECK_WALABOT_RESULT(res, "Walabot_StartCalibration");
CHECK_WALABOT_RESULT(res, "Walabot_GetStatus");
std::cout << "The app is up and running- to use the app, bring your file into focus" << '\n';
bool recording = true;
while (recording)
{
if (gFlag == 0)
{
for (int k = 0; k < gSampleSizeWindow; k++)
{
CHECK_WALABOT_RESULT(res, "Walabot_Trigger");
CHECK_WALABOT_RESULT(res, "Walabot_GetSensorTargets");
YposArray[k] = GetYpos(targets, numTargets);
}
gFlag = 1;
PageFlip(YposArray);
}
if (gFlag == 1)
{
for (int k = 1; k < gSampleSizeWindow; k++)
{
YposArray[k - 1] = YposArray[k];
}
CHECK_WALABOT_RESULT(res, "Walabot_Trigger");
CHECK_WALABOT_RESULT(res, "Walabot_GetSensorTargets");
YposArray[gSampleSizeWindow - 1] = GetYpos(targets, numTargets);
PageFlip(YposArray);
}
}
CHECK_WALABOT_RESULT(res, "Walabot_Stop");
CHECK_WALABOT_RESULT(res, "Walabot_Disconnect");
}
#ifndef _SAMPLE_CODE_
int main()
{
FlipPages_SampleCode();
}
#endif