#include #include #include #include "DMM_HID.h" #include "common.h" using std::cout; using std::endl; using std::string; using std::vector; bool open_dmm(DMM_HID& dmm) { vector devs = DMM_HID::get_dmm_devices(); vector readings; if (0 == devs.size()) { cout << "DMM not found" << endl; return false; } if (devs.size() > 1) { cout << "Multiple DMMs found" << endl; cout << "Using: " << devs[0] << endl; } dmm.Open(devs[0]); // Wait a sec std::this_thread::sleep_for(std::chrono::seconds(1)); // DMM is open. Now check its config readings = dmm.get_readings(1); if (readings.empty()) { cout << "DMM communication is not ON - Press and hold USB/REL key" << endl; } return true; } int main(int argc, char **argv) { bool ok; bool quit = false; DMM_HID dmm; vector readings; Uint32 next_draw = 0; Uint32 ms; SDL_Window *window; SDL_Surface *surface; TTF_Font *font; string text; // Keep compiler happy (void)argc; (void)argv; ok = open_dmm(dmm); if (!ok) { return -1; } ok = init_sdl(&window); if (!ok) { return -1; } font = TTF_OpenFont("./font.ttf", FONT_SIZE); while (!quit) { ms = SDL_GetTicks(); if (next_draw - ms > 1000 / UI_FPS) { surface = SDL_GetWindowSurface(window); // Fill the surface white SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, 255, 255, 255)); // Get Readings readings = dmm.get_readings(); // Calculate Text calc_text(text, readings); // TODO: Draw Text draw_text(text, surface, font); next_draw = ms + 1000 / UI_FPS; // Update the window SDL_UpdateWindowSurface(window); quit = check_quit(); } } TTF_CloseFont(font); quit_sdl(window); return 0; }