"Switch-App" simulation using Touch Injection API in Windows 8 - C++ code - touch

A simple way to switch between application in Windows 8 is "Swipe Right" using the touch screen (put down one finger in the left side of the screen and move it a few pixels to the right). I'm trying to simulate this behavior using Touch Injection API but the switch app behavior is not invoked although the feedback shows the swipe is actually happening.
Here's the code I ran:
int main()
{
//Screen Resolution 1366x768
BOOL ret = TRUE;
//init
InitializeTouchInjection(10, TOUCH_FEEDBACK_INDIRECT);
POINTER_TOUCH_INFO contact = {0};
memset(&contact, 0, sizeof(POINTER_TOUCH_INFO));
contact.pointerInfo.pointerType = PT_TOUCH;
contact.pointerInfo.pointerId = 0;
//set start point (a point at the left side of the screen)
contact.pointerInfo.ptPixelLocation.y = 768/2;
contact.pointerInfo.ptPixelLocation.x = 0;
contact.touchFlags = TOUCH_FLAG_NONE;
contact.touchMask = TOUCH_MASK_CONTACTAREA | TOUCH_MASK_ORIENTATION | TOUCH_MASK_PRESSURE;
contact.orientation = 90;
contact.pressure = 32000;
contact.rcContact.top = contact.pointerInfo.ptPixelLocation.y -2;
contact.rcContact.bottom = contact.pointerInfo.ptPixelLocation.y + 2;
contact.rcContact.left = contact.pointerInfo.ptPixelLocation.x -2;
contact.rcContact.right = contact.pointerInfo.ptPixelLocation.x + 2;
//set flags for "start touch"
contact.pointerInfo.pointerFlags = POINTER_FLAG_DOWN | POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT;
ret = InjectTouchInput(1, &contact);
cout << "X: " << contact.pointerInfo.ptPixelLocation.x << " Y: " << contact.pointerInfo.ptPixelLocation.y << endl;
if(ret != TRUE)
{
cout << "Error 1: " << GetLastError() <<endl;
return 1;
}
for(int i=0; i<100; i++)
{
//set flags for "update"
contact.pointerInfo.pointerFlags = POINTER_FLAG_UPDATE | POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT;
//move the location one pixel right
contact.rcContact.bottom = contact.pointerInfo.ptPixelLocation.x++;
ret = InjectTouchInput(1, &contact);
cout << "X: " << contact.pointerInfo.ptPixelLocation.x << " Y: " << contact.pointerInfo.ptPixelLocation.y << endl;
if(ret != TRUE)
{
cout << "Error 2: " << GetLastError() <<endl;
return 1;
}
}
//set flags for "end touch"
contact.pointerInfo.pointerFlags = POINTER_FLAG_UP;
ret = InjectTouchInput(1, &contact);
cout << "X: " << contact.pointerInfo.ptPixelLocation.x << " Y: " << contact.pointerInfo.ptPixelLocation.y << endl;
if(ret != TRUE)
{
cout << "Error 3: " << GetLastError() <<endl;
return 1;
}
return 0;
}
Is there any idea why this code doesn't behave as expected?
By the way, same happens when trying to "Swipe Left" to open Charms-Bar
The code is written relating on this article

Related

how can I disable windows micphone enhancement by c++ code?

