Example #1
0
/*
 * A simple setup routine, enables/disables the joystick, and makes sure
 * that the button state is read correctly...
 */
void setup(void)
{
  enable_joystick_1x();
  enable_joystick_1y();
  disable_joystick_2x();
  disable_joystick_2y();
  joy_digital();
  read_buttons();                     /* read it twice, I had trouble doing it once only :-( */
  wait_recal();                       /* one round */
  read_buttons();
  wait_recal();                       /* one round */
}
Example #2
0
void loop()
{
	static uint32_t last_run = 0;
	uint32_t current_time = millis();
	if (current_time - last_run >= 5000)
	{
		Serial.println("===============");
		for (uint8_t i = 0; i < CAM_COUNT; i++)
		{
			Serial.print("Camera[");
			Serial.print(i + 1);
			Serial.print("] = ");
			Serial.print(cam_status[i].status, BIN);
			Serial.print(" ");
			Serial.print((millis() - cam_status[i].ref_time) / 1000);
			Serial.println(" sec ago");
		}
		Serial.println("===============");
		Serial.println("request...");
		network.send(14, "E", 1);
		network.send(13, "E", 1);
		last_run = millis();
	}
	network.update();
	network.receive(1000);
	read_buttons();
	indication(current_time);
};
Example #3
0
/**
 * Main.
 *
 * @param	int	 	argc
 * @param	char**	argv
 *
 * @return	int
 */
