From 63d0c699593649f20076c862b078b031ed842c1a Mon Sep 17 00:00:00 2001 From: james schaefer Date: Tue, 5 Feb 2019 05:49:45 -0800 Subject: [PATCH] huge cleanup to grindhouse, and associated files. added set duration, set remaining timers to shm. added set function to grindhouse to simplify setting up various workouts. --- Makefile | 2 +- bin/rmshm.sh | 2 +- src/cat_shm.cpp | 41 +++++++++++++++++--- src/grindhouse.cpp | 95 ++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 116 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 1905de1..afbdbf5 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ BINARIES = anaerobic_tracker cat_shm cli_incline cli_log cli_speed heartrate \ hr_tracker kiosk_sim logger mkshm scripted_session timestamp \ - ct5k_w1 + ct5k_w1 grindhouse BINDIR = ./bin/ SOURCEDIR = ./src/ diff --git a/bin/rmshm.sh b/bin/rmshm.sh index f150b9f..04584f9 100755 --- a/bin/rmshm.sh +++ b/bin/rmshm.sh @@ -6,7 +6,7 @@ # climbing wall. #============================================================================== -TARGET_LIST="curr_halt curr_incline curr_speed duration elevation heartrate heartrate_avg heartrate_avg_duration heartrate_driven heartrate_target log_active req_halt req_incline req_speed start_time timestamp" +TARGET_LIST="curr_halt curr_incline curr_speed session_duration elevation heartrate heartrate_avg heartrate_avg_duration heartrate_driven heartrate_target log_active req_halt req_incline req_speed session_start_time timestamp set_duration set_start_time set_count" echo removing all climbing-wall entries from /dev/shm. for BIN in $TARGET_LIST diff --git a/src/cat_shm.cpp b/src/cat_shm.cpp index 13464db..2542905 100644 --- a/src/cat_shm.cpp +++ b/src/cat_shm.cpp @@ -7,10 +7,31 @@ #include "Shm_vars.h" #include #include +#include using std::cout; using std::endl; +std::string print_duration(const int& duration) +{ + int mins = duration / 60; + int secs = duration - (mins * 60); + string printable_duration ,tmp_mins, tmp_secs = ""; + std::stringstream ss_mins; + std::stringstream ss_secs; + + ss_mins << mins; + ss_secs << secs; + + ss_mins >> tmp_mins; + ss_secs >> tmp_secs; + printable_duration += tmp_mins; + printable_duration += ":"; + printable_duration += tmp_secs; + + return printable_duration; +} + int main (void) { @@ -18,18 +39,26 @@ int main (void) for(;;) { - int set_total_seconds_remaining = (SHM::set_start_time->get() + (SHM::set_duration->get()*60)) - SHM::timestamp->get(); - int set_mins_remaining = set_total_seconds_remaining % 60; + int set_seconds_elapsed = SHM::timestamp->get() - SHM::set_start_time->get(); + //int set_total_seconds_remaining = (SHM::set_duration->get()*60) - set_seconds_elapsed; + int set_total_seconds_remaining = SHM::set_duration->get() - set_seconds_elapsed; + + + int set_mins_remaining = set_total_seconds_remaining / 60; int set_remainder_seconds_remaining = set_total_seconds_remaining - (set_mins_remaining * 60); cout << "timestamp : " << SHM::timestamp->get() << endl; cout << "session start time : " << SHM::session_start_time->get() << endl << endl; cout << "session duration : " << SHM::session_duration->get() << endl << endl; - cout << "set start time : " << SHM::session_start_time->get() << endl << endl; - cout << "set count : " << SHM::set_count->get() << endl << endl; - cout << "set time remaining : " << SHM::set_count->get() << endl << endl; - cout << "set duration : " << SHM::session_duration->get() << endl << endl; + cout << "set count : " << SHM::set_count->get() << endl; + cout << "set start time : " << SHM::set_start_time->get() << endl; + //cout << "set duration : " << SHM::set_duration->get() << endl; + //cout << "set time remaining : " << set_total_seconds_remaining << endl << endl; + cout << "set duration : " << print_duration(SHM::set_duration->get()) << endl; + cout << "set time remaining : " << print_duration(set_total_seconds_remaining) << endl << endl; + + //cout << "set time remaining : " << set_mins_remaining<< ":"<< set_remainder_seconds_remaining << endl << endl; cout << "curr_halt : " << SHM::curr_halt->get() << endl; cout << "curr_speed : " << SHM::curr_speed->get() << endl; diff --git a/src/grindhouse.cpp b/src/grindhouse.cpp index 2d00f3b..0baea93 100644 --- a/src/grindhouse.cpp +++ b/src/grindhouse.cpp @@ -1,5 +1,5 @@ //============================================================================= -// scripted_session.cpp +// grindhouse.cpp // // This program sets up a workout consisting of sets and reps. // It also interacts with both the logger and the climbing wall correctly. @@ -12,35 +12,98 @@ //============================================================================= #include "Shm_vars.h" #include +#include -const int SETS = 5; +const int SETS = 2; + +std::string print_duration(const int& duration) +{ + int mins = duration / 60; + int secs = duration - (mins * 60); + string printable_duration ,tmp_mins, tmp_secs = ""; + std::stringstream ss_mins; + std::stringstream ss_secs; + + ss_mins << mins; + ss_secs << secs; + + ss_mins >> tmp_mins; + ss_secs >> tmp_secs; + printable_duration += tmp_mins; + printable_duration += ":"; + printable_duration += tmp_secs; + + return printable_duration; +} + +void run_set(float duration /*in mins*/, int speed /*in feet per minute*/, int set_count) +{// first gives the user a 10 second warning before the beginning of a set. + // then turns on the treadwall at the given speed for the given duration. + // then halts the treadwall for a "rest". This rest is roughly 60% the + // duration of the work set, but not less than 90 seconds. + if (duration < 0) + return; + + SHM::set_count->set(set_count); + int work_duration = duration * 60; + const float rest_percentage = 0.6; + int rest_duration = ((duration * 60) * rest_percentage ); + if (rest_duration < 90) + rest_duration = 90; + + std::cout << std::endl << std::endl; + std::cout << "Begin Set: " << set_count + //<< std::endl << ", work duration: " << work_duration + //<< std::endl << ", rest_duration: " << rest_duration; + << std::endl << ", work duration: " << print_duration(work_duration) + << std::endl << ", rest_duration: " << print_duration(rest_duration); + std::cout << std::endl << std::endl; + + // perform user wake-up, to alert them to the start of the set + SHM::req_speed->set(speed); + sleep(2); + SHM::req_speed->set(0); + std::cout << "Get Ready to Climb." << std::endl; + sleep(8); + + // begin the work set + SHM::set_start_time->set(SHM::timestamp->get()); + SHM::set_duration->set(work_duration); + SHM::req_speed->set(22); + sleep(work_duration); + + // begin the rest set + SHM::set_start_time->set(SHM::timestamp->get()); + SHM::set_duration->set(rest_duration); + SHM::req_speed->set(0); + sleep(10); + system( "killall -9 kiosk_sim"); + sleep(rest_duration - 30); + + system( "./kiosk_sim& > /dev/null 2>&1 "); + sleep(10); + +} int main (void) { SHM::connect_existing_shm(); - SHM::start_time->set(SHM::timestamp->get()); + SHM::session_start_time->set(SHM::timestamp->get()); + SHM::log_active->set(0); - //SHM::log_active->set(1); SHM::req_speed->set(0); + system( "./kiosk_sim& > /dev/null 2>&1 "); + sleep (5); for (int set_counter = 1; set_counter <= SETS; ++set_counter) { - SHM::req_speed->set(22); - sleep(2); - SHM::req_speed->set(0); - std::cout << "Get Ready to Climb." << std::endl; - sleep(8); - SHM::req_speed->set(22); - std::cout << "begin set " << set_counter << " of " << SETS << std::endl; - sleep(2*60); - SHM::req_speed->set(0); - std::cout << " rest " << set_counter << " of " << SETS << std::endl; - sleep((4*60)-10); + run_set(7, 22, 1); + run_set(7, 22, 2); + run_set(7, 22, 3); } SHM::req_speed->set(0); std::cout << "WORKOUT COMPLETE!!! " << std::endl; SHM::req_speed->set(0); - //SHM::log_active->set(0); return 0; }