LCOV - code coverage report
Current view: top level - examples/gpio_sdl - main.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 28 0
Test Date: 2025-06-11 17:47:30 Functions: 0.0 % 1 0
Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : #include <pigpio.h>
       2                 :             : 
       3                 :             : #include <iostream>
       4                 :             : 
       5                 :             : #include "gpio_sdl.h"
       6                 :             : 
       7                 :             : constexpr uint8_t gpio_button = 17;
       8                 :             : 
       9                 :           0 : auto main() -> int {
      10                 :           0 :     if (!initGPIO()) {
      11                 :           0 :         return -1;
      12                 :             :     }
      13                 :           0 :     gpioSetMode(gpio_button, PI_INPUT);
      14                 :           0 :     gpioSetPullUpDown(gpio_button, PI_PUD_UP);
      15                 :             : 
      16                 :           0 :     SDL_Window* window = nullptr;
      17                 :           0 :     SDL_Renderer* renderer = nullptr;
      18                 :           0 :     if (!initSDL(window, renderer)) {
      19                 :           0 :         cleanupGPIO();
      20                 :           0 :         return -1;
      21                 :             :     }
      22                 :             : 
      23                 :           0 :     bool running = true;
      24                 :           0 :     while (running) {
      25                 :             :         SDL_Event event;
      26                 :           0 :         while (SDL_PollEvent(&event)) {
      27                 :           0 :             if (event.type == SDL_QUIT) {
      28                 :           0 :                 running = false;
      29                 :             :             }
      30                 :             :         }
      31                 :             : 
      32                 :           0 :         int button_state = readButtonState(gpio_button);
      33                 :             : 
      34                 :           0 :         SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
      35                 :           0 :         SDL_RenderClear(renderer);
      36                 :             : 
      37                 :           0 :         if (button_state == 0) {
      38                 :           0 :             SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
      39                 :             :         } else {
      40                 :           0 :             SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
      41                 :             :         }
      42                 :           0 :         SDL_Rect rect = {220, 140, 200, 200};
      43                 :           0 :         SDL_RenderFillRect(renderer, &rect);
      44                 :             : 
      45                 :           0 :         SDL_RenderPresent(renderer);
      46                 :             : 
      47                 :           0 :         SDL_Delay(16);
      48                 :             :     }
      49                 :             : 
      50                 :           0 :     cleanupSDL(window, renderer);
      51                 :           0 :     cleanupGPIO();
      52                 :           0 :     return 0;
      53                 :             : }
        

Generated by: LCOV version 2.0-1