int main(int argc, char **argv)
{
	bcm2835_set_debug(0);

	if (!bcm2835_init()) {
		return 1;
	}

	// Set each of the pins as input or output
	bcm2835_gpio_fsel(NES_LATCH,BCM2835_GPIO_FSEL_OUTP);
	bcm2835_gpio_fsel(NES_CLOCK,BCM2835_GPIO_FSEL_OUTP);
	bcm2835_gpio_fsel(NES_DATA,BCM2835_GPIO_FSEL_INPT);

	// Initialize clock and latch
	bcm2835_gpio_write(NES_LATCH,LOW);
	bcm2835_gpio_write(NES_CLOCK,LOW);
	
	while(1) {
		
		uint8_t pressed = read_buttons();

		if ((pressed & BTN_A) == BTN_A)
			printf("A");
			
		if ((pressed & BTN_B) == BTN_B)
			printf("B");

		if ((pressed & BTN_SELECT) == BTN_SELECT)
			printf("SELECT");

		if ((pressed & BTN_START) == BTN_START)
			printf("START");

		if ((pressed & BTN_UP) == BTN_UP)
			printf("UP");

		if ((pressed & BTN_DOWN) == BTN_DOWN)
			printf("DOWN");

		if ((pressed & BTN_LEFT) == BTN_LEFT)
			printf("LEFT");

		if ((pressed & BTN_RIGHT) == BTN_RIGHT)
			printf("RIGHT"); 

		if (pressed) {
			printf("\n");
		}

		// Delay approximately 60Hz
		delay(((1 / 60) * 1000));
	}

	bcm2835_close();

	return 0;
}
int main(void)
{	
	init();
	BOOL motors_stopped = FALSE;
	
	send_welcome();
	        
    while (1)
    {	
		if (motors_stopped)
		{
			led_on ( STOP_LED );
			led_off ( GO_LED );
		} else
		{
			led_on( GO_LED );
			led_off( STOP_LED );
		}
		
		read_buttons();
		if (stop_button_pressed)
		{
			motors_stopped = TRUE;
			stop_motors();
		}
		if (prog_button_pressed)
		{
			motors_stopped = FALSE; 
			resume_motors();
		}

		encoder_timeslice();		
		limit_switch_timeslice();
		motor_timeslice_10ms();		
		serial_timeslice();		// handle incoming messages (if avail)

		watchdog_reset();
		//delay(one_second/10);
    }
    return (0);
}
Example #5
0
int main(void) {
	RCC_ClocksTypeDef RCC_Clocks;
	
	/* default value with 440 Hz delta fi and Amplitude 1.0V*/
	d_phi = D_PHI_440HZ;
	b = AMPLITUDE_B_HIGH;
	
    initCEP_Board();
	initTimer_Dac();	
		
	msecs = 0;
	
	
	RCC_GetClocksFreq(&RCC_Clocks);
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
	
	TFT_cursor_off();
	
	//Mark buffer as empty
	buf1.isEmpty = 1;
	buf2.isEmpty = 1;
	
	bgbuf  = &buf1;
	isrbuf = &buf1;
   
	TFT_cls();
	TFT_puts("CEP4");
	TFT_gotoxy(1, 2);
	TFT_puts("Besnik & Burim Mulici");
	TFT_gotoxy(1,5);
	TFT_puts("msecs: ");
	TFT_gotoxy(1,6);
	TFT_puts("Interrupts: ");	
	TFT_gotoxy(1,7);
	TFT_puts("delta_P: ");
	TFT_gotoxy(1,8);
	TFT_puts("Frequenz:  440");
	TFT_gotoxy(1,9);
	TFT_puts("Form:    Sinus");	

	
    while (1) {
		
		read_buttons();
	
		//slow down display output
		if(msecCountVar <= msecCounter) {						 
			msecCountVar++;
		} else {
			msecCountVar = 0;
		}
		
		//Display output
		if((output ==1) && (msecCountVar == msecCounter)){		
			ITM->PORT[11].u32 = 0;
			
			TFT_gotoxy(1,5);
			TFT_puts("msecs: ");
			sprintf(msecbuf, "%d" , msecs);
			TFT_puts(msecbuf);	
			
			TFT_gotoxy(1,6);
			TFT_puts("Interrupts: ");
			sprintf(interruptbuf, "%d", interruptCounter);
			TFT_puts(interruptbuf);
			
			TFT_gotoxy(1,7);
			TFT_puts("delta_P: ");
			sprintf(d_phi_buf, "%d", d_phi);
			TFT_puts(d_phi_buf);
			
			ITM->PORT[11].u32 = 1;
		}
		
		//Buffer empty? If yes fill it and Wait-LED off, else Wait-LED on
		if(bgbuf->isEmpty){										
			
			resetLED(WAITING);
			ITM->PORT[12].u32 = 0;
			fill_Buf(bgbuf);
			ITM->PORT[12].u32 = 1;
						
			if(bgbuf == &buf1) { bgbuf = &buf2;} 
			else{ bgbuf = &buf1;}
			
		} else {
			setLED(WAITING);
		}			       
    }
}
Example #6
0
File: poll.c Project: Ashatta/tools
void poll_inputs()
{
  short changed = 0;
  short button_state = 0;    
  short i;
  short *pOldValue = old_sensor_values;
  sensor_t *pSensor = &sensors[0];
  char packet_available;

  throttle_count--;
  if( throttle_count == 0){
    throttle_count = throttle;

    // If we're not polling or someone already has the monitor
    // return.
    if (!poller || get_monitor_count((&(poller->_super))) != 0)
      return;

    // We do not have a thread that we can use to grab
    // the monitor but that's OK because we are atomic
    // anyway.
      
    // Check the sensor canonical values.
    for (i = 1<<SENSOR_POS; i<(1<<BUTTON_POS); i <<= 1, pOldValue++, pSensor++)
    {
      if (*pOldValue != pSensor->value) {
        changed |= i;
        *pOldValue = pSensor->value;
      }
    }

    // Check the button status
    read_buttons (0x3000, &button_state);
    button_state <<= BUTTON_POS; // Shift into poll position  
    changed |= button_state ^ old_button_state;
    old_button_state = button_state;

    // Check serial status
    check_for_data ( &packet_available, null);
    if (packet_available) {
        changed |= 1 << SERIAL_RECEIVED_POS;
    }

    // Only wake threads up if things have changed since
    // we last looked.    
    if (changed)
    {
      // Or in the latest changes. Some threads may not have
      // responded to earlier changes yet so we can't
      // just overwrite them.
      short jword = 0;
      store_word((byte*)(&jword), 2, changed);
      poller->changed |= jword;
      
#if DEBUG_POLL
      jword = get_word((byte*)&poller->changed, 2);
      printf("Poller: poller->changed = 0x%1X\n", jword);      
#endif
           
      // poller.notifyAll()
      monitor_notify_unchecked(&poller->_super, 1);
    }
  }
}
Example #7
0
int main(int argn,char *argv[])
{
	// Print version
	printf("Fred ver. %s\n",VERSION);

	// Read command line arguments
	init_cmds_line_args(argn,argv);
	// Creates thread
	init_threads();
	// Creates channels
	init_speaker_pipe();
	// Init buttons
	init_buttons();
	// Main loop
	//char job_choise = 0;
	char buttons_choise;
	while(1)
	{		
		// Read GPIO
		/*
		printf("\n\n\n\n\nOpzioni:\n1) Posizione\n2) Beccheggio\n3) Rollio\n4)"
			" Impostazione posizione iniziale\n5) Uscita\nScelta:");
		scanf(" %c",&job_choise);
		if(job_choise == '1') write(PIPE_CHANNEL[1],"1", 1);
		if(job_choise == '2') write(PIPE_CHANNEL[1],"2", 1);
		if(job_choise == '3') write(PIPE_CHANNEL[1],"3", 1);
		if(job_choise == '4') write(PIPE_CHANNEL[1],"4", 1);
		if(job_choise == '5') 
		{
			// Request exit to speaker thread
			write(PIPE_CHANNEL[1],"5", 1);
			// Terminates the get_compass_data thread
			pthread_cancel(get_compass_data_thread);
			break;
		}
		*/
		buttons_choise = read_buttons();
		// Send info to speaker
		if(buttons_choise & BTN_GET_POSITION) write(PIPE_CHANNEL[1],"1", 1);
		if(buttons_choise & BTN_GET_PICH) write(PIPE_CHANNEL[1],"2", 1);
		if(buttons_choise & BTN_GET_ROLL) write(PIPE_CHANNEL[1],"3", 1);
		if(buttons_choise & BTN_SET_POSITION) write(PIPE_CHANNEL[1],"4", 1);
		if(buttons_choise & BTN_POWER_OFF) 
		{
			// Request exit to speaker thread
			write(PIPE_CHANNEL[1],"5", 1);
			// Terminates the get_compass_data thread
			pthread_cancel(get_compass_data_thread);
			break;
		}
		
		sleep(1);
	}
	// Wait for last cmd
	sleep(5);
	// Close the pipe channels
	close(PIPE_CHANNEL[0]);
	close(PIPE_CHANNEL[1]);
	// Wait for the end of the thread
	pthread_join(get_compass_data_thread,NULL);
	pthread_join(speaker_thread,NULL);
	return EXIT_SUCCESS;
}
Example #8
0
void labor6(void) {
    run = 1;
    syncword_address =0;
    spi_address = 0;
    pwmVal = 0;
    HMP3Decoder mp3dec;
    bytesLeft = 0;
    bytesTilSyncWord = 0;
    decodeRetVal = 0;
    errorCounter = 0;
    idx_ISR = 0;
    mainBuf_empty = 1;
    interrupt_Counter = 0;
    mseczaehlvar = 0;

    RCC_ClocksTypeDef RCC_Clocks;
    msec = 0;
    int i = 0;

    //Amplitude 1.0V (b_big)
    amplitude = b_big;

    spi_setup();
    setup_TIM8_DAC_PWM();
    mp3dec = MP3InitDecoder();

    //SysTick end of count event each 10ms
    RCC_GetClocksFreq(&RCC_Clocks);
    SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);

    TFT_cursor_off();

    buf1.isEmpty = 1;
    buf2.isEmpty = 1;

    mp3OutBuffer = &buf1;		//start with buf1
    irsInBuffer = &buf1;

    TFT_cls();
    TFT_gotoxy(1,1);
    TFT_puts("Frequenz:   5000");

    while(B1 != 0 && B2 != 0) {}

    do {
        //Check Buttons
        read_buttons();
        //ausgabe
        print_display();

        //wenn der mainBuf leer ist, muss der durch readSPI mit mp3-daten gefuellt werden
        if (mainBuf_empty) {

            do {

                //Shift bytes to the beginning
                /**
                * Bsp:  mainBufSize = 10
                * 			readBytes = 7 --> bytesLeft = 3
                * 			for(){
                * 				mainBuffer[0] = mainBuffer[(10-3)+0]	idx[0] = idx[7]
                * 				mainBuffer[1] = mainBuffer[(10-3)+1]	idx[1] = ide[8] ...
                */
                for(i = 0; i < bytesLeft; i++) {															//die ungelesene bytes am anfang stellen
                    mainBuf[i] = mainBuf[(MAINBUF_SIZE - bytesLeft) + i];
                }

                //Reads size-bytes from current_SPI_Address and writes them into the given array ((mainBuffer + nBytesLeft))
                //also nach diesem aufruf, ist der mainBuf voll und spiadresse muss verschoben werden
                spiFlashMemRead(SPI_MEM_WORK, spi_address, (mainBuf + bytesLeft),  MAINBUF_SIZE - bytesLeft);

                //nach sync word in dem mainBuf suchen
                bytesTilSyncWord = MP3FindSyncWord(mainBuf, MAINBUF_SIZE);


                if (bytesTilSyncWord == 0) {	//falls guelltige date gleich am anfang liegen
                    spi_address =  spi_address + (MAINBUF_SIZE - bytesLeft);
                } else if (bytesTilSyncWord < 0) {//fehler, kein sync word gefunden
                    run = 0;
                } else if (bytesTilSyncWord > 0) {//falls skip word an der n-te adresse gefunden wurde, verschiebe ich die spiadresse um n, damit ich beim naechsten durchlauf vom flash nur die guelltige daten lese (also muell ueberspringen)
                    spi_address = (spi_address - bytesLeft )+ bytesTilSyncWord;
                }

                bytesLeft = 0;		//MUSS DAS HIER NICHT AUSSERHALB DER WHILE ?? DAMIT DIE NBYTES NICHT VERLOREN GEHEN
            } while(bytesTilSyncWord != 0 && run);

            mainBuf_empty = 0; //mainBuf ist voll
        }


        if (run) {	//wenn kein fehler

            //wenn der mp3OutBuf voll ist ODER der MainBuf leer ist, dann warten (WAITING-LED) anschalten
            if (!mp3OutBuffer->isEmpty || mainBuf_empty) {
                setLED(WAITING_LED);
            } else {
                resetLED(WAITING_LED);

                bytesLeft = MAINBUF_SIZE;																					//in nBytesLeft steht wieviele daten aus dem MainBuf noch in dem mp3OutBuf uebertragen werden muessen
                ptrMainBuf = mainBuf;																			//mainBufPointer soll auf MainBuff zeigen, obwohl es bei der initialisierung schon gemacht wurde !!

                /**
                	* para1: decoder instance
                	*	para2: buffer aus dem die daten decodet werden sollen
                	* para3: (input) --> anzahl gueltige bytes, die gelesen werden sollen,
                	* 			 (output)--> input - gelesene bytes, also die bytes die noch gelesen werden muessen
                	* para4: der buffer in dem geschrieben werden soll, der pointer wird geupdatet (bis wo der voll geschrieben wurde)
                	*/

                //nach diesem aufruf ist der mp3OutBuf auf jeden fall voll
                decodeRetVal = MP3Decode(mp3dec, &ptrMainBuf, &bytesLeft, mp3OutBuffer->data, 0);		//decodeResult -->(0 means no error, < 0 means error)


                mainBuf_empty = 1;																									//der mainBuf ist nicht komplett voll

                if (decodeRetVal < 0) {
                    errorCounter++;
                } else {
                    errorCounter = 0;
                }

                if (errorCounter > 2) {																							//fehler beim decode aufgetreten
                    run = 0;
                } else {
                    mp3OutBuffer->isEmpty = 0;																			//der mp3OutBuffer wurde voll geschrieben, bereit fuer die ISR
                    if(mp3OutBuffer == &buf1) {																			//buffer ist voll, also wechseln
                        mp3OutBuffer = &buf2;
                    } else if (mp3OutBuffer == &buf2) {
                        mp3OutBuffer = &buf1;
                    }
                }
            }
        }

    } while (run);

    MP3FreeDecoder(mp3dec);

}
void readSettings(void)
{
	int i;

	ZeroMemory(&mSkin, offset_hooks);

	//====================
	// titlebar click actions
	for (i = 0; i < 12; i++)
	{
		static const char *modifiers[] = { "", "Shift", "Ctrl" };
		static const char *buttons[]  = { "Dbl", "Right", "Mid", "Left" };
		static const char *button_ids[6+1+1] =
		{
			"Close", "Maximize", "Minimize",
			"Rollup", "AlwaysOnTop", "Pin",
			"Lower", NULL
		};

		char rcstring[80];
		sprintf(rcstring, "bbleanskin.titlebar.%s%sClick:", modifiers[i%3], buttons[i/3]);
		const char *p = ReadString(rcpath, rcstring, "");
		mSkin.captionClicks.Dbl[i] = get_string_index(p, button_ids);
	}

	// ############# EDIT: MADE ALL BUTTONS VISIBLE BY DEFAULT ##############
	// ##### (MAKES MORE SENSE, UNLESS BUTTONS 5 and 6 DO NOT WORK (?)) #####
	//  strncpy(mSkin.button_string, ReadString(rcpath, "bbleanskin.titlebar.buttons:", "400321"), 6);
	strncpy(mSkin.button_string, ReadString(rcpath, "bbleanskin.titlebar.buttons:", "465321"), 6);
	// ######################################################################

	// button pics
	read_buttons();

	//====================
	// other settings

//	mSkin.nixShadeStyle = ReadBool(rcpath, "bbleanskin.option.nixShadeStyle:", true);
	mSkin.nixShadeStyle = ReadBool(rcpath, "bbleanskin.option.nixShadeStyle:", false);
//	mSkin.snapWindows = ReadBool(rcpath, "bbleanskin.option.snapWindows:", true);
	mSkin.snapWindows = ReadBool(rcpath, "bbleanskin.option.snapWindows:", false);
	applyToOpen = ReadBool(rcpath, "bbleanskin.option.applyToOpen:", true);
//	adjustCaptionHeight = ReadBool(rcpath, "bbleanskin.option.adjustCaptionHeight:", false);
	adjustCaptionHeight = ReadBool(rcpath, "bbleanskin.option.adjustCaptionHeight:", true);
	enableLog = ReadBool(rcpath, "bbleanskin.option.enableLog:", false);

	//mSkin.drawLocked = ReadBool(rcpath, "bbleanskin.option.drawLocked:", false);
	mSkin.imageDither = ReadBool(bbrcPath(), "session.imageDither:", false);

	//====================
	// windows appearance settings
	MenuHeight = ReadInt(rcpath, "bbleanskin.windows.menu.height:", -1);
	strcpy(windows_menu_fontFace, ReadString(rcpath, "bbleanskin.windows.menu.Font:", ""));
	windows_menu_fontHeight = ReadInt(rcpath, "bbleanskin.windows.menu.fontHeight:", 8);
	ScrollbarSize = ReadInt(rcpath, "bbleanskin.windows.scrollbarsize:", -1);
	setTTColor = ReadBool(rcpath, "bbleanskin.windows.setToolTipColor:", false);

	mSkin.BBhwnd = BBhwnd;
	mSkin.BBVersion = BBVersion;
	mSkin.loghwnd = m_hwnd;
	mSkin.enableLog = enableLog;
}
Example #10
0
uint8_t TM1638::getButtons()
{
    return read_buttons();
}