is there a way to disable the microphone audio enhancements from C++ code?
We are doing some audio processing things on the incoming microphone signal, and the microphone enhancements cause all kinds of trouble. We know we can turn it off manually on Windows10 by going to the Control panel --> Sound --> Recording --> Microphone --> Properties --> advanced--> Enhancements, but we need a way to do this from code.
enter image description here
when I try to access it via C++ It comes back saying there is no AGC on the device.
void AudioDeviceWindowsCore::DisableHardwareAGC() {
// get device topology object for that endpoint
CComPtr<IDeviceTopology> pTopo = NULL;
HRESULT ret = _ptrDeviceIn->Activate(__uuidof(IDeviceTopology), CLSCTX_ALL, NULL,
(void**)&pTopo);
if (FAILED(ret)) {
RTC_LOG(LS_ERROR) << "Couldn't get device topology object: hr = 0x"
<< rtc::ToHex(ret);
} else {
UINT count = 0;
pTopo->GetConnectorCount(&count);
CComPtr<IConnector> pConn = NULL;
ret = pTopo->GetConnector(0, &pConn);
if (FAILED(ret)) {
RTC_LOG(LS_ERROR) << __FUNCTION__ << " GetConnector:" << rtc::ToHex(ret);
return ;
}
CComPtr<IConnector> pConnNext = NULL;
ret = pConn->GetConnectedTo(&pConnNext);
if (FAILED(ret)) {
RTC_LOG(LS_ERROR) << __FUNCTION__
<< " GetConnectedTo:" << rtc::ToHex(ret);
return ;
}
CComPtr<IPart> pPart = NULL;
const IID IID_IPart = __uuidof(IPart);
ret = pConnNext->QueryInterface(IID_IPart, (void**)&pPart);
if (FAILED(ret)) {
RTC_LOG(LS_ERROR) << __FUNCTION__
<< " QueryInterface:" << rtc::ToHex(ret);
return ;
}
// all the real work is done in this function
ret = WalkTreeForwardsFromPart(pPart);
if (SUCCEEDED(ret)) {
RTC_LOG(INFO) << " now close hardware AGC ret:" << rtc::ToHex(ret);
} else {
RTC_LOG(INFO) << " Hardware not Supports Microphone AGC";
}
}
}
HRESULT WalkTreeForwardsFromPart(IPart* pPart) {
HRESULT hr = S_OK;
LPWSTR pwszPartName = NULL;
hr = pPart->GetName(&pwszPartName);
if (FAILED(hr)) {
RTC_LOG(LS_ERROR) << "Could not get part name: hr = 0x"<<rtc::ToHex(hr);
return hr;
}
RTC_LOG(INFO) << "Part name: " << *pwszPartName ? pwszPartName : L"Unnamed";
CoTaskMemFree(pwszPartName);
GUID type_id;
hr = pPart->GetSubType(&type_id);
if (hr == S_OK){
if (IsEqualGUID(type_id,KSNODETYPE_LOUDNESS) ) {
const IID IID_IAudioLoudness = __uuidof(IAudioLoudness);
IAudioLoudness* loudness = NULL;
hr = pPart->Activate(CLSCTX_ALL, IID_IAudioLoudness, (void**)&loudness);
if (E_NOINTERFACE == hr) {
RTC_LOG(LS_ERROR) << "NO AudioLoudness CONTROL";
// not a Microphone node
} else if (FAILED(hr)) {
RTC_LOG(LS_ERROR) << "Unexpected failure trying to activate "
"IID_IAudioLoudness : hr = 0x"
<< rtc::ToHex(hr);
} else {
// it's an AGC node...
RTC_LOG(INFO) << "HAS IAudioLoudness CONTROL";
hr = loudness->SetEnabled(0, NULL);
if (FAILED(hr)) {
RTC_LOG(LS_ERROR)
<< "AudioLoudness Failed: hr = 0x" << rtc::ToHex(hr);
loudness->Release();
return hr;
}
loudness->Release();
}
} else if (IsEqualGUID(type_id, KSNODETYPE_AGC)) {
// Check AGC settings
const IID IID_IAudioAutoGainControl = __uuidof(IAudioAutoGainControl);
IAudioAutoGainControl* aGCcontrol = NULL;
hr = pPart->Activate(CLSCTX_ALL, IID_IAudioAutoGainControl,
(void**)&aGCcontrol);
if (E_NOINTERFACE == hr) {
RTC_LOG(LS_ERROR) << "NO AGC CONTROL";
// not a Microphone node
} else if (FAILED(hr)) {
RTC_LOG(LS_ERROR) << "Unexpected failure trying to activate "
"IAudioAutoGainControl : hr = 0x"
<< rtc::ToHex(hr);
return hr;
} else {
// it's an AGC node...
RTC_LOG(INFO) << "HAS AGC CONTROL";
aGCcontrol->SetEnabled(0, NULL);
if (FAILED(hr)) {
RTC_LOG(LS_ERROR) << "AGC Failed: hr = 0x" << rtc::ToHex(hr);
aGCcontrol->Release();
return hr;
}
aGCcontrol->Release();
}
}
}
// get the list of incoming parts
IPartsList* pOutgoingParts = NULL;
hr = pPart->EnumPartsOutgoing(&pOutgoingParts);
if (E_NOTFOUND == hr) {
// not an error... we've just reached the end of the path
RTC_LOG(INFO) << "No incoming parts at this part";
return hr;
}
if (FAILED(hr)) {
RTC_LOG(LS_ERROR) << " Couldn't enum outgoing parts";
return hr;
}
UINT nParts = 0;
hr = pOutgoingParts->GetCount(&nParts);
if (FAILED(hr)) {
RTC_LOG(LS_ERROR) << "Couldn't get count of outgoing parts";
pOutgoingParts->Release();
return hr;
}
// walk the tree on each incoming part recursively
for (UINT n = 0; n < nParts; n++) {
IPart* pOutgoingPart = NULL;
hr = pOutgoingParts->GetPart(n, &pOutgoingPart);
if (FAILED(hr)) {
RTC_LOG(LS_ERROR) << "Couldn't get part ";
pOutgoingParts->Release();
return hr;
}
hr = WalkTreeForwardsFromPart(pOutgoingPart);
if (FAILED(hr)) {
RTC_LOG(LS_ERROR) << " Couldn't walk tree on part";
pOutgoingPart->Release();
pOutgoingParts->Release();
return hr;
}
pOutgoingPart->Release();
}
pOutgoingParts->Release();
return S_OK;
}

