Exemplo n.º 1
0
void ToggleScaleMenu(bool scaleIsActive) {
    if (scaleIsActive) { //If scale is active
        mScale.EditItem(ID_SCALE_CONNECT, "&Disconnect");
        mScale.EditItem(ID_SCALE_ZERO, "&Zero", 0);
        cButton.SetEnabled(1);
    } else {
        mScale.EditItem(ID_SCALE_CONNECT, "&Connect");
        mScale.EditItem(ID_SCALE_ZERO, "&Zero", MF_DISABLED);
        cButton.SetEnabled(0);
    }
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
0
void HandleMenu(HWND hWnd, DWORD opt) {
    switch(opt) {
        case ID_SCALE_CONNECT:
            cEditBox.SetText("Trying to communicate with the scale...");
            mScale.EditItem(ID_SCALE_CONNECT, "&Connecting...", MF_DISABLED);
            _beginthread(ScaleConnect, 0, (void*) hWnd);
        break;

        case ID_FILE_NEW:
            if (!bSaved && vMealItems.size() > 0) {
                switch(MessageBox(hWnd, "You haven't saved the current meal, would you like to?","Hold Up!", MB_YESNOCANCEL | MB_ICONINFORMATION)) {
                    case IDYES:
                        if (CheckAndSave()==-1) break;
                    case IDNO:
                        cListBox.Clear();
                        vMealItems.clear();
                        strcpy(cSaveName, "");
                        cWindow.SetTitle("MealTrack - Untitled");
                        cButton.SetText("Start Meal");
                    break;

                    case IDCANCEL:
                    default:
                    break;
                }
            } else {
                cListBox.Clear();
                vMealItems.clear();
                strcpy(cSaveName, "");
                cWindow.SetTitle("MealTrack - Untitled");
                cButton.SetText("Start Meal");
            }
        break;

        case ID_FILE_SAVE:
            GetSaveFile(hWnd);
            if (vMealItems.size() >= 1) CheckAndSave();

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

        case ID_FILE_EXIT:
            PostMessage(hWnd, WM_CLOSE, 0, 0);
        break;

        case ID_SCALE_ZERO:
            if (scale != NULL) scale->Zero();
        break;
    }
}
Exemplo n.º 4
0
void ScaleConnect(void* args) {
    //If we aren't connected, connect!
    if (scale == NULL) {
        //Create a new scale and attempt to connect
        scale = new Scale("COM1");
        if (!scale->IsConnected()) {
            delete scale;
            scale = new Scale();
        }

        if (!scale->IsConnected()) {
            char err[256];
            sprintf(err, "Failed to connect! ERROR: %i", scale->GetError());

            mScale.EditItem(ID_SCALE_CONNECT, "&Connect");
            cEditBox.SetText(err);
            delete scale;
            scale = NULL;
            return;
        }

        //Begin the thread which sends a message to the Window's event and loops it
        hScaleThread = (HANDLE)_beginthread(GetScaleReading, 0, args);

        //Switch the menu to allow for disconnect & other features
        SendMessage((HWND)args, WM_SCALE_CONNECTED, 0, 0);
    } else {
        //Deactivate the meal
        bMealActive = 0;

        //Delete the scale which will disconnect it
        delete scale;
        scale = NULL;

        SendMessage((HWND)args, WM_SCALE_DISCONNECTED, 0, 0);
    }
}