예제 #1
0
파일: main.cpp 프로젝트: liqinliqin/bb
int main_chmon(int argc, char* argv[])
{
  if (argc!=2)
  {
    printf("Usage: chmon <port>\n");
    _exit(-1);
  }

  const char* devicename = argv[1];

  printf("Waiting for port to become available\n");
  while (access(devicename, F_OK)!=0)
  {
    sleep(1);
  }

  int fd = -1;
  printf("Waiting for access to port\n");
  while (1)
  {
    fd = open(devicename, O_RDWR | O_NOCTTY | O_NONBLOCK);
    if (fd>=0) break;
    perror("Waiting for port:");
  }
  
  arduino_speed(fd);

  // enter the main loop
  while (1)
  {
    // check for messages in the message file
    check_messages(fd);
    
    // get temperature and write it to file.
    get_temperature(fd);
    
    // read in the thermostat temperature
    get_thermostat();
    // update relay
    update_relay(fd);
    // update display
    update_display(fd);
  }
  return 0;
}
예제 #2
0
// This runs continuously in a loop.
void Controller::loop()
{


	//read from wireless, see if ssd or mode changes
	//if the ssd or mode is different from before,
	//update it

	//	_delay_ms(10000);

	//if button is pressed
	if ((bit_is_clear(PIND,5))){//PD5, the button pin, is pressed
		//check to see if still depressed for 5+ seconds:
		_delay_ms(5000);
		if ((bit_is_clear(PIND,5))){
			//button has been selected for 5+ seconds
			//send reset signal to base station
			update_LED(SYSTEM_SYNC);	//turn led blue

			update_relay(0);
			spin_SSDs();	//spin SSDs

			//after sending sync signal, read ssd values and status from base station
			//update ssds
			//update relay
			//update led to on or off
			update_LED(1);	//turn led green, for debgging, remove this
			update_relay(1);

		}
	}


/*
	//after checking button input, now we can check if receiving wireless
	if (0 == 1){	//read from wireless
		//read status
		//read ssd0
		//read ssd1
		if (read_status != status) {	//updating status of relay
			update_relay(read_status);
			update_LED(read_status);
			status = read_status;
		}
		if (read_ssd0 != ssd0) {
			update_ssd0(read_ssd0);
			ssd0 = read_ssd0;
		}
		if (read_ssd1 != ssd1) {
			update_ssd1(read_ssd1);
			ssd1 = read_ssd1;
		}
	}//end if read from wireless
*/

	_delay_ms(100);

	update_ssd0(9);
	update_ssd1(9);



}