~ruther/CTU-FEE-B0B35APO-Semestral-project

a94c4132d78f33b212f50f49ffd1c2383fe9b750 — František Boháček 3 years ago d003d49
feat: add main implementation
1 files changed, 54 insertions(+), 17 deletions(-)

M image-viewer/src/main.c
M image-viewer/src/main.c => image-viewer/src/main.c +54 -17
@@ 1,26 1,20 @@
/*******************************************************************
  Project main function template for MicroZed based MZ_APO board
  designed by Petr Porazil at PiKRON

  change_me.c      - main file

  include your name there and license for distribution.

  Remove next text: This line should not appear in submitted
  work and project name should be change to match real application.
  If this text is there I want 10 points subtracted from final
  evaluation.

  Image viewer (png, jpeg, ppm)
  made by František Boháček
 *******************************************************************/

#define _POSIX_C_SOURCE 200112L
#include "display_utils.h"
#include "image_viewer.h"

#include <png.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include <unistd.h>

#include "nonblocking_io.h"
#include "logger.h"
#include "mzapo_parlcd.h"
#include "mzapo_phys.h"
#include "mzapo_regs.h"


@@ 28,22 22,65 @@

int main(int argc, char *argv[])
{

  /* Serialize execution of applications */

  /* Try to acquire lock the first */
  if (serialize_lock(1) <= 0) {
    printf("System is occupied\n");

    if (1) {
      printf("Waitting\n");
      /* Wait till application holding lock releases it or exits */
      /* Wait till application holding lock releases IT or exits */
      serialize_lock(0);
    }
  }

  struct termios oldstdin;
  file_set_nonblocking(STDIN_FILENO, &oldstdin);

  logger_t logger = logger_create(LOG_DEBUG, stdout, stdout, stderr, stderr, NULL);

  if (argc < 2) {
    logger_error(&logger, __FILE__, __FUNCTION__, __LINE__, "Not enough arguments.");
  }

  logger_info(&logger, __FILE__, __FUNCTION__, __LINE__,
              "Image %s will be loaded.", argv[1]);

  display_data_t display_data = {
    .base_address = map_phys_address(PARLCD_REG_BASE_PHYS, PARLCD_REG_SIZE, 0),
  };

  void *reg_knobs_base =
      map_phys_address(SPILED_REG_BASE_PHYS, SPILED_REG_SIZE, 0) +
      SPILED_REG_KNOBS_8BIT_o;

  logger_debug(&logger, __FILE__, __FUNCTION__, __LINE__,
              "Initializing display...", argv[1]);
  display_t display = display_init(display_data);
  logger_debug(&logger, __FILE__, __FUNCTION__, __LINE__,
              "Display initialized...", argv[1]);

  logger_debug(&logger, __FILE__, __FUNCTION__, __LINE__,
              "Starting image viewer...", argv[1]);

  image_viewer_t viewer = image_viewer_create(argv[1], &display, &logger);

  image_viewer_display_image(&viewer);

  image_viewer_start_loop(&viewer, reg_knobs_base);

  logger_info(&logger, __FILE__, __FUNCTION__, __LINE__,
              "Cleaning up...", argv[1]);

  display_deinit(&display);
  image_viewer_destroy(&viewer);

  file_set_blocking(STDIN_FILENO, &oldstdin);

  /* Release the lock */
  serialize_unlock();

  logger_info(&logger, __FILE__, __FUNCTION__, __LINE__, "Application quit",
              argv[1]);

  return 0;
}

Do not follow this link