Exemple #1
0
cmd_type commBase::read()
{
	//Required - insures we can read the packets 
	startListening();

	cmd_type ret = PKT_EMPTY;
	byte packet[PACKET_SIZE]; //packet buffer
	if (com.available())
	{
		delay(5);
		com.read(packet, PACKET_SIZE);
	}
	else
		return ret;


	for (int i = 0; i < PACKET_SIZE; i++)
		PT(packet[i]);
	PTL();

	byte cmd = packet[0]; //first packet gives the type of packet
	if (cmd == PKT_UPDATE_TEMPERATURE)
	{
		PT("Updating Temp ");
		float * value = (float*)&packet[1];
		temperature_sensor = *value;
		ret = PKT_UPDATE_TEMPERATURE;
		PTL(*value);
	}

	// stopListening();
	return ret;
}
Exemple #2
0
int main() {
	pthread_mutex_t mtx;
	pthread_mutexattr_t mtx_attr;
	PTLockS PTL(&mtx, &mtx_attr);
	/*
	int ret = 0; 

	ret = shm_init();

	if (ret) {
		fprintf(stderr, "shm_init() failed. \n");
		return ret;
	}

	sharedLock->lock();
	for (int i=0; i<10; i++) {
		g_shm->i++;   
		fprintf(stdout, "i = %d, j = %d\n", g_shm->i, g_shm->j);
		sleep(1);
	}
	sharedLock->unlock();

	printf("i: %d\n", g_shm->i);

	return ret;
	*/
}
Exemple #3
0
void switchPage(page_type _page) {
  PTS("Switching from "); PT(page);
  PTS(", to "); PTL(_page);
  page = _page;
  lcd.clear();
  //Without this the page will stay empty for a while
  // forceLCDupdate = true; 
}
Exemple #4
0
void check_serial_cmd()
{
	while (Serial.available())
	{
		delay(1);
		static String command;
		char input = Serial.read();

		if (input == '\r')
		{

		} 
		else if (input == '\n')
		{
			if (command.equals(("size")))
			{
				PTS("Schedule size: ");
				PTL(node_size());
			} else if (command.equals(("mem"))) {
				PTLS("Reading");
				for (int i = 0; i < MAX_NODE; i++) {
					schedule s = node_get(i);
					PT(i); PTS(", ");
					PT(s.day); PTS(", ");
					PT(s.hour); PTS(", ");
					PT(s.minute); PTS(", ");
					PT(s.temperature); PTL();
				}
			} else if (command.equals(("RESET"))) {
				PTLS("Resetting Memory");
				node_RESET();
			}
			command = "";
		}
		else
		{
			command.concat(input);
		}

	}
}
Exemple #5
0
inline void page_modifyTime() {
  static int timeScaleIndex = 0;
  if (pre_page != MODIFY_TIME)
  {
    PTLS("Page Mod Time");
    pre_page = MODIFY_TIME;
    lcd.cursor();
  }
  lcd.setCursor(0,1);
  String str_time = getTimeString(); 
  lcd.print(str_time);

  if (timeScaleIndex == 0) lcd.setCursor(0,1);
  else if (timeScaleIndex == 1) lcd.setCursor(0,4);
  else if (timeScaleIndex == 2) lcd.setCursor(0,7);
    
  if (button_input == PLUS_UP || button_input == PLUS_HOLD)
  {
    long adjust = timeScale[timeScaleIndex];
    adjustTime(adjust);
    setSyncInterval(SCALE_HOUR);
  }
  else if (button_input == MINUS_UP || button_input == MINUS_HOLD)
  {
    long adjust = -timeScale[timeScaleIndex];
    adjustTime(adjust);
    setSyncInterval(SCALE_HOUR);
  }
  else if (button_input == SET_UP)
  {
    setSyncInterval( 3600 );
    switchPage(HOME);
  }
  else if (button_input == MODE_UP)
  {
    timeScaleIndex++;
    timeScaleIndex = timeScaleIndex % 3;
    PTS("Changed focus: "); PTL(timeScaleIndex);
  }
}