示例#1
0
文件: xpl.c 项目: cobree/hasy
//////////////////////////////////////////////////////////
// xpl_init
// Initialisation of the xPL library. Tries to restore the
// INSTANCE_ID from EEPROM
void xpl_init(void){

	// Enable the PWM hardware if required
	// !!!!!!! Warning enabling means that resistor must be dismanteled from print, if not it will be fried !!!!!!!!!!!!!!!
#ifdef PWM_ENABLED
#warning "PWM output enabled on PORTC.2"
	// Enable PORTC.2 output direction 
	TRISC &= 0xFB;

	// Enable the PWM timer
	OpenTimer2(TIMER_INT_OFF &
			T2_PS_1_16 &
			T2_POST_1_1);

	// And enable the PWM
	OpenPWM1(249);
	SetDCPWM1(1000);
#endif

	// Init the helper libraries do that we know if need to 
	// library specific code
	if (!oo_init()){
		xpl_node_configuration |= ONE_WIRE_PRESENT;
		oo_read_temperatures();
	}

    xpl_init_instance_id();
    
    xpl_count_gas = 0;
    xpl_count_water = 0;
    xpl_count_elec = 0;
    
    // Only apply this function after we have read the EEPROM, as we enable serial reception
	// in this function and when we do that we need to know our ID.
	xpl_init_state();
	
	xpl_rx_fifo_write_pointer = 0;
	xpl_rx_fifo_read_pointer = 0;
	xpl_rx_fifo_data_count = 0;
	
	//xpl_rate_limiter = time_ticks;

	xpl_hbeat_sent = 0;

	xpl_flow = FLOW_ON;
	putc(XON, _H_USART);
}
示例#2
0
int main(int argc, char *argv[]) {
  id Object = oo_init();

  id Person = class_new(Object, struct Person, "Person");
  object_call("add_method", Person, "init", person_init);
  object_call("add_method", Person, "greet", person_greet);

  id Friend = class_new(Person, struct Person, "Friend");
  object_call("add_method", Friend, "greet", friend_greet);

  id Cat = class_new(Object, struct Cat, "Cat");
  object_call("add_method", Cat, "init", cat_init);
  object_call("add_method", Cat, "greet", cat_greet);

  id Array = object_call("find", Object, "Array");
  id array = object_new(Array);

  id carl = object_call("autorelease", object_new(Person, "Carl"));
  id jenny = object_call("autorelease", object_new(Friend, "Jenny"));
  id sassy = object_call("autorelease", object_new(Cat, "Sassy", 4, 0));
  id tp = object_call("autorelease", object_new(Cat, "Thunder Pickles", 4, 1));

  object_call("push", array, carl);
  object_call("push", array, jenny);
  object_call("push", array, sassy);
  object_call("push", array, tp);

  for(int ii = 0; ii < 10; ii++) {
    object_call("push", array, tp);
  }

  // these calls are polymorphic because the behavior of the "greet"
  // method depends on the class of the object that it is being
  // invoked on.
  object_call("foreach", array, "println", stdout);
  object_call("foreach", array, "greet");
  object_call("dump", Array, stdout);

  //object_call("undefined", sassy);
  object_call("release", array);
  object_call("release_pending", Object);

  return 0;
}