Ejemplo n.º 1
0
void DispStatRegs(){
  //todo remove after debugging is complete
  uint8_t inByte1,inByte2;
  FlashSSLow();
  SPI.transfer(READ_STATUS_REG);
  inByte1 = SPI.transfer(0);
  inByte2 = SPI.transfer(0);
  FlashSSHigh(); 
  Serial<<"SB1: "<<_HEX(inByte1)<<"\r\nSB2: "<<_HEX(inByte2)<<"\r\n";
}
Ejemplo n.º 2
0
void loop() {
  serial_default_t<bps,CPU::frequency,TX_PIN,NO_PIN> Serial;

    bits = bit_indx = 0; // reset and try again

    Serial << endl
           << "Press a single 'U' to test the factory calibrated DCO value for " << CPU::frequency << " Hz" << endl
           << "(press reset and try multiple times)" << endl;

    // sleep until user presses the 'U' keyboard key
    LPM0;

    // display results
    uint16_t i, mask=0x01;
    uint32_t avg=0;

    Serial << "bit val ts  duration" << endl;
    for (i = 0; i < bit_indx; i++) {
      Serial << "[" << i << "] = " <<  (bits & mask ? "1 " : "0 ") << cnts[i];
      mask <<= 1;
      if ( i > 0 ) {
        unsigned bdur = cnts[i]-cnts[i-1];
        Serial << " " << bdur;
        avg += bdur;
      }
      if ( i == 0 ) Serial << " (start bit)";
      if ( i == 9 ) Serial << " (stop bit)";
      Serial << endl;
    }

    // compute tweaks to the DCO to make it more accurate
    // you will probably run this multiple times to get it right

    avg = (((avg+5)*10)/(howmany-1))/10;

    Serial << endl
           << "ideal bit duration is: " << bit_duration << endl;
    Serial << " your bit duration is: " << avg << " which is " << (uint32_t)avg*bps << " Hz" << endl
           << endl;

    if ( avg == bit_duration ) {
      Serial << "Your DCO is just right!" << endl;
    }
    else if ( avg < bit_duration ) {
        Serial << "Your DCO is too cold, add this line to your setup():\n" << endl
               << "  DCOCTL=0x" << _HEX(DCOCTL+1) << "; // slightly faster" << endl;
    }
    else { /* avg > bit_duration */
        Serial << "Your DCO is too hot, add this line to your setup():\n" << endl
               << "  DCOCTL=0x" << _HEX(DCOCTL-1) << "; // slightly slower" << endl;
    }
    Serial << "  // BCSCTL1=0x" << _HEX(BCSCTL1) << "; // your current BCSCTL1 setting" << endl;
    Serial << "  // DCOCTL=0x" << _HEX(DCOCTL) << "; // your current DCOCTL setting" << endl;
}
Ejemplo n.º 3
0
//----------------------------------------------------------------------------
// DeviceSearch
//----------------------------------------------------------------------------
CTempDS18B20::EnumResult CTempDS18B20::DeviceSearch (OneWire* i_poOneWire,
                                                     byte     o_aabyDevAddr[][8],
                                                     byte&    o_byDeviceCount)
{
  if (!i_poOneWire) return EnumResult::Error_ValueInvalid;

  byte byDevice = 0;
  bool bFound   = false;
  do
  {
    bFound = i_poOneWire->search (o_aabyDevAddr[byDevice]);
    if (bFound)
    {
      #ifdef DEBUG_CTempDS18B20
      Serial << F("DS18B20 #") << (byDevice+1) << F(", address");
      for (int ixCnt = 0; ixCnt < 8; ixCnt++)
        Serial << " " << (o_aabyDevAddr[byDevice][ixCnt] > 0xF ? "" : "0") << _HEX(o_aabyDevAddr[byDevice][ixCnt]);
      Serial << endl;
      #endif
      byte byCRC = OneWire::crc8 (o_aabyDevAddr[byDevice], 7);
      if (byCRC != o_aabyDevAddr[byDevice][7]) return EnumResult::Error_WrongCRC;
      byDevice++;
    }
  }
  while (bFound);
  o_byDeviceCount = byDevice;

  return EnumResult::SUCCESS;
}
Ejemplo n.º 4
0
/**
 * @brief it's only for information purpose if channel config was changed (List0/1 or List3/4)
 */