Omnet++ error when simulating multiple submodules

I am trying to simulate 10 submodules. But omnet++ gives an error when the number of submodules are greater than five. here is the error:
(omnetpp::cMessage)sampleEvent: par(int): Has no parameter #4 -- in module (Sam1) Net.sampler1[4] (id=6), during network initialization
My .ned file
simple Sam1
{
parameters:
#display("i=block/routing");
gates:
inout gate[]; // declare two way connections
}
simple Svr1
{
parameters:
#display("i=block/process");
gates:
inout gate[]; // declare two way connections
}
network Net
{
#display("bgb=670.56,274.32");
types:
channel Ch extends ned.DelayChannel
{
delay = 100ns;
}
submodules:
sampler1[10]: Sam1 {
#display("p=334,127;is=l");
}
server: Svr1 {
parameters:
#display("i=,gold;p=109.21999,88.899994");
}
connections:
for i=0..9 {
server.gate++ <--> Ch <--> sampler1[i].gate++;
}
}
omnetpp.ini file
[General]
[Config Net]
network = Net
record-eventlog = true
sam1 class
#include <stdio.h>
#include <string.h>
#include <omnetpp.h>
using namespace omnetpp;
class Sam1 : public cSimpleModule
{
private:
simtime_t timeout; // timeout
cMessage *sampleEvent; // holds pointer to the self-message
int seq; // message sequ ence number
cMessage *message; // message that has to be re-sent on timeout
double vK;
double vM;
double threshold = 1.0;
int counter;
double xmean = 0.01;
double xsigma = 1;
double sensigma = 0.1;
double x;
double zOut = 0.0;
double previousSentTime = 0.0;
int samplerID;
double xSum;
long numSent;
long numReceived;
long totalEvents;
cLongHistogram SampleStats;
cOutVector SampleVector;
cLongHistogram interSampleStats;
cOutVector interSampleVector;
cLongHistogram sentSampleStats;
cOutVector sentSampleVector;
cOutVector constructedSignal;
public:
Sam1();
virtual ~Sam1();
protected:
virtual cMessage *generateNewMessage();
virtual void sampleAndSend(cMessage *msg);
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
// The finish() function is called by OMNeT++ at the end of the simulation:
virtual void finish();
};
Define_Module(Sam1);
Sam1::Sam1()
{
sampleEvent = message = nullptr;
}
Sam1::~Sam1()
{
cancelAndDelete(sampleEvent);
delete message;
}
void Sam1::initialize()
{
// Initialize variables.
vM = 0;
seq = 0;
timeout = 100.0; // in every 100 second
sampleEvent = new cMessage("sampleEvent");
xSum = 0.0;
counter = 1;
numSent = 0;
numReceived = 0;
totalEvents = 0;
WATCH(numSent);
WATCH(totalEvents);
samplerID = getIndex();
interSampleStats.setName("interSampleStats");
interSampleStats.setRangeAutoUpper(0, 10, 1.5);
interSampleVector.setName("interSample");
SampleStats.setName("SampleStats");
// interSampleStats.setRangeAutoUpper(0, 10, 1.5);
SampleVector.setName("Sample");
sentSampleStats.setName("sentSampleStats");
// interSampleStats.setRangeAutoUpper(0, 10, 1.5);
sentSampleVector.setName("sentSample");
constructedSignal.setName("constructedSignal");
// Generate and send initial message.
EV << "Sending initial message\n";
message = generateNewMessage();
sampleAndSend(message);
// scheduleAt(simTime()+timeout, sampleEvent);
}
void Sam1::handleMessage(cMessage *msg)
{
if (msg == sampleEvent) {
// EV << "sampling Again\n";
// Ready to send another one.
message = generateNewMessage();
sampleAndSend(message);
}
}
cMessage *Sam1::generateNewMessage()
{
// Generate a message
cMessage *msg = new cMessage("sampleEvent");
double t1 = simTime().dbl() * 1000;
msg->addPar("sampleValue");
x = normal(xmean, xsigma) + normal(xmean, sensigma);
xSum = x + xSum;
msg->par("sampleValue").setDoubleValue(xSum);
msg->addPar("counter");
msg->par("counter").setLongValue(counter);
msg->addPar("generatedTimestamp");
msg->par("generatedTimestamp").setDoubleValue(t1);
msg->addPar("samplerName");
msg->par(samplerID);
counter = counter +1;
totalEvents++;
return msg;
}
void Sam1::sampleAndSend(cMessage *msg)
{
double sampleValue = msg->par("sampleValue").doubleValue();
double genTimestamp = msg->par("generatedTimestamp").doubleValue();
cMessage *copy = (cMessage *)msg->dup();
vK = sampleValue-vM;
// EV << vK << " vK \n";
if(fabs(sampleValue-vM) > threshold){
vM = sampleValue;
zOut = sampleValue;
// In this example, we just pick a random gate to send it on.
// We draw a random number between 0 and the size of gate `out[]'.
int n = gateSize("gate");
int k = intuniform(0, n-1);
send(copy, "gate$o", k);
double t2 = simTime().dbl() * 1000; // sample time in milli seconds
double interSample = t2 - previousSentTime;
previousSentTime = genTimestamp;
numSent++;
interSampleVector.record(interSample);
interSampleStats.collect(interSample);
sentSampleVector.record(1);
sentSampleStats.collect(1);
}else{
zOut = vM;
sentSampleVector.record(0);
sentSampleStats.collect(0);
}
EV << "vM " << vM << endl;
// EV << "sampling Again. node " << simTime() << endl;
SampleVector.record(sampleValue);
SampleStats.collect(sampleValue);
constructedSignal.record(zOut);
scheduleAt(simTime()+timeout, sampleEvent);
}
void Sam1::finish(){
// This function is called by OMNeT++ at the end of the simulation.
EV << "Sent: " << numSent << endl;
EV << "Total Events: " << totalEvents << endl;
float rate = (float)numSent/totalEvents;
EV << "Traffic Reduction: " << rate << endl;
EV << "Threshold: " << threshold << endl;
EV << "Signal Mean: " << xmean << endl;
EV << "Signam sigma: " << xsigma << endl;
EV << "Sensor Sigma: " << sensigma << endl;
EV << "Inter Sample Time, min: " << interSampleStats.getMin() << endl;
EV << "Inter Sample Time, max: " << interSampleStats.getMax() << endl;
EV << "Inter Sample Time, mean: " << interSampleStats.getMean() << endl;
EV << "Inter Sample Time, stddev: " << interSampleStats.getStddev() << endl;
recordScalar("#sent", numSent);
recordScalar("#total", totalEvents);
interSampleStats.recordAs("inter sample");
SampleStats.recordAs("sample");
sentSampleStats.recordAs("sent sample");
}
/**
* Sends back an acknowledgement -- or not.
*/
class Svr1 : public cSimpleModule
{
protected:
virtual void handleMessage(cMessage *msg) override;
};
Define_Module(Svr1);
void Svr1::handleMessage(cMessage *msg)
{
double sampleValue = msg->par("sampleValue").doubleValue();
long counter = msg->par("counter").longValue();
long samplerID = msg->par("samplerName").longValue();
EV << sampleValue << " received, sending back an acknowledgment from sampler "<< samplerID << ". counter " << counter << "\n";
delete msg;
// In this example, we just pick a random gate to send it on.
// We draw a random number between 0 and the size of gate `out[]'.
int n = gateSize("gate");
int k = msg->getArrivalGate()->getIndex();
EV << "n: " << n << "k: " << k << endl;
// send(new cMessage("ack"), "gate$o", k);
}

