Exemple #1
0
//--------------------------------
// Cals
//--------------------------------
bool Sensor::isCalChannelValid(int _channel) {
	if (_channel >= 0 && _channel < getSensorCalCount()) {
		return true;
	}
	DEBUGPRINTLN(DebugLevel::ERROR, F("ERROR: isCalChannelValid() channel out of bounds"));
	return false;
}
Exemple #2
0
//--------------------------------
// Values
//--------------------------------
bool Sensor::isValueChannelValid(int _channel) {
	if (_channel >= 0 && _channel < SENSOR_VALUE_COUNT) { // FIXME getSensorValueCount()) {
		return true;
	}
	DEBUGPRINTLN(DebugLevel::ERROR, F("ERROR: isValueChannelValid() channel out of bounds"));
	return false;
}
void SPIClass::begin() {
	DEBUGPRINTLN("ASDFASDF");
	
	
	GPIO_PinModeSet(
    (GPIO_Port_TypeDef)dPorts[ pinSettings->mosiPin],
    dPins[ pinSettings->mosiPin],
    gpioModeWiredAndPullUpFilter,
   1);
   
   GPIO_PinModeSet(
    (GPIO_Port_TypeDef)dPorts[ pinSettings->misoPin],
    dPins[ pinSettings->misoPin],
    gpioModeInput,
   0);
   
   //This needs to be push pull or the CC3000 doesn't work!!!!!
	GPIO_PinModeSet(
    (GPIO_Port_TypeDef)dPorts[ pinSettings->clkPin],
    dPins[ pinSettings->clkPin],
    gpioModePushPull,
   1);

	/*//setup SPI Pins
	pinMode(
		  pinSettings->mosiPin,
		  gpioModeWiredAndPullUpFilter);
  digitalWrite(pinSettings->mosiPin, 1);
  pinMode(
		  pinSettings->misoPin,
		  gpioModeInput);
  //digitalWrite(pinSettings->misoPin, 0);
  
  pinMode(
		  35,
		  gpioModeInput);
  //digitalWrite(35, 0);

  pinMode(
		  34,
		  gpioModeInput);
  //digitalWrite(34, 0);
			
  
  
  pinMode(
		  pinSettings->clkPin,
		  gpioModeWiredAndPullUpFilter);
  digitalWrite(pinSettings->clkPin, 1);*/
		

	// NPCS control is left to the user
	CMU_ClockEnable(cmuClock_HFPER, true);
	CMU_ClockEnable(spi_clk, true);
	//CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFRCO);
 
	DEBUGPRINTLN("CONFIG");
	DEBUGPRINTLN(id);
	DEBUGPRINTLN(spi_clk);
	DEBUGPRINTLN(mode[0]);
	DEBUGPRINTLN(bitOrder[0] ? 1 : 0);
	DEBUGPRINTLN("ENDCONFIG");
	
	// Default speed set to 4Mhz
	//usartInit.msbf = true;//bitOrder[0];
	//usartInit.clockMode = usartClockMode0;
	//usartInit.baudrate = 1000000;//84000000 / divider[0];
	usartInit.refFreq = 14000000;
	
	  usartInit.baudrate     = 100000;
	  //usartInit.baudrate     = 1000000;
	  usartInit.databits     = usartDatabits8;
	  usartInit.msbf         = bitOrder[0] ? 1 : 0;
	  usartInit.master       = 1;
	  usartInit.clockMode    = mode[0];
	  usartInit.prsRxEnable  = 0;
	  usartInit.autoTx       = 0;
	
	
	USART_InitSync(spi, &usartInit);
	//USART_Enable(spi, usartEnable);
	
	  // Enable receiver and transmitter
	   /* Module USART2 is configured to location 1 */
	  spi->ROUTE = id;
	  /* Enable signals TX, RX, CLK */
	  spi->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_CLKPEN | USART_ROUTE_RXPEN;
	  //
	
	//spi->CLKDIV = 0x200;
			 
		
}
Exemple #4
0
bool Sensor::acquire(void) {
	unsigned long _now = millis();
	unsigned long _then = _now;
	unsigned long _dur = _now;
	unsigned long lasttime = 0;
	if (isSensorActive()) {
		switch (getNextSubTask()) {
			case 0:
				DEBUGPRINT(DebugLevel::TIMINGS, F("]->acquire_setup START"));
				if ((_now - last_acquiresetup_timestamp_ms) >= minimum_time_between_acquiresetup_ms) {
					lasttime = last_acquiresetup_timestamp_ms;
					last_acquiresetup_timestamp_ms = _now;
					acquire_setup();
					incNextSubtask();
					_then = millis();
					_dur = _then - _now;
					DEBUGPRINT(DebugLevel::TIMINGS, F("\t\tct="));
					DEBUGPRINT(DebugLevel::TIMINGS, (_now - lasttime));
					DEBUGPRINT(DebugLevel::TIMINGS, "/");
					DEBUGPRINTLN(DebugLevel::TIMINGS, minimum_time_between_acquiresetup_ms);
				}
				else {
					_then = millis();
					_dur = _then - _now;
					DEBUGPRINTLN(DebugLevel::TIMINGS, "\tdelayed");
				}
				DEBUGPRINT(DebugLevel::TIMINGS, String(_then) + " sensors[" + String(sensorID));
				DEBUGPRINT(DebugLevel::TIMINGS, F("]->acquire_setup DONE \t\t\tdur="));
				DEBUGPRINTLN(DebugLevel::TIMINGS, _dur);
				break;
			case 1:
				DEBUGPRINT(DebugLevel::TIMINGS, F("]->acquire1      START"));
				if ((_now - last_acquiresetup_timestamp_ms) >= minimum_wait_time_after_acquiresetup_ms) {
					lasttime = last_acquiresetup_timestamp_ms;
					last_acquire1_timestamp_ms = _now;
					acquire1();
					incNextSubtask();
					_then = millis();
					_dur = _then - _now;
					DEBUGPRINT(DebugLevel::TIMINGS, F("\t\tct="));
					DEBUGPRINT(DebugLevel::TIMINGS, (_now - lasttime));
					DEBUGPRINT(DebugLevel::TIMINGS, "/");
					DEBUGPRINTLN(DebugLevel::TIMINGS, minimum_wait_time_after_acquiresetup_ms);
				}
				else {
					_then = millis();
					_dur = _then - _now;
					DEBUGPRINTLN(DebugLevel::TIMINGS, "\tdelayed");
				}
				DEBUGPRINT(DebugLevel::TIMINGS, String(_then) + " sensors[" + String(sensorID));
				DEBUGPRINT(DebugLevel::TIMINGS, F("]->acquire1      DONE \t\t\tdur="));
				DEBUGPRINTLN(DebugLevel::TIMINGS, _dur);
				break;
			case 2:
				DEBUGPRINT(DebugLevel::TIMINGS, F("]->acquire2      START"));
				if ((_now - last_acquire1_timestamp_ms) >= minimum_wait_time_after_acquire1_ms) {
					lasttime = last_acquire1_timestamp_ms;
					last_acquire2_timestamp_ms = _now;
					acquire2();
					incNextSubtask();
					_then = millis();
					_dur = _then - _now;
					DEBUGPRINT(DebugLevel::TIMINGS, F("\t\tct="));
					DEBUGPRINT(DebugLevel::TIMINGS, (_now - lasttime));
					DEBUGPRINT(DebugLevel::TIMINGS, "/");
					DEBUGPRINTLN(DebugLevel::TIMINGS, minimum_wait_time_after_acquire1_ms);
				}
				else {
					_then = millis();
					_dur = _then - _now;
					DEBUGPRINTLN(DebugLevel::TIMINGS, "\tdelayed");
				}
				DEBUGPRINT(DebugLevel::TIMINGS, String(_then) + " sensors[" + String(sensorID));
				DEBUGPRINT(DebugLevel::TIMINGS, F("]->acquire2      DONE \t\t\tdur="));
				DEBUGPRINTLN(DebugLevel::TIMINGS, _dur);
				break;
			default:
				break;
		}
	}
	return true;
}