Example #1
0
/**
 *	Converts ADC data to G force. The ADC value is multiplied by the
 *	reference voltage of the ADC, this is then divided by 2^ of the ADC size.
 * 	e.g. a 10bit ADC uses the value 2^10 = 1023.
 * 	The zero voltage is then taken from this value and the entire result is
 *	divided by the sensor's sensitivity.
 */
void Accelerometer::calculate() {
  //Serial.println("ACC calculating");
  readPins();
  xCalculated = (xAverage * refVolt / 1023.00 - zeroGVolt) / sensitivity;
  yCalculated = (yAverage * refVolt / 1023.00 - zeroGVolt) / sensitivity;
  zCalculated = (zAverage * refVolt / 1023.00 - zeroGVolt) / sensitivity;
}
Example #2
0
int
main(int argc, char **argv)
{
	static int      read, mask;
	int             pins;
	int             c;
	int             option_index = 0;
	char           *serial = NULL;
	static struct option long_options[] = {
		{"mask", required_argument, 0, 'm'},
		{"serial", required_argument, 0, 's'},
		{"read", no_argument, 0, 'r'},
		{"list", no_argument, 0, 'l'},
		{"help", no_argument, 0, 'h'},
		{0, 0, 0, 0}	/* This is a filler for -1 */
	};
	if (argc == 1) {
		helpMessage();
		return 1;
	}
	while ((c = getopt_long(argc, argv, "m:rhls:", long_options, &option_index)) != -1) {
		switch (c) {
		case 'l':
			listRelays();
			return 1;
			break;
		case 'r':
			read = 1;
			break;
		case 'm':
			mask = 1;
			pins = atoi(optarg);
			break;
		case 's':
			serial = optarg;
			break;
		case 'h':
			helpMessage();
			return 0;
			break;
		default:
			helpMessage();
			return 1;
			break;
		}
	}
	if (read || mask) {
		initBoard(serial);
	}
	if (mask) {
		setPins(pins);
	}
	if (read) {
		return readPins();
	}
	exit(0);
	return (0);
}
Example #3
0
void CGeneratorInput::readInputFile(const std::string& fileName, CPinPass::States& states)
{
	TiXmlDocument document;

	if(!base::loadXml(fileName, document))
	{
		base::lerr<<"Can't open input XML file \""<<fileName<<"\".";
		return;
	}

	TiXmlElement* root = document.FirstChildElement("EffectGeneratorParameters");

	if(!root)
	{
		base::lerr<<"Can't find root element in input XML file \""<<fileName<<"\".";
		return;
	}

	TiXmlElement* elem = root->FirstChildElement();

	while(elem != NULL)
	{
		std::string name = elem->Value();

		if(name == "constants")
			readConstants(elem);
		else
		if(name == "includes")
			readIncludes(elem);
		else
		if(name == "states")
			readStates(elem, states);
		else
		if(name == "pins")
			readPins(elem, states);
		else
		if(name == "inputs")
			readInputs(elem, states);
		else
			base::lwrn<<"Found element \""<<name<<"\" while parsing input file \""<<
						fileName<<"\". Nothing know about this type. Skipping...";

		elem = elem->NextSiblingElement();
	}
}