@@ -162,32 +162,33 @@ void SampleListener::onExit(const Controller& controller) {
}

void SampleListener::onFrame(const Controller& controller) {
const Frame frame = controller.frame();
HandList hands = frame.hands();
try {
// First, we create a Hub with our application identifier. Be sure not to use the com.example namespace when
// publishing your application. The Hub provides access to one or more Myos.
myo::Hub hub("io.github.devinmui.finger");

std::cout << "Attempting to find a Myo..." << std::endl;

myo::Myo* myo = hub.waitForMyo(10000);

if (!myo) {
throw std::runtime_error("Unable to find a Myo!");
}

std::cout << "Connected to a Myo armband!" << std::endl << std::endl;


DataCollector collector;

hub.addListener(&collector);

float pitch = collector.pitch_w;
float yaw = collector.yaw_w;
const Frame frame = controller.frame();

HandList hands = frame.hands();
while(1) {

for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); hl++) {
const Hand hand = *hl;
hub.run(1000/20);
double foo = hand.palmPosition()[2];
std::cout << std::to_string(foo) << std::endl;
std::string pose = collector.currentPose.toString();
float init_pitch = collector.pitch_w;
float init_yaw = collector.yaw_w;
@@ -203,45 +204,38 @@ void SampleListener::onFrame(const Controller& controller) {
} else {
move_yaw = init_yaw - yaw;
}

// after calculations
if(move_pitch >= 1) {
std::cout << "YES" << std::endl;
} else {
std::cout << "NO" << std::endl;
}

//std::cout << "pitch: " << init_pitch << ", yaw: "<< init_yaw << std::endl;
pitch = init_pitch; // pitch should be around ~ 5+ difference
yaw = init_yaw; // yaw should be 1 - 2 difference
// whatever might not need yaw or roll just do pitch

if(pose == "fist"){
std::cout << "FISTBUMP!" << std::endl;
// play music based on calculations from leap motion
} else {
std::cout << "No fistbump :(" << std::endl;
}

// this doesnt execute...
for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {

const Hand hand = *hl;

std::cout << hand.palmPosition()[2] << std::endl;
}
}

// If a standard exception occurred, we print out its message and exit.
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
std::cerr << "Press enter to continue.";
std::cin.ignore();
std::cin.ignore()
;
//return -1;
}

}






void SampleListener::onFocusGained(const Controller& controller) {
@@ -275,20 +269,78 @@ int main(int argc, char** argv)
SampleListener listener;
Controller controller;

// Have the sample listener receive events from the controller
controller.addListener(listener);

if (argc > 1 && strcmp(argv[1], "--bg") == 0)
controller.setPolicy(Leap::Controller::POLICY_BACKGROUND_FRAMES);

// Keep this process running until Enter is pressed
std::cout << "Press Enter to quit..." << std::endl;
std::cin.get();

// Remove the sample listener when done
controller.removeListener(listener);
try {
myo::Hub hub("io.github.devinmui.finger");
std::cout << "Attempting to find a Myo..." << std::endl;

myo::Myo* myo = hub.waitForMyo(10000);

if (!myo) {
throw std::runtime_error("Unable to find a Myo!");
}

std::cout << "Connected to a Myo armband!" << std::endl << std::endl;


DataCollector collector;

hub.addListener(&collector);

float pitch = collector.pitch_w;
float yaw = collector.yaw_w;
while(1){
const Frame frame = controller.frame();
HandList hands = frame.hands();
for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); hl++) {
const Hand hand = *hl;
double foo = hand.palmPosition()[2];
std::cout << std::to_string(foo) << std::endl;
}
hub.run(1000/20);
std::string pose = collector.currentPose.toString();
float init_pitch = collector.pitch_w;
float init_yaw = collector.yaw_w;
float move_pitch = 0;
float move_yaw = 0;
if(init_pitch - pitch < 0) {
move_pitch = (init_pitch - pitch) * -1;
} else {
move_pitch = init_pitch - pitch; // calculate the movement of the pitch
}
if(init_yaw - yaw < 0) {
move_yaw = (init_yaw - yaw) * -1; // calculate the movement of the yaw
} else {
move_yaw = init_yaw - yaw;
}

// after calculations
if(move_pitch >= 1) {
std::cout << "YES" << std::endl;
} else {
std::cout << "NO" << std::endl;
}

//std::cout << "pitch: " << init_pitch << ", yaw: "<< init_yaw << std::endl;
pitch = init_pitch; // pitch should be around ~ 5+ difference
yaw = init_yaw; // yaw should be 1 - 2 difference
// whatever might not need yaw or roll just do pitch

if(pose == "fist"){
std::cout << "FISTBUMP!" << std::endl;
// play music based on calculations from leap motion
} else {
std::cout << "No fistbump :(" << std::endl;
}

}
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
std::cerr << "Press enter to continue.";
std::cin.ignore()
;
return -1;
}

return 0;

}

Binary file not shown.