예제 #1
0
static void *
sparky_main(void *unused)
{
    track_t *track;
    stop_t *stop;
    int last_state = 0;

    set_lights(false, false);

    if ((track = track_new("tesla.wav")) == NULL) {
	perror("tesla.wav");
	exit(1);
    }
    if (track) track_set_volume(track, 100);

    stop = stop_new();

    while (1) {
	stop_reset(stop);
	if (track) track_play_asynchronously(track, stop);
	while (! stop_is_stopped(stop)) {
	    int ms = random_number_in_range(25, 100);
	    int state;

	    while ((state = random_number_in_range(0, 3)) == last_state) {}
	    last_state = state;

	    set_lights(state & 1, state & 2);
	    ms_sleep(ms);
	}
    }

    return NULL;
}
예제 #2
0
파일: run_elevator.c 프로젝트: aakre/gocode
int main(){
	printf("\nInitialization starting...\n");
	if(!elev_init()){
		printf("\nFailed to initialize elevator...\n");
		return 0;
	}
	printf("\nInitialization complete\n");

	int state = BOOT;
	int event = STOP;
	int order_table[N_FLOORS][N_BUTTONS];
	clear_order_table(order_table);
	
	while(1){
		//printf("\nCurrent state: %d, Current event: %d", state, event);

		state = handle_event(state, event, order_table);
		get_orders(order_table, state);
		set_lights(order_table);

		int temp_event = get_direction(order_table, state);
		if(get_emergency(state)){
			event = EMERGENCY_BUTTON;
		}else if(get_obstruction(order_table, state)){
			event = OBSTRUCTION;
		}else if(temp_event != -1){
			event = temp_event;
		}
	}
	return 0;
} // End main
예제 #3
0
void btnpress()
{
	//     val=digitalRead(btn);
	if(timediff<LONGBUTTONPRESS)
	{
		lightstate=++lightstate%4;
	         set_lights(lightstate);
                 if(!lightstate)
                         lightcounter=0;

	}
	else
	{
//		toggle_led(led,&ledstate);    
                if(laserstate==0)
                  laserstate=1;
                  else
                  laserstate=0;
//                laserstate=!laserstate;
                set_laser(laserstate);

	}
	//  digitalWrite(led,HIGH);

}
예제 #4
0
static
void display (void)
{
	static GLfloat angle;

	angle += delta;

	pm_framestart();

	GLCHK(glMatrixMode(GL_MODELVIEW));
	GLCHK(glLoadIdentity());

	if (d_exponent != 0) {
		exponent += d_exponent;
		if (exponent >= 128)
			exponent = 128;
		if (exponent < 1)
			exponent = 1;
		lights_changed = 1;
	}

	if (d_cutoff != 0) {
		cutoff += d_cutoff;
		if (cutoff > 90)
			cutoff = 90;
		if (cutoff < 2)
			cutoff = 2;
		lights_changed = 1;
	}

	set_lights();

	static const float len = 6;

	float se = sinf(elevation * M_PI / 180);
	float ce = cosf(elevation * M_PI / 180);
	float sb = sinf(bearing * M_PI / 180);
	float cb = cosf(bearing * M_PI / 180);

	float x = ce * cb * len;
	float y = ce * sb * len;
	float z = se * len;


	GLCHK(glEnable(GL_SCISSOR_TEST));

	glLoadIdentity();
	gluLookAt(0, 0, len,  0,0,.5,  0,1,0);
	GLCHK(glScissor(0,0, width/2, height/2));
	GLCHK(glViewport(0,0, width/2, height/2));
	GLCHK(glClearColor(.2,.2,.3,1));
	GLCHK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
	drawscene(angle);

	glLoadIdentity();
	gluLookAt(-len, 0, .5,  0,0,.5,  0,0,1);
	GLCHK(glScissor(width/2,0, width/2, height/2));
	GLCHK(glViewport(width/2,0, width/2, height/2));
	GLCHK(glClearColor(.3,.2,.2,1));
	GLCHK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
	drawscene(angle);

	glLoadIdentity();
	gluLookAt(x,y,z,  0,0,.5,  0,0,1);
	GLCHK(glScissor(width/2,height/2, width/2, height/2));
	GLCHK(glViewport(width/2,height/2, width/2, height/2));
	GLCHK(glClearColor(.2,.2,.2,1));
	GLCHK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
	drawscene(angle);

	glLoadIdentity();
	gluLookAt(0, -len, .5,  0,0,.5,  0,0,1);
	GLCHK(glScissor(0,height/2, width/2, height/2));
	GLCHK(glViewport(0,height/2, width/2, height/2));
	GLCHK(glClearColor(.2,.3,.2,1));
	GLCHK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
	drawscene(angle);

	GLCHK(glScissor(0, 0, width, height));
	GLCHK(glViewport(0, 0, width, height));

	pm_frameend();

	if (shot) {
		shot = 0;
		screenshot("viewports");
	}

	glutSwapBuffers();
	glutPostRedisplay();
}
예제 #5
0
// the loop routine runs over and over again forever:
void loop() {
  byte lclocktick=0;
 //       int j;
	//    analogWrite(9, 60);
	//  TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
	//  TCCR2B = _BV(CS22);
	//  OCR2A = 180;
	//  OCR2B = 50;

	//  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
	if(!(laserstate||lightstate||command_pending))
	{
              
            if(sleepcounter==0)
            {
                attachInterrupt(0, int0, LOW);

		WDT_Stop();
                set_led(led,&ledstate,0);
               set_led(led2,&ledstate2,0);
//                delay(100);
		go_sleep();
                int0f();
		WDT_Init();
            }
	}
        else
            sleepcounter=SLEEPIDLESECS;
        if(clocktick)
        {
          cli();
            lclocktick=clocktick;
            clocktick=0;
          sei();
       	set_led(led,&ledstate,0);

            wdtcounter+=lclocktick;
            sleepcounter--;
           if(!(wdtcounter%BATCHECKSECS))
               checkbat=1;
            if(laserstate)
            		lasercounter++;
            
             if(lightstate)
			lightcounter++;


        }

	if(command_pending==2)
	{
		btnpress();

		command_pending=0;
            

	}
	if(command_pending==1&&millis()-timepressed>LONGBUTTONPRESS)
		int0r();
//	toggle_led(led2,&ledstate2);

	if(laserstate&&(lasercounter>LASER_MAX_ON))
	{
		set_laser(0);
                laserstate=0;

	}
	if(lightstate&&(lightcounter>LIGHT_MAX_ON))
	{
              set_lights(0);
              lightstate=0;
	}

        if(checkbat)
        {
          check_bat();
          checkbat=0;
        }
        if(volts<VBATTHRESH)
        {
             if(lclocktick)
         	    toggle_led(led2,&ledstate2);   
        }
        else   
            set_led(led2,&ledstate2,0);      
        if(volts<VBATTHRESH_CRIT)
        {
          if(!(wdtcounter%BATCHECKCRITSECS))
          {
   //         for(j=0;j<3;j++)
   //         {
              set_lights(0);
              delay(100);
              set_lights(lightstate);
               delay(100);
   //         }
            
          }
          
        }            


	//delay(100);
	//  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
	//  delay(500);               // wait for a second
}