Question about the What's In the Box code game assignment

I am struggling to understand how to properly use pass by value and reference in this program. It keeps saying identifier is undefined when I put the Int in the main function. But when it's out of the main function it works fine. I can't use it outside of the main function otherwise it's an automatic 0. Am I just missing code that identifies it?
I didn't explain the program very well. It's essentially the Monty Hall problem but with boxes. The user then tries to guess the right box. The biggest issue I had was getting the non prize box to appear to the user in the output.
I am very new to coding so I am probably overlooking something.
#include <stdlib.h>
#include <iomanip>
#include <iostream>
#include <time.h>
#include <string>
using namespace std;
/*******************************************************************************
* Function Name: main()
* Parameters: None
* Return Value: int
* Purpose: To execute the main function of the program. Performs loops and takes user input to execute the game.
*****************************************************************************/
void BoxCheck(int);
void PrizeBox(int&);
//int UserGuess = 0;
int main()
{
int UserChoice;
int UserGuess;
int BoxReveal;
int PrizeB;
// int Prize;
//char Switch;
cout << "Wellcome to Pandora's Prize!" << endl;
cout << "Infront of you there are three doors, and behind one of them is the grand prize!" << endl;
cout << "But in the the other two they contain a stink bomb." << endl;
cout << "It's your job to guess which one has the prize behind it." << endl;
cout << "Door 1?" << endl;
cout << "Door 2?" << endl;
cout << "Door 3?" << endl;
PrizeBox(PrizeB);
cin >> UserGuess;
BoxReveal != (PrizeB || UserGuess);
// cout << "The host revealed box number " << BoxReveal << " ." << endl;
//if (true)
//{
if (UserGuess == 1)
{
cout << "You picked box 1." << endl;
cout << "The host revealed box number " << BoxReveal << " ." << endl;
cout << "Would you like to stay with box number 1 or switch." << endl;
//cin >> UserChoice;
}
else if (UserGuess == 2)
{
cout << "You picked box 2." << endl;
cout << "The host revealed box number " << BoxReveal << " ." << endl;
cout << "Would you like to stay with box number 2 or switch." << endl;
//cin >> UserChoice;
}
else if (UserGuess == 3)
{
cout << "You picked box 3." << endl;
cout << "The host revealed box number " << BoxReveal << " ." << endl;
cout << "It contains a red snapper!" << endl;
cout << "Would you like to stay with box number 3 or switch." << endl;
//cin >> UserChoice;
}
else
{
cout << "This isn't a number associated with a box. Try again." << endl;
}
//}
/* if (true)
{
} */
//PrizeBox(Prize);
if (UserChoice == UserGuess)
{
cout << "You chose to stay with your original box." << endl;
BoxCheck(UserGuess);
}
else if (UserChoice != UserGuess) //|| UserChoice != BoxReveal)
{
cout << "You decided to switch." << endl;
BoxCheck(UserGuess);
}
/*else if (UserChoice != UserGuess || BoxReveal)
{
cout << "You decided to switch." << endl;
BoxCheck(UserGuess);
} */
else
{
cout << "Your answer was out of the parameters." << endl;
BoxCheck(UserGuess);
}
//BoxCheck(UserGuess);
system("pause");
return 0;
}
void PrizeBox(int& PrizeB)
{
srand(time(NULL));
PrizeB = rand() % 3 + 1;
//Prize = rand() % 3 + 1;
//cin >> PrizeB;
/* BoxReveal = !(PrizeBox || boxChoice);
cout << "Here is one of the box's opened! " << boxReveal << " ." << endl;
BSwitch = (boxChoice || boxReveal); */
}
void BoxCheck(int UserChoice)
{
if (UserChoice == PrizeB)
{
cout << "WOW YOU WON!!!!" << endl;
}
else if (UserChoice != PrizeB)
{
cout << "Sorry you got a red snapper" << endl;
}
else
{
cout << "Sorry you got a red snapper" << endl;
}
}

