Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C
I have this program and I need help with 2 issues
 
It needs a way to save the information for thr[acct] and timesave[acct]. I need a way to save the information so it can be used later. I know I am supposed to write another file for it to store and pull from but I do not know how to go about it.
 
It needs a way to read a square wave signal from a specified USB and it needs a way to send a output signal high or low to the USB. I have been looking around but I have not found a way to go about it.
 
Any help with this would be greatly appreciated.
 

 

#include <stdio.h>
#include <stdlib.h>

void accountselect();
 
    int timesave[20]={0};
    int thr[20]={0};
    int p; //“input from the heart rate monitor”
    int p1;
    int tvon; //“output from program to usb or other output”

void accountselect()
{
    int input=0;
     
    //system("clrscr");
    printf( "Enter your Account Number, 0 to quit: " );
    scanf( "%d", &input );
    switch ( input ) {
        case 1-19:            /* Note the colon, not a semicolon */
            workoutbegin(input);
            break;
        case 0:        
            printf( "Thanks for using exervision\n" );
            break;
        default:            
            printf( "Bad input, quitting!\n" );
            break;
    }
    getch();
}
 
void accountset()
{
    int age;                          /* Need a age... */
    char sex;
 
    // set account number
    //fscanf
    //fprintf
    //
    int acct=1;
      
    printf( "Please enter your age: ");  /* Asks for age */
    scanf( "%d", &age );                 /* The input is put in age */
    printf("please enter your gender (m/f): "); /*asks for sex */
 
    // this should be fixed some time to not read the return as the character
	sex=getch();
	sex=getch();
	
    if (sex=='f' ) {                  /* If the sex is f */
        thr[acct]=226-age;
    }
    else if (sex=='m') {            /* if the sex is m */ 
        thr[acct] = 220-age;
    }
    else {
        printf( "invalid entry\n" );     /* Executed if no other statement is */
        //break;
    }
    printf ("Your target heart rate is %d\n" ,thr[acct] ); /* Just to show you it works... */
    printf("Your account number is %d.  Please remember this number for future use.\n",acct);
    system("Pause");
    //return 0;
}
 
void account()
{
    int input;
     
    //system("clr");
    printf( "1. Run Exervision\n" );
    printf( "2. Create account\n" );
    printf( "3. quit\n" );
    printf( "Selection: " );
    scanf( "%d", &input );
    switch ( input ) {
        case 1:            /* uses account* to run*/
            accountselect();
            break;
        case 2:          
            accountset();
            break;
        case 3:        
            printf( "Thanks for using exervision\n" );
            break;
        default:            
            printf( "Bad input, quitting!\n" );
            break;
 }
    getchar();
 
}
 

int workoutbegin(int acct)
{
/*
	select accounts 
		account 1, 2, 3,q			
			int age
			int sex
			Printf select Run or Setup
			if Setup then printf enter age
			getchar=>age
			Printf select sex (m,f)
			getchar=>sex
			if sex=m then thr1=220-age
			else thr1=226-age
*/			
    printf("start working out\n");
    printf("work out if you wish to stop watching TV and save any time left press q");
 
    p1=p;
    //I need the program to wait 1 minute
    //time_t start,end;
    //start=clock();//predefined  function in c
    //after the user defined function does its work
    //end=clock();
    system("ping -n 60 127.0.0.1");
    //t=(end-start)/CLOCKS_PER_SEC;
    //or
    
    /*  //this section won't work without some sort of semaphore 
    scanf("%s",&selection);//q then return to main 
 
    if strcmp(selection,"q")
        break;
    */
 
    if (p >thr[acct])
    {
       tvon=1;
       timesave[acct]++;
       p1=p;
       printf("Congradulations in Target Heart Rate zone.  You earned 1 minute extra time that you can save or use at the end of your work out/n");
       workoutbegin(acct);
    }
    
    else if (p > p1)
    {
        tvon=1;
        printf("You may continue to watch tv, but you are not yet in your Target Heart Rate zone.\n");
        p1 =p;
        workoutbegin(acct);
    }
    
    else if (p0)
    {
        tvon=1;
        timesave[acct]--;
        p1 =p;
        printf("You are watching on borrowed time.  Time is being taken from your savings.\n");
        workoutbegin(acct);
    }
 
    else if (p
    {
        printf ("YOU'RE NOT WORKING OUT HARD ENOUGH.  WORK OUT HARDER OR THE TV WILL TURN OFF IN ONE MINUTE!\n");
    
        system("ping -n 60 127.0.0.1");
        
        if (p<p1)>
        printf ("Sorry workout was inefficient and you are out of saved time. No TV for you.\n");
        tvon=0;
        //account select
    }
}
 

int main(int argc, char *argv[])
{
    account();
    
    return 0;
    system("PAUSE");	
}
[EDIT]
Added tags for code formatting. Even in the unedited version some text at p and p1 conditions is wrong (probably destroyed when pasting).
[/EDIT]
Posted 19-Nov-12 15:53pm
Edited 19-Nov-12 21:08pm
(no name)54.2K
v2
Comments
Andy411 at 20-Nov-12 6:30am
   
If you do not know about writing files in C you shuold also ask google. My hints are fopen and fwrite
Do you have any kind of documentation about your USB device?
Chris Gilchrist at 20-Nov-12 13:46pm
   
It is not a device that I would be hooking it up to. I just need the program to connect to a usb on the computer the program is located on. I only need to receive a square wave signal and to send out a specified high or low.
Andy411 at 21-Nov-12 1:56am
   
Sorry, your reply is not clear for me. Is this software located in a micro controller on an usb device?
Chris Gilchrist at 21-Nov-12 15:42pm
   
I want the program to run on any computer. It would connect the program to a usb on the computer. I have cut the end off of a usb cord and there are 4 wires, one power one ground and two data transfers from what it looked like on the multimeter. I need to figure out how to control the two data transfer wires. I mean this has to have been done before right? I can find examples on how to write to a file but not to a usb drive. Even writing to a parrel drive port would work.
Andy411 at 22-Nov-12 2:04am
   
AFAIK You cannot access the usb data lines directly. This is only handled by the usb controller.
If you realy want to toggle some datalines the easiest way is IMO the RS232 port. You can use EscapeCommFunction http://msdn.microsoft.com/en-us/library/windows/desktop/aa363254%28v=vs.85%29.aspx to access RTS and CTS

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100