Exemplo n.º 1
0
void RelayBoard::setOn(uint8_t relay,uint8_t state)
{
    status1(1);
    if(verbose)
    {
        Serial.print(F("Setting relayboard "));
        Serial.print(getId());
        Serial.print(F(" relay "));
        Serial.print(relay);
        Serial.print(F(" to "));
        Serial.println(state);
    }
    _board->click(relay, state, 1);
    status1(0);
}
Exemplo n.º 2
0
void RelayBoard::delayedSetOn(uint8_t relay,uint8_t state, int seconds)
{
    status1(1);
    _board->click(relay, state, 1 + seconds * 13);
    status1(0);
}
Exemplo n.º 3
0
//=====================================
// main program...
//-------------------------------------
int main(int argc,char*argv[]) {
	//=====================================
	// init variables...
	//-------------------------------------
	bool uniFont    = false;
	bool noBorder   = false;
	bool fastSetup  = false;
	bool withDialog = false;
	bool yastMode   = false;
	bool useHwData  = false;
	bool fullScreen = false;
	bool setInfo    = false;
	bool set3D      = false;
	bool setXIdle   = false;
	bool checkPacs  = false;
	for (int n=0;n<argc;n++) {
	if (strcmp(argv[n],"-style") == 0) {
		globalStyle = (char*) malloc (sizeof(char) * 128);
		sprintf(globalStyle,"%s",argv[n+1]);
		break;
	}
	}

	//=====================================
	// check for root priviliges...
	//-------------------------------------
	if (! accessAllowed()) {
		fprintf (stderr,"xapi: only root can do this\n");
		usage();
	}

	//=====================================
	// start logging...
	//-------------------------------------
	logInit();

	//=====================================
	// allocate main qt object...
	//-------------------------------------
	for (int i=0;i<argc;i++) {
	QString item (argv[i]);
	if ((item == "-h") || (item == "--help")) {
		logExit(); usage(); exit(0);
	}
	}
	QApplication app(argc,argv);

	//=====================================
	// get additional options...
	//-------------------------------------
	QString* idlePID     = NULL;
	QString* cardName3D  = NULL;
	QString* popUpDialog = NULL;
	QString* cardDriver  = NULL;
	while (1) {
	int option_index = 0;
	static struct option long_options[] =
	{
		{"usehwdata"  , 0 , 0 , 'u'},
		{"fullscreen" , 0 , 0 , 'l'},
		{"info"       , 0 , 0 , 'i'},
		{"yast"       , 0 , 0 , 'y'},
		{"checkpacs"  , 0 , 0 , 'c'},
		{"noborder"   , 0 , 0 , 'n'},
		{"3d"         , 1 , 0 , 'D'},
		{"driver"     , 1 , 0 , 'd'},
		{"frameWidth" , 1 , 0 , 'w'},
		{"dialog"     , 1 , 0 , 'O'},
		{"unifont"    , 0 , 0 , 'U'},
		{"xidle"      , 0 , 0 , 'x'},
		{"pid"        , 1 , 0 , 'p'},
		{"fast"       , 0 , 0 , 'f'},
		{"help"       , 0 , 0 , 'h'},
		{0            , 0 , 0 , 0  }
	};
	int c = getopt_long (
		argc, argv, "uicD:fhxlw:d:yp:nUO:",long_options, &option_index
	);
	if (c == -1)
	break;

	switch (c) {
	case 0:
		fprintf (stderr,"xapi: option %s", long_options[option_index].name);
		if (optarg)
		fprintf (stderr," with arg %s", optarg);
		fprintf (stderr,"\n");
	break;

	case 'f':
		fastSetup  = true;
	break;

	case 'U':
		uniFont  = true;
	break;

	case 'O':
		withDialog  = true;
		popUpDialog = new QString (optarg);
	break;

	case 'n':
		noBorder = true;
	break;

	case 'y':
		yastMode = true;
	break;

	case 'w':
		globalFrameWidth = atoi (optarg);
	break;

	case 'u':
		useHwData  = true;
	break;

	case 'l':
		fullScreen = true;
	break;

	case 'i':
		setInfo    = true;
	break;

	case 'c':
		checkPacs  = true;
	break;

	case 'D':
		set3D      = true;
		cardName3D = new QString (optarg);
	break;

	case 'p':
		idlePID    = new QString (optarg);
	break;

	case 'd':
		cardDriver = new QString (optarg);
	break;

	case 'x':
		setXIdle   = true;
	break;

	case 'h':
		logExit(); usage();
	break;
	default:
		logExit(); exit(1);
	}
	}

	//=====================================
	// check if xapi should act as xidle
    //-------------------------------------
	if (setXIdle) {
		XTimeElapsed* idleTimer = new XTimeElapsed ( idlePID );
		app.setMainWidget (idleTimer);
		idleTimer->show();
		return app.exec();
	}

	//=====================================
	// check md5 sum of current config
	//-------------------------------------
	if ((! setInfo) && (! set3D) && (! checkPacs) &&
		(! useHwData) && (! fastSetup)
	) {
	bool createMD5sum = false;
	QFileInfo xc (MD5CONFIG);
	if (xc.exists()) {
		QString mD5Sum = qx(MD5,STDOUT,1,"%s",XCONFIG);
		QFile mHandle (MD5CONFIG); 
		if (mHandle.open(IO_ReadOnly)) {
		QString compare;
		mHandle.readLine(compare,MAX_LINE_LENGTH);
		mHandle.close();
		compare = compare.stripWhiteSpace();
		if (compare == mD5Sum) {
			fastSetup = true;
		} else {
			fastSetup = false;
		}
		} 
	} else {
		fastSetup = false;
	}
	if (createMD5sum) {
		QString mD5Sum = qx(MD5,STDOUT,1,"%s",XCONFIG);
		QFile mHandle (MD5CONFIG);
		if (mHandle.open(IO_WriteOnly)) {
			mHandle.writeBlock (mD5Sum.ascii(),mD5Sum.length());
			mHandle.close();
		}
	}
	} 

	//=====================================
	// check option combinations...
	//-------------------------------------
	if (useHwData == true) {
		fastSetup = false;
	}

	//=====================================
	// set root window cursor to the watch
	//-------------------------------------
	setMouseCursor ("watch");

	//=====================================
	// init program...
	//-------------------------------------
	QWidget::WFlags wflags = Qt::WType_TopLevel;
	if (noBorder) {
		wflags |= Qt::WStyle_Customize | Qt::WStyle_NoBorder;
	}
	if (uniFont) {
		QFont currentFont = QFont( "Helvetica", 12 );
		currentFont.setStyleHint( QFont::SansSerif, QFont::PreferBitmap );
		currentFont.setRawName (UNIFONT);
		qApp->setFont (currentFont);
	}
	xapi = new XFrame (
		globalFrameWidth, wflags
	);
	if (setInfo) {
		signal (SIGHUP ,gotKill);
		signal (SIGKILL,gotKill);
		signal (SIGABRT,gotKill);
		signal (SIGTERM,gotKill);
		XInfo infoBox (xapi);
		infoBox.showIntroBox();
		logExit();
		setMouseCursor ();
		exit (
			infoBox.returnCode()
		);
	}
	if (set3D) {
		XInfo infoBox (xapi);
		infoBox.show3DBox (*cardName3D,cardDriver);
		printf("%d\n",infoBox.returnCode());
		logExit();
		setMouseCursor ();
		exit (
			infoBox.returnCode()
		);
	}
	if (fastSetup) {
		xapi->fastSetup  = true;
	}
	if (useHwData) {
		xapi->useHwData  = true;
	}
	if (fullScreen) {
		xapi->fullScreen = true;
	}
	if (yastMode) {
		xapi->yastMode   = true;
	}

	//=====================================
	// check 3D environment
	//-------------------------------------
	XStringList packageInfo ( qx (GET3D,STDOUT) );
	packageInfo.setSeperator (":");
	QString package = packageInfo.getList().at(0);
	QString real3d  = packageInfo.getList().at(1);
	QString soft3d  = packageInfo.getList().at(2);
	QString general = packageInfo.getList().at(3);
	QString active  = packageInfo.getList().at(4);
	QString answer  = packageInfo.getList().at(5);
	QString flag    = packageInfo.getList().at(6);
	global3DActive  = active.toInt();
	QString status1 ("1");
	if (checkPacs) {
		// ...
		// if the 3D Answer was no, there is no need
		// to check for any packages or scripts
		// ---
		if (answer == "no") {
			setMouseCursor (); exit (0);
		}
		// ...
		// install the missing packages using YaST2
		// sw_single mode
		// ---
		if (package != "<none>") {
		if (setMessage("InstallPackage",xapi)) {
		status1 = qx (
			GETINSTALLED,STDOUT,1,"%s",package.ascii()
		);
		}
		}
		setMouseCursor ();
		exit (0);
	}

	//=====================================
	// remove lilo code file...
	//-------------------------------------
	unlink (LILOCODE);

	//=====================================
	// init main frame...
	//-------------------------------------
	if (! xapi->frameInitialized()) {
		xapi->setFrame ();
	}

	//=====================================
	// set signal handler...
	//-------------------------------------
	signal (SIGUSR2,SIG_IGN);
	signal (SIGINT ,gotInterrupted);

	//=====================================
	// init dialogs...
	//-------------------------------------
	XIntro*			intro    = new XIntro();
	XAccessX*		xaccess  = new XAccessX();
	XMouse*			mouse    = new XMouse();
	XCard*			card     = new XCard();
	XDesktop*		desktop  = new XDesktop();
	XDisplayGeometry*	geo  = new XDisplayGeometry();
	XKeyboard*		keyboard = new XKeyboard();
	XLayout*		layout   = new XLayout();
	XMonitor*		monitor  = new XMonitor();
	XMultihead*		multi    = new XMultihead();
	XTablet*		tablet   = new XTablet();
	XTouchScreen*	toucher  = new XTouchScreen();
	XOpenGL*        opengl   = new XOpenGL();
	XVirtual*       virtuals = new XVirtual();
	Xvnc*           vnc      = new Xvnc();

	intro     -> addTo (xapi);
	xaccess   -> addTo (xapi,intro);
	mouse     -> addTo (xapi,intro);
	card      -> addTo (xapi,intro);
	desktop   -> addTo (xapi,intro);
	geo       -> addTo (xapi,intro);
	keyboard  -> addTo (xapi,intro);
	layout    -> addTo (xapi,intro);
	monitor   -> addTo (xapi,intro);
	multi     -> addTo (xapi,intro);
	tablet    -> addTo (xapi,intro);
	toucher   -> addTo (xapi,intro);
	opengl    -> addTo (xapi,intro);
	virtuals  -> addTo (xapi,intro);
	vnc       -> addTo (xapi,intro);

	//=====================================
	// save intro pointer...
	//-------------------------------------
	introPointer = intro;

	//=====================================
	// make sure the serverlayout structure
	// is created at least one time
	//-------------------------------------
	XLayout* layoutDialog;
	layoutDialog = (XLayout*) intro -> retrieve (Layout);
	layoutDialog -> setupLayout();

	//=====================================
	// make sure the card dialog was build
	// in init stage
	//-------------------------------------
	XCard* cardDialog;
	cardDialog = (XCard*) intro -> retrieve (Card);
	cardDialog -> showSetupWindow (false);
	cardDialog -> slotRun (Card);
	cardDialog -> showSetupWindow (true);

	//=====================================
	// call resetPage of the desktop dialog
	// to check for framebuffer usage
	//-------------------------------------
	XDesktop* desktopDialog;
	desktopDialog = (XDesktop*) intro -> retrieve (Colors);
	desktopDialog -> resetPage ( PAGE_RELOAD );

	//=====================================
	// add margin around pushbutton texts 
	// this is only needed for QT3 
	//------------------------------------- 
	#if 1
	QObject* obj;
	QObjectList* l = xapi->queryList( "QPushButton" );
	QObjectListIt it( *l );
	QDict<char>* mText = xapi->getTextPointer();
	while ( (obj=it.current()) != 0 ) {
	++it;
	QPushButton* btn = (QPushButton*) obj;
	QString text = btn->text();
	if (! text.isNull()) {
		QDictIterator<char> n (*mText);
		for (; n.current(); ++n) {
		if (n.current() == text) {
			QString* newText = new QString();
			QTextOStream (newText) << "  " << text << "  ";
			mText->replace (n.currentKey(),*newText);
			break;
		}
		}
		QString addText;
		QTextOStream (&addText) << "  " << text << "  ";
		btn->setText (addText);
	}
	}
	delete l;
	// ...
	// special keys which are used dynamically on widgets
	// with initially other texts
	// ---
	QList<char> keyList;
	keyList.append ( "finish" );
	keyList.append ( "Next" );
	QListIterator<char> io ( keyList );
	for (; io.current(); ++io) {
		QString key ( io.current() );
		QString curText (mText->operator[](key));
		QString* newText = new QString();
		QTextOStream (newText) << "  " << curText << "  ";
		mText->replace (key,*newText);
	}
	#endif

	//=====================================
	// remove xfine cache directory...
	//-------------------------------------
	removeXFineCache();

	//=====================================
    // go to main event loop...
    //-------------------------------------
	app.setMainWidget(xapi);
	xapi -> show();
	xapi -> enterEvent ( 0 );
	xapi -> activateFirstItem();
	setMouseCursor();
	if (! withDialog) {
		intro -> checkDetected();
	} else {
		if ( *popUpDialog == "Monitor" ) {
			xapi -> runDialog (Monitor);
		} else
		if ( *popUpDialog == "Card") {
			xapi -> runDialog (Card);
		} else {
			fprintf (stderr,"xapi: no such dialog: %s\n",popUpDialog->ascii());
			exit (1);
		}
	}
	return app.exec();
}