How to get OpenGL-ES working on Raspberry Pi with SDL2?

I am trying to get OpenGL-ES working on a Raspberry Pi, but so far no luck. I compiled SDL 2.0.3 from source with this, as the version in Rasbian is missing Raspberry Pi support:
./configure --prefix=/home/pi/run/SDL2-2.0.3/ \
--disable-video-x11 \
--disable-pulseaudio \
--disable-esd \
--disable-video-opengl
The code below should create a OpenGL context and clear the screen to red. When I run the code, the Raspberry Pi is switching video modes, but the screen is turning black instead of red and the calls to glGetString(GL_VERSION) and Co. return NULL which would indicate that something is wrong with the GL context creation.
#include <SDL.h>
#include <SDL_opengles2.h>
#include <iostream>
void print_gl_string(GLenum name)
{
const GLubyte* ret = glGetString(name);
if (ret == 0)
{
std::cerr << "error getting string: " << name << std::endl;
}
else
{
std::cerr << name << ": " << ret << std::endl;
}
}
void set_gl_attribute(SDL_GLattr attr, int value)
{
if (SDL_GL_SetAttribute(attr, value) != 0)
{
std::cerr << "SDL_GL_SetAttribute(" << attr << ", " << value << ") failed: " << SDL_GetError() << std::endl;
}
}
int main()
{
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
std::cerr << "SDL_Init() failed: " << SDL_GetError() << std::endl;
exit(EXIT_FAILURE);
}
SDL_DisplayMode videomode;
if (SDL_GetCurrentDisplayMode (0, &videomode) != 0)
{
std::cerr << "Error getting current display mode: " << SDL_GetError() << std::endl;
exit(EXIT_FAILURE);
}
std::cout << "Current screen mode: " << videomode.w << "x" << videomode.h << std::endl;
set_gl_attribute(SDL_GL_RED_SIZE, 5);
set_gl_attribute(SDL_GL_GREEN_SIZE, 6);
set_gl_attribute(SDL_GL_BLUE_SIZE, 5);
//set_gl_attribute(SDL_GL_DEPTH_SIZE, 8);
set_gl_attribute(SDL_GL_DOUBLEBUFFER, 1);
set_gl_attribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
set_gl_attribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
set_gl_attribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_Window* window = SDL_CreateWindow("Minimal SDL2 Example",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
720, 576,
SDL_WINDOW_OPENGL);
if (!window)
{
std::cerr << "Could not create window: " << SDL_GetError() << std::endl;
exit(EXIT_FAILURE);
}
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
print_gl_string(GL_RENDERER);
print_gl_string(GL_SHADING_LANGUAGE_VERSION);
print_gl_string(GL_VERSION);
print_gl_string(GL_EXTENSIONS);
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(window);
SDL_Delay(5000);
SDL_GL_DeleteContext(gl_context);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
The problem turned out to not be in the code, but in the library path. A simple -L/opt/vc/lib/ added to the compile command line fixed it. Without that the compiler would pick:
/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2
While the right one would be (use ldd to check):
/opt/vc/lib/libGLESv2.so

