Skip to content

Commit

Permalink
huge cleanup to grindhouse, and associated files.
Browse files Browse the repository at this point in the history
added set duration, set remaining timers to shm.
added set function to grindhouse to simplify setting up
various workouts.
  • Loading branch information
james-schaefer committed Feb 5, 2019
1 parent 888755b commit 63d0c69
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion bin/rmshm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 35 additions & 6 deletions src/cat_shm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,58 @@
#include "Shm_vars.h"
#include <iostream>
#include <iomanip>
#include <sstream>

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)
{

SHM::connect_existing_shm();

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;
Expand Down
95 changes: 79 additions & 16 deletions src/grindhouse.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -12,35 +12,98 @@
//=============================================================================
#include "Shm_vars.h"
#include <iostream>
#include <sstream>

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;
}
Expand Down

0 comments on commit 63d0c69

Please sign in to comment.