示例#1
0
void Meal(void* args) {
    //Disable buttons/settings
    cButton.SetText("End Meal");
    cEditDelay.SetEnabled(0);
    cComboDate.SetEnabled(0);
    cComboRecord.SetEnabled(0);
    cComboSensitivity.SetEnabled(0);
    mScale.EditItem(ID_SCALE_ZERO, "&Zero", MF_DISABLED);

    //Get Variables
    char* tmpWait = new char[255];
    cEditDelay.GetText(tmpWait);
    iMealWait = atoi(tmpWait);
    if (iMealWait==0) iMealWait = 10;

    mCompare = cComboRecord.GetSelectedItem();
    mSensitivity = ((float)cComboSensitivity.GetSelectedItem()+1.0)/100.0;

    //Initialize the first weight
    AddCurrentValue();

    //Activate the meal
    bMealActive = true;

    while(bMealActive) {
        //So if the scale is not stable, set the current time to when the scale was last stable
        if (!scale->IsStable()) uLastStable = time(0);

        if (time(0) - uLastStable >= iMealWait) {
            if (scale!=NULL && scale->IsConnected()) {
                if (fabs(scale->GetWeight() - fLastWeight) >= mSensitivity) {
                    if ((mCompare == 0 || mCompare == 2) && scale->GetWeight() > fLastWeight) AddCurrentValue();
                    if ((mCompare == 1 || mCompare == 2) && scale->GetWeight() < fLastWeight) AddCurrentValue();
                }
            }
        }

        //Sleep for .1 second
        Sleep(100);
    }

    //Check and see if the person saved the file
    CheckAndSave();

    //Enable them
    cButton.SetText("New Meal");
    cEditDelay.SetEnabled(1);
    cComboDate.SetEnabled(1);
    cComboRecord.SetEnabled(1);
    cComboSensitivity.SetEnabled(1);
    mScale.EditItem(ID_SCALE_ZERO, "&Zero", 0);
}
示例#2
0
bool SaveMeal() {
    if (cSaveName==NULL || strlen(cSaveName)<=1) return 0;
    if (vMealItems.size() <=0) return 0;

    if (strstr(cSaveName,".csv") == NULL) strcat(cSaveName,".csv");

    //Open the file
    FILE* fSave = fopen(cSaveName, "w+");
    if (fSave == NULL) return 0;

    char tmp[313];
    strftime(tmp, 128, "%m/%d/%Y", vMealItems[0].getTime());

    if (fprintf(fSave, "MEAL START: %s,,\n", tmp) == 0) {
        fclose(fSave);
        return 0;
    }

    fprintf(fSave, "Time,Mass,Unit\n");

    std::vector<MealItem>::iterator mealIterator = vMealItems.begin();
    while(mealIterator != vMealItems.end()) {
        if (cComboDate.GetSelectedItem()==0) strftime(tmp, 128, "%I:%M:%S %p", mealIterator->getTime());
        else strftime(tmp, 128, "%H:%M:%S", mealIterator->getTime());
        fprintf(fSave, "%s,%.2f,%s\n", tmp, mealIterator->getValue(), mealIterator->getUnit());
    }

    strftime(tmp, 128, "%m/%d/%Y", vMealItems[vMealItems.size()-1].getTime());
    fprintf(fSave, "MEAL END: %s,,\n", tmp);

    fclose(fSave);

    sprintf(tmp, "MealTrack - %s", strrchr(cSaveName,'\\') + 1);
    cWindow.SetTitle(tmp);

    bSaved = 1;
    return(1);
}
示例#3
0
void AddCurrentValue() {
    //For temporary strings
    char tmp[128], tmp2[128];
    time_t rwtm;

    //Retrieve the current time
    time(&rwtm);

    //Get the current values from the scale and computer
    fLastWeight = scale->GetWeight();

    MealItem item = MealItem::create(fLastWeight, scale->GetUnit());
    vMealItems.push_back(item);

    //Convert time to string (12/24 hour format)
    if (cComboDate.GetSelectedItem()==0) strftime(tmp2, 128, "%I:%M:%S %p", item.getTime());
    else strftime(tmp2, 128, "%H:%M:%S", item.getTime());

    //Print to the textbox
    sprintf(tmp, "%s: %.2f %s", tmp2, item.getValue(), item.getUnit());

    cListBox.AddItem(tmp);
}