Undefined reference to a method in another class file, how to fix?

I've been working on a program that will do a couple of equations in regards to audio, SPL, etc.
I decided to have the main class file present the user with an option to choose what equation he wants to do, while the equations are housed in another class file.
Atm, the main class file is setup just to test maxPeakSPL(), yet I can't get it to run.
main.cpp
//Kh[a]os
#include "equations.h"
#include <iostream>
void mainLoop();
int maxSPL = 0;
int main()
{
std::cout << "Created by Kh[a]os" << std::endl << std::endl;
mainLoop();
return 0;
}
void mainLoop()
{
std::cout << "hi";
maxSPL = equations::maxPeakSPL();
std::cout << std::endl << maxSPL << "db" << std::endl << std::endl;
}
equations.h
#ifndef EQUATIONS_H
#define EQUATIONS_H
#include <string>
class equations
{
public:
equations();
static int maxPeakSPL();
protected:
private:
};
#endif // EQUATIONS_H
equations.cpp
#include "equations.h"
#include <iostream>
#include <string>
equations::equations()
{
}
static int maxPeakSPL()
{
int Sens = 0;
double Distance = 0;
int Watts = 0;
int sWatts = 2;
int eWatts = 0;
double maxSPL = 0;
double counter = 0;
double wall = 0;
std::string corner = "";
bool v = true;
std::cout << "Sensitivity (db): " << std::endl;
std::cin >> Sens;
std::cout << "Amplification (watts): " << std::endl;
std::cin >> Watts;
std::cout << "Listening Distance (meters): " << std::endl;
std::cin >> Distance;
std::cout << "Distance from Wall (ft): " << std::endl;
std::cin >> wall;
std::cout << "Are you they in a corner? (y/n): " << std::endl;
std::cin >> corner;
maxSPL = Sens - (Distance*3 - 3);
while(v == true)
{
if (sWatts > Watts)
{
v = false;
eWatts = sWatts;
sWatts = sWatts/2;
Watts = Watts-sWatts;
counter = (double)Watts/(double)eWatts;
counter = counter*3;
maxSPL = maxSPL + counter;
}
if (v == true)
{
maxSPL = maxSPL + 3;
sWatts = sWatts*2;
}
}
if (wall <= 4)
maxSPL = maxSPL + 3;
if (corner == "Y" || corner == "YES" || corner == "y" || corner == "yes")
maxSPL = maxSPL + 3;
return maxSPL;
}
The error I get when I run it is: undefined reference to `equations::maxPeakSPL()'
I haven't a clue how to fix this, any assistance would be great. Thank you.
In your main, try putting the function before the main block. Include an underscore before the name of your directives/flags.