void cmMyBlind::configCngEvent(void) {
	#ifdef CM_BLIND_DBG
		dbg << F("Channel config changed, lst1: ") << _HEX(((uint8_t*)&lstCnl), sizeof(s_lstCnl)) << '\n';
	#endif

	modReferenceTimeTopBottom = (uint32_t)GET_2_BYTE_VALUE(lstCnl.REFERENCE_RUNNING_TIME_TOP_BOTTOM) * 100;
	modReferenceTimeBottomTop = (uint32_t)GET_2_BYTE_VALUE(lstCnl.REFERENCE_RUNNING_TIME_BOTTOM_TOP) * 100;

	#ifdef CM_BLIND_DBG
		dbg << F("modReferenceTimeTopBottom: ") << modReferenceTimeTopBottom << '\n';
		dbg << F("modReferenceTimeBottomTop: ") << modReferenceTimeBottomTop << '\n';
	#endif

	msgDelay = lstCnl.STATUSINFO_MINDELAY * 500;									// get message delay

	if (lstCnl.STATUSINFO_RANDOM) {
		// maybe we outsource this call to external module
		hm->initPseudoRandomNumberGenerator();
		msgDelay += (rand()%(uint16_t)(lstCnl.STATUSINFO_RANDOM * 1000));
	}

	if (!msgDelay) {
		msgDelay = 2000;
	}
}
Ejemplo n.º 5
0
/**
 * @brief We received a message from master to set a new value.
 *        SET_LOCK  (Type 0x11, Subtype: 0x01)
 *        LEVEL_SET (Type 0x11, Subtype: 0x02)
 *        STOP      (Type 0x11, Subtype: 0x03)
 *
 *        Typical you will find three bytes in data:
 *           1st byte = value;
 *           2nd and 3rd byte = ramp time;
 *           4th and 5th byte = on duration time;
 *
 *        after setting the new value we have to send an enhanced ACK:
 *           <- 0E E7 80 02 1F B7 4A 63 19 63 01 01 C8 00 54
 */
void cmMyBlind::pairSetEvent(uint8_t *data, uint8_t len) {
	#ifdef CM_BLIND_DBG
		dbg << F("PSE, value:") << _HEXB(data[0]);
		if (len > 1) { dbg << F(", modRampTime: ") << _HEX((data+1), 2); };
		if (len > 3) { dbg << F(", modDurationTime: ") << _HEX((data+3), 2); };
		dbg << '\n';
	#endif

	trigger11(
		((len > 0) ? data[0] : 255),											// send 255 if stop was sent
		((len > 1) ? data+1 : NULL),											// sent modRampTime if len > 1
		((len > 3) ? data+3 : NULL)												// sent modDurationTime if len > 3
	);

	// we don't need this. ack_status was sent implicit
	// stateToSend = AS_CM_STATETOSEND_ACK;										// ACK should be send
	// msgTmr.set(100);															// give some time
}
Ejemplo n.º 6
0
void setup()
{
  Serial.begin(9600);
  int lettera = 'A';
  int month = 4, day = 17, year = 2009;
  
  Serial << "This is an example of the new streaming" << endl;
  Serial << "library.  This allows you to print variables" << endl;
  Serial << "and strings without having to type line after" << endl;
  Serial << "line of Serial.print() calls.  Examples: " << endl;
  
  Serial << "A is " << lettera << "." << endl;
  Serial << "The current date is " << day << "-" << month << "-" << year << "." << endl;
  
  Serial << "You can use modifiers too, for example:" << endl;
  Serial << _BYTE(lettera) << " is " << _HEX(lettera) << " in hex. " << endl;
}
Ejemplo n.º 7
0
//----------------------------------------------------------------------------
// constructor
//----------------------------------------------------------------------------
CTempDS18B20::CTempDS18B20 (OneWire*    i_poOneWire,
                            byte        i_abyDevAddr[8],
                            EnumResult& o_enResult)
{
  if (!i_poOneWire)
  { o_enResult = EnumResult::Error_ValueInvalid; return;}

  m_poOneWire = i_poOneWire;
  memcpy (m_abyDeviceAddress, i_abyDevAddr, sizeof(m_abyDeviceAddress));
#ifdef DEBUG_CTempDS18B20
  Serial << F("create device ");
  for (int ixCnt = 0; ixCnt < 8; ixCnt++)
    Serial << " " << (m_abyDeviceAddress[ixCnt] > 0xF ? "" : "0") << _HEX(m_abyDeviceAddress[ixCnt]);
  Serial << endl;
#endif

  o_enResult = EnumResult::SUCCESS;
}
Ejemplo n.º 8
0
/**
 * @brief We received a peer event.
 *       In type you will find the type of peer event.
 *          0x3E = switch
 *          0x40 = remote
 *          0x41 = sensor
 *
 *       Appropriate answer is an ACK
 */
void cmMyBlind::peerMsgEvent(uint8_t type, uint8_t *data, uint8_t len) {
	#ifdef CM_BLIND_DBG
		dbg << F("peer message type: ")  << _HEXB(type) << F(", data: ")  << _HEX(data, len) << '\n';
	#endif
	
	if ( (type == 0x40) || (type == 0x41) ) {
		if (type == 0x40) {
			trigger40( ((data[0] & 0x40) ? 1 : 0), data[1]);							// filter out the long message bit

		} else if (type == 0x41) {
			trigger41( (data[0] & 0x7F), data[1], data[2]);
		}

		stateToSend = AS_CM_STATETOSEND_ACK;										// ACK should be send
		//msgTmr.set(100);															// immediately

	} else {
		hm->sendACK();
	}
}
Ejemplo n.º 9
0
void	RV::poll(void) {
	static uint8_t last_rCnt;

	if (this->bufLen > 10) {																// create search string for peer
		memcpy(this->peerId, this->mBdy.reID, 3);
		this->peerId[3] = (this->buf[10] & 0x3f);											// mask out long and battery low
	}
	
	uint8_t bIntend = pHM->ee.getIntend(this->mBdy.reID,this->mBdy.toID, this->peerId);		// get the intend of the message

	// some debugs
	#ifdef RV_DBG																			// only if AS debug is set
		dbg << (char)bIntend << F("> ") << _HEX(this->buf, this->bufLen) << ' ' << _TIME << '\n';
	#endif
	
	#ifdef RV_DBG_EX																		// only if extended AS debug is set
		pHM->explainMessage(this->buf);
	#endif
	
	// filter out unknown or not for us
	if ((bIntend == 'l') || (bIntend == 'u')) {												// not for us, or sender unknown
		this->mBdy.mLen = 0;																// clear receive buffer
		return;
	}

	// filter out repeated messages
	if ((this->mBdy.mFlg.RPTED) && (last_rCnt == this->mBdy.mLen)) {						// check if message was already received
		#ifdef RV_DBG																		// only if AS debug is set
			dbg << F("  repeated message\n");
		#endif

		this->mBdy.mLen = 0;																// clear receive buffer
		return;																				// wait for next message
	}
	last_rCnt = this->mBdy.mLen;

	pHM->recvMessage();

	this->mBdy.mLen = 0;
}
Ejemplo n.º 10
0
void SN::poll(void) {
	#define maxRetries    3
	#define maxTime       300
	
	// set right amount of retries
	if (!this->maxRetr) {																	// first time run, check message type and set retries
		if (reqACK) this->maxRetr = maxRetries;												// if BIDI is set, we have three retries
		else this->maxRetr = 1;
	}
	
	//dbg << "x:" << this->retrCnt << " y:" << this->maxRetr << " t:" << sndTmr.done() << '\n';
	
	// send something while timer is not busy with waiting for an answer and max tries are not done 
	if ((this->retrCnt < this->maxRetr) && (sndTmr.done() )) {								// not all sends done and timing is OK

		// some sanity
		this->mBdy.mFlg.RPTEN = 1;															// every message need this flag
		//if (pHM->cFlag.active) this->mBdy.mFlg.CFG = pHM->cFlag.active;						// set the respective flag while we are in config mode
		this->timeOut = 0;																	// not timed out because just started
		this->lastMsgCnt = this->mBdy.mCnt;													// copy the message count to identify the ACK
		this->retrCnt++;																	// increase counter while send out

		// check if we should send an internal message
		if (compArray(this->mBdy.toID, HMID, 3)) {											// message is addressed to us
			memcpy(pHM->rv.buf, this->buf, sndLen);											// copy send buffer to received buffer
			this->retrCnt = 0xff;															// ACK not required, because internal
						
			#ifdef SN_DBG																	// only if AS debug is set
			dbg << F("<i ");
			#endif

		} else {																			// send it external
			uint8_t tBurst = this->mBdy.mFlg.BURST;											// get burst flag, while string will get encoded
			pHM->encode(this->buf);															// encode the string
			disableGDO0Int();
			pHM->cc.sndData(this->buf,tBurst);												// send to communication module
			enableGDO0Int();
			pHM->decode(this->buf);															// decode the string, so it is readable next time
			
			if (reqACK) sndTmr.set(maxTime);												// set the time out for the message
			
			#ifdef SN_DBG																	// only if AS debug is set
			dbg << F("<- ");
			#endif

		}
		
		if (!pHM->ld.active) pHM->ld.set(send);												// fire the status led
		
		#ifdef SN_DBG																		// only if AS debug is set
		dbg << _HEX(this->buf,sndLen) << ' ' << _TIME << '\n';
		#endif

	} else if ((this->retrCnt >= this->maxRetr) && (sndTmr.done() )) {						// max retries achieved, but seems to have no answer
		this->retrCnt = 0;
		this->maxRetr = 0;
		this->active = 0;
		if (!reqACK) return;
		
		this->timeOut = 1;																	// set the time out only while an ACK or answer was requested
		pHM->pw.stayAwake(100);
		pHM->ld.set(noack);
		
		#ifdef SN_DBG																		// only if AS debug is set
		dbg << F("  timed out") << ' ' << _TIME << '\n';
		#endif
	}

	if (this->retrCnt == 0xff) {															// answer was received, clean up the structure
		this->timeOut = 0;
		this->retrCnt = 0;
		this->maxRetr = 0;
		this->active = 0;
		sndTmr.set(0);
		
		pHM->pw.stayAwake(100);
		if (!pHM->ld.active) pHM->ld.set(ack);												// fire the status led
	}

	
}