void FramebufferFrameGrabber::setDevicePath(const QString& path)
{
	if(_fbDevice != path)
	{
		_fbDevice = path;
		int result;
		struct fb_var_screeninfo vinfo;

		// Check if the framebuffer device can be opened and display the current resolution
		_fbfd = open(QSTRING_CSTR(_fbDevice), O_RDONLY);
		if (_fbfd == 0)
		{
			Error(_log, "Error openning %s", QSTRING_CSTR(_fbDevice));
		}
		else
		{
			// get variable screen information
			result = ioctl (_fbfd, FBIOGET_VSCREENINFO, &vinfo);
			if (result != 0)
			{
				Error(_log, "Could not get screen information");
			}
			else
			{
				Info(_log, "Display opened with resolution: %dx%d@%dbit", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
			}
			close(_fbfd);
		}

	}
}
Example #2
0
int ProviderSpi::open()
{
	Debug(_log, "_baudRate_Hz %d,  _latchTime_ns %d", _baudRate_Hz, _latchTime_ms);
	Debug(_log, "_spiDataInvert %d,  _spiMode %d", _spiDataInvert, _spiMode);

	const int bitsPerWord = 8;

	_fid = ::open(QSTRING_CSTR(_deviceName), O_RDWR);

	if (_fid < 0)
	{
		Error( _log, "Failed to open device (%s). Error message: %s", QSTRING_CSTR(_deviceName),  strerror(errno) );
		return -1;
	}

	if (ioctl(_fid, SPI_IOC_WR_MODE, &_spiMode) == -1 || ioctl(_fid, SPI_IOC_RD_MODE, &_spiMode) == -1)
	{
		return -2;
	}

	if (ioctl(_fid, SPI_IOC_WR_BITS_PER_WORD, &bitsPerWord) == -1 || ioctl(_fid, SPI_IOC_RD_BITS_PER_WORD, &bitsPerWord) == -1)
	{
		return -4;
	}

	if (ioctl(_fid, SPI_IOC_WR_MAX_SPEED_HZ, &_baudRate_Hz) == -1 || ioctl(_fid, SPI_IOC_RD_MAX_SPEED_HZ, &_baudRate_Hz) == -1)
	{
		return -6;
	}

	return 0;
}
Example #3
0
	bool fileExists(const QString& path, Logger* log, bool ignError)
	{
		QFile file(path);
		if(!file.exists())
		{
			ErrorIf((!ignError), log,"File does not exist: %s",QSTRING_CSTR(path));
			return false;
		}
		return true;
	}
Example #4
0
	bool removeDir(const QString& path, Logger* log)
	{
		//QDir dir(path);
		if(!QDir(path).removeRecursively())
		{
			Error(log, "Failed to remove directory: %s", QSTRING_CSTR(path));
			return false;
		}
		return true;
	}
bool LedDeviceWS281x::init(const QJsonObject &deviceConfig)
{
	LedDevice::init(deviceConfig);

	QString whiteAlgorithm = deviceConfig["whiteAlgorithm"].toString("white_off");
	_whiteAlgorithm            = RGBW::stringToWhiteAlgorithm(whiteAlgorithm);
	Debug( _log, "whiteAlgorithm : %s", QSTRING_CSTR(whiteAlgorithm));
	Debug( _log, "rgbw : %d", deviceConfig["rgbw"].toBool(false) );
	if (_whiteAlgorithm == RGBW::INVALID)
	{
		Error(_log, "unknown whiteAlgorithm %s", QSTRING_CSTR(whiteAlgorithm));
		return false;
	}

	_channel           = deviceConfig["pwmchannel"].toInt(0);
	if (_channel != 0 && _channel != 1)
	{
		throw std::runtime_error("WS281x: invalid PWM channel; must be 0 or 1.");
	}

	_led_string.freq   = deviceConfig["freq"].toInt(800000ul);
	_led_string.dmanum = deviceConfig["dma"].toInt(5);
	_led_string.channel[_channel].gpionum    = deviceConfig["gpio"].toInt(18);
	_led_string.channel[_channel].count      = deviceConfig["leds"].toInt(256);
	_led_string.channel[_channel].invert     = deviceConfig["invert"].toInt(0);
	_led_string.channel[_channel].strip_type = (deviceConfig["rgbw"].toBool(false) ? SK6812_STRIP_GRBW : WS2811_STRIP_RGB);
	_led_string.channel[_channel].brightness = 255;

	_led_string.channel[!_channel].gpionum = 0;
	_led_string.channel[!_channel].invert = _led_string.channel[_channel].invert;
	_led_string.channel[!_channel].count = 0;
	_led_string.channel[!_channel].brightness = 0;
	_led_string.channel[!_channel].strip_type = WS2811_STRIP_RGB;

	Debug( _log, "ws281x strip type : %d", _led_string.channel[_channel].strip_type );

	if (ws2811_init(&_led_string) < 0)
	{
		throw std::runtime_error("Unable to initialize ws281x library.");
	}
	
	return true;
}
Example #6
0
	void resolveFileError(const QFile& file, Logger* log)
	{
		QFile::FileError error = file.error();
		const char* fn = QSTRING_CSTR(file.fileName());
		switch(error)
		{
			case QFileDevice::NoError:
				Debug(log,"No error occurred while procesing file: %s",fn);
				break;
			case QFileDevice::ReadError:
				Error(log,"Can't read file: %s",fn);
				break;
			case QFileDevice::WriteError:
				Error(log,"Can't write file: %s",fn);
				break;
			case QFileDevice::FatalError:
				Error(log,"Fatal error while processing file: %s",fn);
				break;
			case QFileDevice::ResourceError:
				Error(log,"Resource Error while processing file: %s",fn);
				break;
			case QFileDevice::OpenError:
				Error(log,"Can't open file: %s",fn);
				break;
			case QFileDevice::AbortError:
				Error(log,"Abort Error while processing file: %s",fn);
				break;
			case QFileDevice::TimeOutError:
				Error(log,"Timeout Error while processing file: %s",fn);
				break;
			case QFileDevice::UnspecifiedError:
				Error(log,"Unspecified Error while processing file: %s",fn);
				break;
			case QFileDevice::RemoveError:
				Error(log,"Failed to remove file: %s",fn);
				break;
			case QFileDevice::RenameError:
				Error(log,"Failed to rename file: %s",fn);
				break;
			case QFileDevice::PositionError:
				Error(log,"Position Error while processing file: %s",fn);
				break;
			case QFileDevice::ResizeError:
				Error(log,"Resize Error while processing file: %s",fn);
				break;
			case QFileDevice::PermissionsError:
				Error(log,"Permission Error at file: %s",fn);
				break;
			case QFileDevice::CopyError:
				Error(log,"Error during file copy of file: %s",fn);
				break;
			default:
				break;
		}
	}
LedDevice * LedDeviceFactory::construct(const QJsonObject & deviceConfig)
{
	Logger * log = Logger::getInstance("LEDDEVICE");
	QJsonDocument config(deviceConfig);
	QString ss(config.toJson(QJsonDocument::Indented));

	QString type = deviceConfig["type"].toString("UNSPECIFIED").toLower();

	const LedDeviceRegistry& devList = LedDeviceWrapper::getDeviceMap();
	LedDevice* device = nullptr;
	try
	{
		for ( auto dev: devList)
		{
			if (dev.first == type)
			{
				device = dev.second(deviceConfig);
				Info(log,"LedDevice '%s' configured.", QSTRING_CSTR(dev.first));
				break;
			}
		}

		if (device == nullptr)
		{
			Error(log, "Dummy device used, because configured device '%s' is unknown", QSTRING_CSTR(type) );
			throw std::runtime_error("unknown device");
		}
	}
	catch(std::exception& e)
	{

		Error(log, "Dummy device used, because configured device '%s' throws error '%s'", QSTRING_CSTR(type), e.what());
		const QJsonObject dummyDeviceConfig;
		device = LedDeviceFile::construct(QJsonObject());
	}

	return device;
}
int FramebufferFrameGrabber::grabFrame(Image<ColorRgb> & image)
{
	if (!_enabled) return 0;

	struct fb_var_screeninfo vinfo;
	unsigned capSize, bytesPerPixel;
	PixelFormat pixelFormat;

	/* Open the framebuffer device */
	_fbfd = open(QSTRING_CSTR(_fbDevice), O_RDONLY);

	/* get variable screen information */
	ioctl (_fbfd, FBIOGET_VSCREENINFO, &vinfo);

	bytesPerPixel = vinfo.bits_per_pixel / 8;
	capSize = vinfo.xres * vinfo.yres * bytesPerPixel;

	switch (vinfo.bits_per_pixel)
	{
		case 16: pixelFormat = PIXELFORMAT_BGR16; break;
		case 24: pixelFormat = PIXELFORMAT_BGR24; break;
#ifdef ENABLE_AMLOGIC
		case 32: pixelFormat = PIXELFORMAT_RGB32; break;
#else
		case 32: pixelFormat = PIXELFORMAT_BGR32; break;
#endif
		default:
			Error(_log, "Unknown pixel format: %d bits per pixel", vinfo.bits_per_pixel);
			close(_fbfd);
			return -1;
	}

	/* map the device to memory */
	_fbp = (unsigned char*)mmap(0, capSize, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, _fbfd, 0);

	_imageResampler.setHorizontalPixelDecimation(vinfo.xres/_width);
	_imageResampler.setVerticalPixelDecimation(vinfo.yres/_height);
	_imageResampler.processImage(_fbp,
								vinfo.xres,
								vinfo.yres,
								vinfo.xres * bytesPerPixel,
								pixelFormat,
								image);

	munmap(_fbp, capSize);
	close(_fbfd);

	return 0;
}
Example #9
0
QByteArray command_exec(QString cmd, QByteArray data)
{
	char buffer[128];
	QString result = "";

	std::shared_ptr<FILE> pipe(popen(cmd.toLocal8Bit().constData(), "r"), pclose);
	if (pipe)
	{
		while (!feof(pipe.get()))
		{
			if (fgets(buffer, 128, pipe.get()) != NULL)
				result += buffer;
		}
	}
	return QSTRING_CSTR(result);
}
Example #10
0
void PriorityMuxer::registerInput(const int priority, const hyperion::Components& component, const QString& origin, const QString& owner, unsigned smooth_cfg)
{
	// detect new registers
	bool newInput = false;
	if(!_activeInputs.contains(priority))
		newInput = true;

	InputInfo& input     = _activeInputs[priority];
	input.priority       = priority;
	input.timeoutTime_ms = newInput ? -100 : input.timeoutTime_ms;
	input.componentId    = component;
	input.origin         = origin;
	input.smooth_cfg     = smooth_cfg;
	input.owner          = owner;

	if(newInput)
	{
		Debug(_log,"Register new input '%s/%s' with priority %d as inactive", QSTRING_CSTR(origin), hyperion::componentToIdString(component), priority);
		emit priorityChanged(priority, true);
		emit prioritiesChanged();
		return;
	}
}
int LedDeviceMultiLightpack::open()
{
	// retrieve a list with Lightpack serials
	QStringList serialList = getLightpackSerials();

	// sort the list of Lightpacks based on the serial to get a fixed order
	std::sort(_lightpacks.begin(), _lightpacks.end(), compareLightpacks);

	// open each lightpack device
	foreach (auto serial , serialList)
	{
		LedDeviceLightpack * device = new LedDeviceLightpack(serial);	
		int error = device->open();

		if (error == 0)
		{
			_lightpacks.push_back(device);
		}
		else
		{
			Error(_log, "Error while creating Lightpack device with serial %s", QSTRING_CSTR(serial));
			delete device;
		}
	}
Example #12
0
void CgiHandler::cmd_cfg_set()
{
	_reply->addHeader ("Content-Type", "text/plain");
	if ( _args.at(0) == "cfg_set" )
	{
		QtHttpPostData data = _request->getPostData();
		QJsonParseError error;
		if (data.contains("cfg"))
		{
			QJsonDocument hyperionConfig = QJsonDocument::fromJson(QByteArray::fromPercentEncoding(data["cfg"]), &error);

			if (error.error == QJsonParseError::NoError)
			{
				QJsonObject hyperionConfigJsonObj = hyperionConfig.object();
				try
				{
					// make sure the resources are loaded (they may be left out after static linking)
					Q_INIT_RESOURCE(resource);

					QString schemaFile = ":/hyperion-schema";
					QJsonObject schemaJson;

					try
					{
						schemaJson = QJsonFactory::readSchema(schemaFile);
					}
					catch(const std::runtime_error& error)
					{
						throw std::runtime_error(error.what());
					}

					QJsonSchemaChecker schemaChecker;
					schemaChecker.setSchema(schemaJson);

					QPair<bool, bool> validate = schemaChecker.validate(hyperionConfigJsonObj);

					
					if (validate.first && validate.second)
					{
						QJsonFactory::writeJson(_hyperion->getConfigFileName(), hyperionConfigJsonObj);
					}
					else if (!validate.first && validate.second)
					{
						Warning(_log,"Errors have been found in the configuration file. Automatic correction is applied");
						
						QStringList schemaErrors = schemaChecker.getMessages();
						foreach (auto & schemaError, schemaErrors)
							Info(_log, schemaError.toUtf8().constData());

						hyperionConfigJsonObj = schemaChecker.getAutoCorrectedConfig(hyperionConfigJsonObj);

						if (!QJsonFactory::writeJson(_hyperion->getConfigFileName(), hyperionConfigJsonObj))
							throw std::runtime_error("ERROR: can not save configuration file, aborting ");
					}
					else //Error in Schema
					{
						QString errorMsg = "ERROR: Json validation failed: \n";
						QStringList schemaErrors = schemaChecker.getMessages();
						foreach (auto & schemaError, schemaErrors)
						{
							Error(_log, "config write validation: %s", QSTRING_CSTR(schemaError));
							errorMsg += schemaError + "\n";
						}

						throw std::runtime_error(errorMsg.toStdString());
					}