void main (void)
{
	WDTCTL = WDTPW | WDTHOLD;		// Stop watchdog timer

    // Set 16MHz clock
	BCSCTL1 = CALBC1_16MHZ;
	DCOCTL = CALDCO_16MHZ;
	// Startup Delay
	_delay_cycles(2000);

	// Initialize serial port
	SERIAL_init();
	// Enable interrupt
	_EINT();
	rxEchoPos = 0;

	// Set the servo port to digital output
	P2DIR |= BIT2;

 	int deg; // servo rotation degree

 	// Main loop
 	while(1)
 	{
 		// load the target degree from the serial port
 		deg = checkSerial();
 		// if there is a new value
 		if(deg > -1)
 		{
 			// Move the servo
 			moveServo(deg);
 		}
 		__delay_cycles(1000);
 	}
}
Beispiel #2
0
void loop() {
  //checkBlink();
  checkOnOff();
  checkSerial();
  if(bHaveNewMsg){
    writeNewMsg();
  }
  //int reader = analogRead(0);
  //Serial.print(reader/4);
  //Serial.print('\n');
}
Beispiel #3
0
void fingerRoll(int del, int dir)
{
	if(dir==CLOSE)
	{
		for(int i=NUM_FINGERS-1;i>=0;i--)
		{
			fingerControl(i,100,0, gripSpeed);
      if(checkSerial())
		return;
			customDelay(del);
		}
	}
	else
	{
		for(int i=0;i<NUM_FINGERS;i++)
		{
			fingerControl(i,0,0, gripSpeed);
      if(checkSerial())
		return;
			customDelay(del);
		}
	}
}
Beispiel #4
0
int main(void) {

	uchar owAddrBytes[8];
	uchar writeBuffer[] = {0x64, 0xEE, 0x00, 0x00, 0x00, 0x02, 0x03};

	portNum = 0;
	strcpy(portName,"DS2490-1");
	strcpy(serial, "FA00000001743763");

	portNum = owAcquireEx(portName);
	if(portNum <= 0 ) {
		printf("Error acquiring 1-wire USB device\n");
		return 1;
	}

	// Convert string-based serial to owAddress
	if(!checkSerial(serial, owAddrBytes)) {
		owRelease(portNum);
		return 1;
	}

	// DO STUFF HERE

	owSerialNum(portNum, owAddrBytes, FALSE);

	// 1) Test Maxq Read status
	testMaxQReadStatus(portNum, owAddrBytes);

	// 2) See what's in the command buffer initially
	testReadCmdBuffer(portNum, owAddrBytes, 7);

	// 3) Write something to the command buffer
	testWriteCmdBufferExStart(portNum, owAddrBytes, writeBuffer, 7);

	// 4) Test Maxq Read status
	testMaxQReadStatus(portNum, owAddrBytes);

	// 5) Read back what we wrote
	testReadCmdBuffer(portNum, owAddrBytes, 7);

	// Notice that the write succeeds but the release sequence response fails.

	owRelease(portNum);

	printf("Finished Successfully\n");
	return 0;
}
Beispiel #5
0
// this is executed continuously
void appBase::run() {
  float idletime;
  uint32_t thisLoop;

  // delay loop to force update on even looptime boundaries
  while ( millis() < nextLoop ) { // delay until time for next loop
    if( /* lcd != NULL && */ buttons != NULL ) // check for button press
      checkInput();
    checkSerial(); // Has a command been received?
  }

  thisLoop = millis(); // actual time marker for this loop
  // time stamp = system time, seconds, for this set of samples
  timestamp = 0.001 * float( thisLoop ) - reftime;
  getSamples(); // retrieve values from MCP9800 and MCP3424
  if( first ) { // use first set of samples for RoR base values only
    first = false;
    initControl();
  }
  else {
    logSamples(); // output results to serial port
    doControl(); // perform control operations, if required
  }

  // save values for RoR calculation in next loop
  for( int j = 0; j < _NCHAN; j++ ) {
   int k = chan.getChan( j );
   if( k != 0 ) {
     --k;
     flast[k] = ftemps[k];
     lasttimes[k] = ftimes[k];
   }
  }

  idletime = looptime - ( millis() - thisLoop );
  // complain if we don't have some time left
  if (idletime < _IDLE_TIME_ALARM ) {
    Serial.print("# idle: ");
    Serial.println(idletime);
  }

  nextLoop += looptime; // time mark for start of next update
//  Serial.print("nextLoop="); Serial.print( nextLoop );
//  Serial.print("   looptime="); Serial.print( looptime );
//  Serial.println();
}
int main(int argc, char *argv[])
{
	if(argc != 3)
	{
		printf("Usage: %s username serial\n", argv[0]);
		return -1;
	}

	char *ptr;
	unsigned long serial = strtoul(argv[2], &ptr, 10);

	if (checkSerial(argv[1], serial))
	{
		printf("Serial WRONG!\n");
	}
	else
	{
		printf("Serial OK!\n");
	}
	return 0;
}
void ClockController::tick() {
  int	time[7];

  rtc.get(time, true);

  seconds  = time[0];
  minutes  = time[1];
  hours    = time[2];
  //int dow     = time[3];
  day     = time[4];
  month   = time[5];
  year    = time[6];

  temperature = rtc.getTemperature();

  if(currentFace != NULL) {
    if(seconds != currentFace->seconds ||
       minutes != currentFace->minutes ||
       hours   != currentFace->hours)
      currentFace->setTime(hours, minutes, seconds);

    if(day   != currentFace->day ||
       month != currentFace->month ||
       year  != currentFace->year)
      currentFace->setDate(day, month, year);

    if(temperature != currentFace->temperature)
      currentFace->setTemperature(temperature);

    currentFace->lastUpdate = millis();
    currentFace->updateDisplay();
  }

  checkForBeep();
  checkSerial();
}
Beispiel #8
0
void demoMode(void)
{
	MYSERIAL.println("Demo starting");
	
	printGrip(FIST_GRIP,OPEN);
	gripMovement(FIST_GRIP,BLANK,OPEN, gripSpeed);
 if(checkSerial())
 return;
	customDelay(gripDuration);
	
	printGrip(FIST_GRIP,CLOSE);
	gripMovement(FIST_GRIP,BLANK,CLOSE, gripSpeed);
  if(checkSerial())
  return;
	customDelay(gripDuration);
	
	printGrip(FIST_GRIP,OPEN);
	gripMovement(FIST_GRIP,BLANK,OPEN, gripSpeed);
  if(checkSerial())
  return;
	customDelay(gripDuration);
	
	printGrip(FINGER_ROLL,CLOSE);
	fingerRoll(300,CLOSE);
	if (checkSerial())
		return;
	customDelay(gripDuration / 4);
	
	printGrip(FINGER_ROLL,OPEN);
	fingerRoll(300,OPEN);
	if (checkSerial())
		return;
	customDelay(gripDuration / 2);
	
	printGrip(FINGER_ROLL,CLOSE);
	fingerRoll(300,CLOSE);
  if(checkSerial())
  return;
	customDelay(gripDuration/2);
	
	printGrip(FINGER_ROLL,OPEN);
	fingerRoll(300,OPEN);
	
	printGrip(FINGER_ROLL,CLOSE);
	fingerRoll(300,CLOSE);
  if(checkSerial())
  return;
	customDelay(gripDuration/4);
	
	printGrip(FIST_GRIP,OPEN);
	gripMovement(FIST_GRIP,BLANK,OPEN, gripSpeed);
  if(checkSerial())
  return;
	customDelay(gripDuration);

	for(int i=0;i<NUM_GRIPS;i++)
	{
		printGrip(i,CLOSE);
		gripMovement(i,BLANK,CLOSE, gripSpeed);
    if(checkSerial())
    return;
		customDelay(gripDuration);
		
		printGrip(i,OPEN);
		gripMovement(i,BLANK,OPEN, gripSpeed);
    if(checkSerial())
    return;
		customDelay(gripDuration);
	}
	
	#ifdef TRIPOD_GRIP
	printGrip(TRIPOD_GRIP,CLOSE);
	gripMovement(TRIPOD_GRIP,BLANK,CLOSE, gripSpeed);
  if(checkSerial())
  return;
	customDelay(gripDuration);
	
	printGrip(TRIPOD_GRIP,OPEN);
	gripMovement(TRIPOD_GRIP,BLANK,OPEN, gripSpeed);
  if(checkSerial())
  return;
	customDelay(gripDuration);
	#endif
	
	printGrip(PINCH_GRIP,CLOSE);
	gripMovement(PINCH_GRIP,BLANK,CLOSE, gripSpeed);
  if(checkSerial())
  return;
	customDelay(gripDuration);
	
	printGrip(FIST_GRIP,OPEN);
	gripMovement(FIST_GRIP,BLANK,OPEN, gripSpeed);
  if(checkSerial())
  return;
	customDelay(gripDuration);
	
	printGrip(FINGER_ROLL,CLOSE);
	fingerRoll(430,CLOSE);
	customDelay(gripDuration/2);
	
	printGrip(FIST_GRIP,OPEN);
	gripMovement(FIST_GRIP,BLANK,OPEN, gripSpeed);
  if(checkSerial())
  return;
	
	if(!advancedSettings.demoFlag)
		demoFlag = 0;

	MYSERIAL.println("Demo complete");
	
	// if demo mode is enabled from start up
	if(advancedSettings.demoFlag)
	{
		MYSERIAL.println("\nStart up demo mode ON");
		MYSERIAL.println("Enter A0 to disable this mode");
	}
}