Exemplo n.º 1
0
int main(void)
{
  // Initialize system upon power-up.
  serial_init();   // Setup serial baud rate and interrupts
  settings_init(); // Load grbl settings from EEPROM
  stepper_init();  // Configure stepper pins and interrupt timers
  system_init();   // Configure pinout pins and pin-change interrupt
  ldr_init();        //Setup the ADC

  memset(&sys, 0, sizeof(sys));  // Clear all system variables
  sys.abort = true;   // Set abort to complete initialization
  sei(); // Enable interrupts

  // Check for power-up and set system alarm if homing is enabled to force homing cycle
  // by setting Grbl's alarm state. Alarm locks out all g-code commands, including the
  // startup scripts, but allows access to settings and internal commands. Only a homing
  // cycle '$H' or kill alarm locks '$X' will disable the alarm.
  // NOTE: The startup script will run after successful completion of the homing cycle, but
  // not after disabling the alarm locks. Prevents motion startup blocks from crashing into
  // things uncontrollably. Very bad.
  #ifdef HOMING_INIT_LOCK
    if (bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { sys.state = STATE_ALARM; }
  #endif
  
  // Grbl initialization loop upon power-up or a system abort. For the latter, all processes
  // will return to this loop to be cleanly re-initialized.
  for(;;) {

    // TODO: Separate configure task that require interrupts to be disabled, especially upon
    // a system abort and ensuring any active interrupts are cleanly reset.
  
    // Reset Grbl primary systems.
    serial_reset_read_buffer(); // Clear serial read buffer
    gc_init(); // Set g-code parser to default state
    laser_init();
    probe_init();
    plan_reset(); // Clear block buffer and planner variables
    st_reset(); // Clear stepper subsystem variables.

    // Sync cleared gcode and planner positions to current system position.
    plan_sync_position();
    gc_sync_position();

    // Reset system variables.
    sys.abort = false;
    sys.execute = 0;
    if (bit_istrue(settings.flags,BITFLAG_AUTO_START)) { sys.auto_start = true; }
    else { sys.auto_start = false; }
          
    // Start Grbl main loop. Processes program inputs and executes them.
    protocol_main_loop();
    
  }
  return 0;   /* Never reached */
}
Exemplo n.º 2
0
int main(void)
{
  sei();
  
  serial_init(BAUD_RATE);
  protocol_init();        
  settings_init();  
  plan_init();      
  st_init();
  laser_init();
  gc_init();
  limits_init();
                    
  for(;;){
    sleep_mode(); // Wait for it ...
    protocol_process(); // ... process the serial protocol
  }
  return 0;   /* never reached */
}
Exemplo n.º 3
0
Arquivo: game.c Projeto: chaem/test
void gameStart_Play()
{
	for(int i=0;i<2;i++)
	{
		map_init(&gScreenBuf[i]);
		map_new(&gScreenBuf[i],35,22);

	}

	map_init(&gAlienModel);
	map_load(&gAlienModel,"alien.dat");

	map_init(&gBulletModel);
	map_load(&gBulletModel,"bullet1.dat");

	map_init(&gPlaneModel);
	map_load(&gPlaneModel,"plane1.dat");

	map_init(&gLaserModel);
	map_load(&gLaserModel,"plasma.dat");

	alien_init(&gTestAlienObject,&gAlienModel);
	bullet_init(&gTestBulletObject,0,0,0,&gBulletModel);
	Plane_init(&gPlaneObject,&gPlaneModel,0,0);
	laser_init(&gLaserObject,0,0,0,&gLaserModel);

	gTestAlienObject.m_pBullet = &gTestBulletObject;
	
	gPlaneObject.m_fXpos = 17;
	gPlaneObject.m_fYpos = 20;
	gPlaneObject.m_nFSM = 1;
	gTestAlienObject.m_fXpos = -10;
	gTestAlienObject.m_fYpos = 1;
	gTestAlienObject.m_nFSM = 1;

    system("clear");

}
Exemplo n.º 4
0
int main(void) {
    char c;
    signed char length;
    unsigned char msgtype;
    unsigned char msgbuffer[MSGLEN + 1];
    unsigned char i;

    ANSELA = 0x0; // Set to Digital Function
    ANSELB = 0x0;
    ANSELC = 0x0;
    ANSELD = 0x0;
    ANSELE = 0x0;

    UART_DATA uart_data1;
    UART_DATA uart_data2;
    TIMER_DATA TIMER1;
    timer_init(&TIMER1);

    UART1_Init(&uart_data1);
    UART2_Init(&uart_data2);

    TRISAbits.TRISA0 = 0; // Set PIN A as output
    TRISAbits.TRISA1 = 0;
    TRISAbits.TRISA2 = 0; // Set PIN A as output
    TRISAbits.TRISA3 = 0;

    TRISAbits.TRISA4 = 0; // Set PIN A as output
    TRISAbits.TRISA5 = 0;
    TRISAbits.TRISA6 = 0; // Set PIN A as output
    TRISAbits.TRISA7 = 0;

    LATAbits.LATA1 = 0; //Set PIN for Stepper motor low
    // initialize message queues before enabling any interrupts
    init_queues();

    // Peripheral interrupts can have their priority set to high or low
    // enable high-priority interrupts and low-priority interrupts
    enable_interrupts();

    laser_init();

    /* Junk to force an I2C interrupt in the simulator (if you wanted to)
       PIR1bits.SSPIF = 1;
       _asm
       goto 0x08
       _endasm;
     */

    // printf() is available, but is not advisable.  It goes to the UART pin
    // on the PIC and then you must hook something up to that to view it.
    // It is also slow and is blocking, so it will perturb your code's operation
    // Here is how it looks: printf("Hello\r\n");


    // loop forever
    // This loop is responsible for "handing off" messages to the subroutines
    // that should get them.  Although the subroutines are not threads, but
    // they can be equated with the tasks in your task diagram if you
    // structure them properly.
    while (1) {
        // Call a routine that blocks until either on the incoming
        // messages queues has a message (this may put the processor into
        // an idle mode)
        block_on_To_msgqueues();

        // At this point, one or both of the queues has a message.  It
        // makes sense to check the high-priority messages first -- in fact,
        // you may only want to check the low-priority messages when there
        // is not a high priority message.  That is a design decision and
        // I haven't done it here.
        length = ToMainHigh_recvmsg(MSGLEN, &msgtype, (void *) msgbuffer);
        if (length < 0) {
            // no message, check the error code to see if it is concern
            if (length != MSGQUEUE_EMPTY) {
                // This case be handled by your code.
            }
        } else {
            switch (msgtype) {
                case MSGT_LASER_READ:
                {
                    ReadLaser_Message(msgbuffer, length);
                    break;
                };
                case MSGT_WIFLY_RECIEVE:
                {
                    ReadWIFLY_Message(msgbuffer,length);
                    break;
                };
                default:
                {
                    // Your code should handle this error
                    break;
                };
            };
        }

        // Check the low priority queue
        length = ToMainLow_recvmsg(MSGLEN, &msgtype, (void *) msgbuffer);
        if (length < 0) {
            // no message, check the error code to see if it is concern
            if (length != MSGQUEUE_EMPTY) {
                // Your code should handle this situation
            }


        } else {
            switch (msgtype) {
                case MSGT_TIMER0:
                {
                    Timer_message_handle();
                    break;
                };
                default:
                {
                    // Your code should handle this error
                    break;
                };
            };
        }
    }

}