Skip to content

Initializing wiringMvs/wiringPi

November 11, 2018

Right now my code has a couple of explicit initialization paths in it (cases 6 and 7 below)

int wiringMVS(int function, int parameter){//implements wiringPi functions for MVS
	int result=0;

	switch (function){
		case 0:	//pinmode INPUT
			pinMode(parameter,INPUT);
			break;
		.
		.
		.
		case 6: // setup()
			result=wiringPiSetup ();
			if (result!=0)
 				printf("wiringMVS Setup() sez %d\n",result);
			break;
		case 7: // mcp3002Setup()
			result=mcp3002Setup (MY_PIN_BASE,SPI_CHAN);
			if (result<0)
 				printf("wiringMVS mcp3002Setup() sez %d\n",result);
			break;
		.
		.
		.
	}
	return result;
}

I would like to replace them with automatic initialization using static variables as below:

int wiringMVS(int function, int parameter){//implements wiringPi functions for MVS
	static int init=0;
	int result=0;
	if (!init){
		init=1;
		result=wiringPiSetup ();
		if (result!=0) printf("wiringMVS Setup() sez %d\n",result);
	}
	switch (function){
		case 0:	//pinmode INPUT
			pinMode(parameter,INPUT);
			break;
		.
		.
		.
		case 7: // mcp3002Setup()
			result=mcp3002Setup (MY_PIN_BASE,SPI_CHAN);
			if (result<0)
 				printf("wiringMVS mcp3002Setup() sez %d\n",result);
			break;
		.
		.
		.
	}
	return result;
}

UPDATE: I decided this wasn't a good idea and I kept the explicit initialization. I need to arrange for something to run when MVS starts to make the init cals.

Advertisements

From → Olduino/370

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: