Summary Files Commits Branches @commit @diff @stats
path: root / src / LEDVideoWall.cpp
blob: 30972901cd4e8f05c4ce7fefc8df2a8e937de57e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "LEDVideoWall.h"
#include "cli.hpp"
#include <stdio.h>

LEDVideoWall::~LEDVideoWall() { }

LEDVideoWall* LEDVideoWall::Freeform(mm panel_width, mm panel_height, mm wall_max_width, mm wall_max_height) {
	return new LEDVideoWall(
		(wall_max_width / panel_width) * panel_width,
		(wall_max_height / panel_height) * panel_height);
}

LEDVideoWall* LEDVideoWall::Aspect(mm panel_width, mm panel_height, unsigned int aspect_width, unsigned int aspect_height) {
	return new LEDVideoWall(
			aspect_width * panel_width,
			aspect_height * panel_height);
}

LEDVideoWall::LEDVideoWall(mm width, mm height) : Screen(width, height) { }

enum class LEDVideoWallType {
	Freeform = 0, Aspect
};

LEDVideoWall* LEDVideoWall::fromCommandLine() {
	mm ipanel_width = 0, ipanel_height = 0;
	cli::scanTwoValues(
		"%dx%d",
		ipanel_width,
		ipanel_height,
		"Enter panel size (in the format 'WIDTHxHEIGHT'): ",
		"Invalid size, try again!");

	unsigned int itype = 2;
	cli::readUserInputMax(
		itype,
		(unsigned int)2,
		"Select an LED video wall type [0 for Freeform, 1 for Aspect]: ",
		"Invalid type, try again!");

	LEDVideoWallType type = static_cast<LEDVideoWallType>(itype);
	switch (type) {
		case LEDVideoWallType::Freeform: {
			mm iwall_max_width = 0, iwall_max_height = 0;
			cli::scanTwoValues(
				"%dx%d",
				ipanel_width,
				ipanel_height,
				"Enter singe wall size (in the format 'WIDTHxHEIGHT'): ",
				"Invalid size, try again!");

			return LEDVideoWall::Freeform(ipanel_width, ipanel_height, iwall_max_width, iwall_max_height);
		};

		case LEDVideoWallType::Aspect: {
			mm i_width = 0, i_height = 0;
			cli::scanTwoValues(
				"%d:%d",
				i_width,
				i_height,
				"Enter aspect ratio (in the format 'width:height'): ",
				"Invalid input, try again!");

			return LEDVideoWall::Aspect(ipanel_width, ipanel_height, i_width, i_height);
		};
	}
	throw std::logic_error("Implementation error: didn't handle all types of LED video walls!");
}