void ShowPrompt()

in BusTools/PwmTestTool/main.cpp [146:256]


void ShowPrompt (PwmController^ device)
{
    PwmPin^ pin;

    while (std::wcin) {
        std::wcout << L"> ";

        std::wstring line;
        if (!std::getline(std::wcin, line)) {
            return;
        }

        std::wistringstream linestream(line);
        std::wstring command;

        linestream >> command;
        if ((command == L"q") || (command == L"quit")) {
            return;
        } else if ((command == L"h") || (command == L"help")) {
            std::wcout << Help;
        } else if (command == L"open") {
            // open pin N
            unsigned int pinId;
            if (!(linestream >> std::dec >> pinId)) {
                std::wcout << L"Expecting integer. e.g: open 0\n";
                continue;
            }

            pin = device->OpenPin(pinId);
        }
        else if (command == L"freq") {
            // set controller frequency
            double freq;

            if (!(linestream >> freq)) {
                std::wcout << L"Expecting float.\n";
                continue;
            }

            device->SetDesiredFrequency(freq);
        }
        else if (command == L"start") {
            if (!pin) {
                std::wcout << L"No open pin\n";
                continue;
            }

            pin->Start();
        }
        else if (command == L"stop") {
            if (!pin) {
                std::wcout << L"No open pin\n";
                continue;
            }
            else if (!pin->IsStarted) {
                std::wcout << L"Pin not started\n";
                continue;
            } 

            pin->Stop();
        } 
        else if (command == L"dutycycle") {
            double duty;

            if (!(linestream >> duty)) {
                std::wcout << L"Expecting float.\n";
                continue;
            } else if (!pin) {
                std::wcout << L"No open pin\n";
                continue;
            } else if ((duty < 0.0) || (duty > 100.0)) {
                std::wcout << "Duty cycle must be between 0 and 100\n";
                continue;
            }

            pin->SetActiveDutyCyclePercentage(duty / 100.0);
        }
        else if (command == L"polarity") {
            if (!pin) {
                std::wcout << L"No open pin\n";
                continue;
            }

            if (pin->Polarity == PwmPulsePolarity::ActiveHigh) {
                pin->Polarity = PwmPulsePolarity::ActiveLow;
            }
            else {
                pin->Polarity = PwmPulsePolarity::ActiveHigh;
            }

            std::wcout << L"Polarity is now " << pin->Polarity << L"\n";
        }
        else if (command == L"info") {
            std::wcout << L" ActualFrequency: " << device->ActualFrequency << L"\n";
            std::wcout << L"    MaxFrequency: " << device->MaxFrequency << L"\n";
            std::wcout << L"    MinFrequency: " << device->MinFrequency << L"\n";
            std::wcout << L"        PinCount: " << device->PinCount << L"\n";

            if (pin) {
                std::wcout << L"                 IsStarted: " << pin->IsStarted << L"\n";
                std::wcout << L"                  Polarity: " << pin->Polarity << L"\n";
                std::wcout << L" ActiveDutyCyclePercentage: " << pin->GetActiveDutyCyclePercentage() * 100.0 << L"\n";
            }
        } else if (command.empty()) {
            // ignore
        } else {
            std::wcout << L"Unrecognized command: " << command <<
                L". Type 'help' for command usage.\n";
        }
    }
}