Ejemplo n.º 1
0
S16 Read_temperature(void)
{
#ifndef AVRGCC
   U16 adc_code;
   S8 index=0;
   adc_code=Get_adc_temp_val();
   if(adc_code>temperature_code[0])
   {
      return (S16)(-20);
   }
   else
   {
      while(temperature_code[index++]>adc_code);
      return (S16)(index-1-20);
   }
#else
   U16 adc_code;
   S8 index=0;
   adc_code=Get_adc_temp_val();
   if(adc_code>pgm_read_word_near(&temperature_code))
   {
      return (S16)(-20);
   }
   else
   {
      while(pgm_read_word_near(&temperature_code[index++])>adc_code);
      return (S16)(index-1-20);
   }   

#endif
}
Ejemplo n.º 2
0
Color ColorList::getNextColor(int address){
  address++;
  if (address != address % _sizeOfList){
    address = address % _sizeOfList;
    Serial.println("address looped in getColor");
  }
  int red = pgm_read_word_near(_listPointer + address * 4);
  int green = pgm_read_word_near(_listPointer + address * 4 + 1);
  int blue = pgm_read_word_near(_listPointer + address * 4 + 2);
  return Color(red,green,blue);
};
Ejemplo n.º 3
0
/* Main Program Routine */
int
main(void)
{
    uint16_t pgm_crc, count, cmp_crc;
	uint8_t crcgood=0;
#ifdef UART_DEBUG
    char sout[8];    
#endif

	init();
#ifdef UART_DEBUG
	uart_write("\nStart Node ", 12);
	itoa(node_id,sout, 16);
	uart_write(sout, strlen(sout));
	uart_write("\n", 1);
#endif

    /* Find the firmware size and checksum */
	count   = pgm_read_word_near(PGM_LENGTH);
    cmp_crc = pgm_read_word_near(PGM_CRC);

	/* Retrieve the Program Checksum */
	pgm_crc = pgmcrc(count);
	/* If it matches then set the good flag */
	if(pgm_crc == cmp_crc) {
	    crcgood = 1;
    }
#ifdef UART_DEBUG
    itoa(pgm_crc,sout,16);
	uart_write("Checksum ", 9);
	uart_write(sout,strlen(sout));
	uart_write("\n",1);
#endif
	/* This timer expires at roughly one second after startup */
	while(TCNT1 <= 0x2B00) /* Run this for about a second */
        bload_check();
    TCNT1 = 0x0000;
#ifdef UART_DEBUG
	uart_write("TIMEOUT\n",8);
#endif
	if(crcgood) {
	   start_app(); /* When we go here we ain't never comin' back */
    }
	
    /* If CRC is no good we sit here and look for a firmware update command
       forever. */
    PORTB |= (1<<PB0);
    while(1) { 

        bload_check();
        _delay_loop_2(0xFFFF); /* Delay */
	}	
}
Ejemplo n.º 4
0
int KEMPER_NAMESPACE::getOptionValue(PartialParameter *parameter, int optionIndex) {
	if (parameter->totalOptionCount && optionIndex<parameter->totalOptionCount && optionIndex>=0) {
		PGM_KemperParam** params = (PGM_KemperParam**)pgm_read_word_near(&AllStomps[parameter->stompInfo->PGM_index].params);
		const PGM_KemperParam *psrc = (PGM_KemperParam*)pgm_read_word_near(&params[parameter->currentParam]);
		KemperParamOption** options = (KemperParamOption**)pgm_read_word_near(&psrc->options);
		if (!options)
			return 0;
		KemperParamOption* option = (KemperParamOption*)pgm_read_word_near(&options[optionIndex]);
		return (int)pgm_read_word_near(&option->value);
	}
	else {
		return 0;
	}
}
Ejemplo n.º 5
0
void X10Firecracker::sendCmd(HouseCode house, int device, CommandCode cmnd)
{
	unsigned int dataBuff = 0;
	byte messageBuff[5];

	// Build message by ORing the parts together. No device if Bright or Dim,
	// the bright and dim codes operate on the last-addressed device
	if ( (cmnd == cmdOn) | (cmnd == cmdOff) )
	{
		dataBuff =  pgm_read_word_near( houseCode  + house      )
		          | pgm_read_word_near( deviceCode + (device-1) ) 
				  | pgm_read_word_near( cmndCode   + cmnd       );
	} else { 
		dataBuff =  pgm_read_word_near( houseCode  + house ) 
		          | pgm_read_word_near( cmndCode   + cmnd  );
	}

	// Build a string for the whole message 
	messageBuff[0] = 0xD5;               // Header byte 0 11010101 = 0xD5 
	messageBuff[1] = 0xAA;               // Header byte 1 10101010 = 0xAA 
	messageBuff[2] = dataBuff >> 8;      // MSB of dataBuff
	messageBuff[3] = dataBuff & 0xFF;    // LSB of dataBuff
	messageBuff[4] = 0xAD;               // Footer byte 10101101 = 0xAD

	// Now send it out to CM17A 
	digitalWrite(DTR_pin, LOW);	 // reset device - both low is power off
	digitalWrite(RTS_pin, LOW);
	delay(Bit_delay);

	digitalWrite(DTR_pin, HIGH); // standby mode - supply power
	digitalWrite(RTS_pin, HIGH);
	delay(35);                   // need extra time for it to settle

	for (byte i=0; i<5; i++){
		for( byte mask = 0x80; mask; mask >>=1 )
		{
			if( mask & messageBuff[i] ) 
				digitalWrite(DTR_pin, LOW);   // 1 = RTS HIGH/DTR-LOW
			else 
				digitalWrite(RTS_pin, LOW);   // 0 = DTR-HIGH/RTS-LOW
			delay(Bit_delay);                 // delay between bits

			digitalWrite(DTR_pin,HIGH);       // wait state between bits
			digitalWrite(RTS_pin,HIGH);
			delay(Bit_delay);
		}  
	}
	delay(1000);                         	 // wait required before next xmit
}
Ejemplo n.º 6
0
void SerialSend(uint8_t val){
	cli();
	TCCR1B = TCCR1B_Value;
	TCNT1 = 0;
	uint16_t timing;
	prog_uint16_t* pTiming = CUR_TIMING;
	PORT_Send &= ~BIT_Send;timing = pgm_read_word_near(pTiming++);while(TCNT1<timing);//startbit
	uint8_t chkbit = 0x01;
	for(uint8_t i = 8 ; i > 0 ; i--)
	{
		if(val&chkbit){PORT_Send |= BIT_Send;}else{PORT_Send &= ~BIT_Send;}chkbit<<=1;timing = pgm_read_word_near(pTiming++);while(TCNT1<timing);
	}
	PORT_Send |= BIT_Send;timing = pgm_read_word_near(pTiming);while(TCNT1<timing);
	sei();
}
Ejemplo n.º 7
0
/**
   Kerzen-Effekt
*/
void Effects::showCandle(eColors color) {
  word matrix [16];
  for (byte k = 0; k < 5; k++) {
    for (int j = -4; j < 4; j++) {
      renderer.clearScreenBuffer(matrix);
      for (byte i = 5; i < 10; i++) {
        matrix[i] |= (pgm_read_word_near(&(effectMasksCandle[5][i])) << 5);
      }
      for (byte i = 0; i < 5; i++) {
        matrix[i] |= (pgm_read_word_near(&(effectMasksCandle[4 - abs(j % 4)][i])) << 5);
      }
      writeToBuffer(matrix, 10, color);
    }
  }
}
Ejemplo n.º 8
0
//The acos function uses a lookup table for corresponding output. 
//Output data are stored as byte values (0 - 255), they are scaled down to float number (0.0 - 1.0) for output.
float Turbo_Trig::acos(float num) {
  float rads = 0;
  bool negative = false;
  uint8_t step = 0;
  
  //Get sign of input
  if(num < 0) {
    negative = true;
    num = -num;
  }
  
  if((num >= 0) && (num < 0.9)) {
    //num between 0 and 0.9.
    step = TurboTrig.floatToInt(num * DEC4 / 79);
  } else if ((num >= 0.9) && (num < 0.99)) {
    //num between 0.9 and 0.99.
    step = TurboTrig.floatToInt((num * DEC4 - 9000) / 8) + 114;
  } else if ((num >= 0.99) && (num <= 1)) {
    //num between 0.99 and 1.0.
    step = TurboTrig.floatToInt((num * DEC4 - 9900) / 2) + 227;
  }
  
  rads = (float)((uint8_t)pgm_read_word_near(ACOS_TABLE + step) * 0.00616);
  
  //Account for the negative sign if required.
  if(negative) {
    rads = PI - rads;
  }
  
  return rads;
}
Ejemplo n.º 9
0
/**
 * Reads flash address and sends it through uart
 *
 * Note: does not avoid the bootloader area to be read.
 *
 * @param address The starting address to be read
 * @param size The size of memory to be read
 * @return Returns the address+size (next address to be read)
 */
static inline uint16_t readFlashPage(uint16_t waddr, pagebuf_t size)
{
  uint32_t address = (uint32_t)waddr<<1;
  uint16_t data;

  do {
#if defined(RAMPZ)
      data = pgm_read_word_far(address);
#else
      data = pgm_read_word_near(address);
#endif

      // This is to make avrdude not complaint about
      // errors when reading the interrupt table area
      // after writing the flash
      if(address == RESET_VECTOR_OFFSET * 2)
        data = vectorTemp[0];
      else if(address == PCINT0_VECTOR_OFFSET * 2)
        data = vectorTemp[1];
      else if(address == TIM0_COMPA_VECTOR_OFFSET * 2)
        data = vectorTemp[2];
      else if(address == TIM0_COMPB_VECTOR_OFFSET * 2)
        data = vectorTemp[3];
      
      swuartXmit(data);                 // send LSB
      swuartXmit((data >> 8));          // send MSB
      address += 2;                       // Select next word in memory
      size -= 2;                        // Subtract two bytes from number of bytes to read
  } while (size);                     // Repeat until block has been read

  return address>>1;
}
/** Special startup routine to check if the bootloader was started via a watchdog reset, and if the magic application
 *  start key has been loaded into \ref MagicBootKey. If the bootloader started via the watchdog and the key is valid,
 *  this will force the user application to start via a software jump.
 */
void Application_Jump_Check(void)
{
	/* Check the reason for the reset so we can act accordingly */
	uint8_t  mcusr_state = MCUSR;		// store the initial state of the Status register
	MCUSR = 0;							// clear all reset flags

	/* If a request has been made to jump to the user application, honor it */
	if (
		// If it's not an external reset
		!(mcusr_state & (1<<EXTRF))
		// And after a power-on reset...
		&& ((mcusr_state & (1<<PORF))
		// ... or Boot Key is set
		|| MagicBootKey == MAGIC_BOOT_KEY)
		// And there is a firmware in memory
		&& (pgm_read_word_near(0) != 0xFFFF))
	{
		/* Turn off the watchdog */
		//MCUSR &= ~(1 << WDRF);
		//wdt_disable();

		/** Enable watchdog by default, the user application either needs to
		 *  disable it, or reset it on a regular basis. This is to make sure
		 *  that if the user code is faulty, the board will return automatically
		 *  to booloader mode.
		 */
		wdt_enable(WDTO_2S);

		/* Clear the boot key and jump to the user application */
		MagicBootKey = 0;

		// cppcheck-suppress constStatement
		((void (*)(void))0x0000)();
	}
}
Ejemplo n.º 11
0
void PT04::pt04()
{
	long t1=micros();

    if(digitalRead(2)!=pt04_state) 
    {
		// wrong state, restart
		reset();
		return;
    }
    
    int currentSlot = pgm_read_word_near(&pt04_pattern[pt04_count]);
    
    if(currentSlot)
    {
		long dt=(t1-pt04_t)-currentSlot;
		if(dt<-TOLERANCE || dt>TOLERANCE) 
		{
			// did not meet timing, restart
			reset();
			return;
		}
    }
    pt04_t=t1;
    pt04_state=!pt04_state;
    pt04_count++;
    
    if(pt04_count>=pt04_patternLength) 
    {
		// pattern complete, set trigger flag and restart
		pt04_triggered=1;
		reset();
    }
}
Ejemplo n.º 12
0
void starburst_main()
{
#ifdef STARBURST_PCA9685
	if(update == STARBURST_UPDATE) /*Only transmit if at least one channels has been updated*/
	{
		update=STARBURST_NOUPDATE;
		/*Prepare Array*/
		uint16_t pca9685_values[2*STARBURST_PCA9685_CHANNELS];
		for(uint8_t i=0;i<STARBURST_PCA9685_CHANNELS*2;i+=2)
		{
			uint16_t tmp=pgm_read_word_near(stevens_power_12bit + pca9685_channels[i/2].value);
			pca9685_channels[i/2].update = STARBURST_NOUPDATE;
			if(tmp == 4096) /*Special case: LED is always on, that means we need to set ON to 4096*/
			{
				pca9685_values[i]=4096;
				pca9685_values[i+1]=0;
			}
			else if(tmp == 0) /*Special case: LED is always off, that means we need to set OFF to 4096*/
			{
				pca9685_values[i]=0;
				pca9685_values[i+1]=4096;
			}
			else /*Default case: LED needs PWM*/
			{
				pca9685_values[i]=0;
				pca9685_values[i+1]=tmp;
			}
		}
		i2c_pca9685_set_leds(STARBURST_PCA9685_ADDRESS,0,STARBURST_PCA9685_CHANNELS*2,pca9685_values);
	}
#endif
}
uint8_t SFEMP3Shield::playMP3(char* fileName){

	if (playing) return 1;

	//Open the file in read mode.
	if (!track.open(&root, fileName, O_READ)) return 2;
	   
	playing = TRUE;
	
	//look for first MP3 frame (11 1's)
	bitrate = 0;
	uint8_t temp = 0;
	uint8_t row_num =0;
	
	
	for(uint16_t i = 0; i<65535; i++){
	//for(;;){
		if(track.read() == 0xFF) {
			
			temp = track.read();
			
			if(((temp & 0b11100000) == 0b11100000) && ((temp & 0b00000110) != 0b00000000)) {

				//found the 11 1's
				//parse version, layer and bitrate out and save bitrate
				if(!(temp & 0b00001000)) //!true if Version 1, !false version 2 and 2.5
					row_num = 3;
			    if((temp & 0b00000110) == 0b00000100) //true if layer 2, false if layer 1 or 3
					row_num += 1;
				else if((temp & 0b00000110) == 0b00000010) //true if layer 3, false if layer 2 or 1	
					row_num += 2;
				
				//parse bitrate code from next byte
				temp = track.read();
				temp = temp>>4;
				
				//lookup bitrate
				bitrate = pgm_read_word_near ( temp*5 + row_num );
				//							      bitrate_table[temp][row_num];
				
				//convert kbps to Bytes per mS
				bitrate /= 8;
				
				//record file position
				track.seekCur(-3);
				start_of_music = track.curPosition();
				
				//Serial.print("POS: ");
				//Serial.println(start_of_music);
				
				//Serial.print("Bitrate: ");
				//Serial.println(bitrate);
				
				//break out of for loop
				break;
			
			}
		    
		}
	}
Ejemplo n.º 14
0
static inline uint16_t readFlashPage(uint16_t waddr, uint8_t size)
{
	uint32_t baddr = (uint32_t)waddr<<1;
	uint16_t data;
	uint8_t i;
	i = 0x00;

	do
	{

		#ifndef READ_PROTECT_BOOTLOADER
		#warning "Bootloader not read-protected"

		#if defined(RAMPZ)
		data = pgm_read_word_far(baddr);
		#else
		data = pgm_read_word_near(baddr);
		#endif

		#else
		// don't read bootloader
		if ( baddr < APP_END )
		{
			#if defined(RAMPZ)
			data = pgm_read_word_far(baddr);
			#else
			data = pgm_read_word_near(baddr);
			#endif
		}
		else
		{
			data = 0xFFFF; // fake empty
		}
		#endif
		
		gBuffer[i] = data;			// send LSB
		i++;
		gBuffer[i] =data >> 8;		// send MSB
		i++;

		baddr += 2;			// Select next word in memory
		size -= 2;			// Subtract two bytes from number of bytes to read
	}
	while (size);				// Repeat until block has been read
	
	return baddr>>1;
}
Ejemplo n.º 15
0
int ColorList::getDelay(int address){
  if (address != address % _sizeOfList){
    address = address % _sizeOfList;
    Serial.println("address looped in Delay");
  }
  int colorDelay = pgm_read_word_near(_listPointer + address * 4 + 3);
  return colorDelay;
};
Ejemplo n.º 16
0
//starts the playing of the selected song
void play_song(char song)
{
  //determine the note length based on the tempo of the song
  song_note_len = ( 60000 / pgm_read_word_near(tempo + song)) * 4;
  
  //determine the end position of the song
  song_end_pos = pgm_read_word_near(song_start + (song+1)) - 1;
  
  //set the note to the first note of the song
  current_note = pgm_read_word_near(song_start + song);
  
  //set the state to 'playing'
  music_state = SONG_PLAYING;
  
  //set the current song value to the passed parameter
  current_song = song;
}
Ejemplo n.º 17
0
//handles the music/sfx playing for the sketch
void update_sound()
{
  switch (music_state)
  {
  case SONG_PLAYING:
  case SONG_PLAYING_ONCE:
  case SONG_PLAYING_SFX:
    static long next_note_start_time = 0;
    if (millis() >= next_note_start_time)
    {
      if (current_note == song_end_pos)
      {
         switch (music_state)
         {
	    //it's the end of the song, so we can contine
	    case SONG_PLAYING:
	         music_state = SONG_ENDED;
                  break;
			  
	    case SONG_PLAYING_ONCE:
                 music_state = MUSIC_STOPPED;
                 break;	

           case SONG_PLAYING_SFX:
		//restore the old state of the music and continue
		song_note_len = old_song_note_len;
		song_end_pos = old_song_end_pos;
		current_note = old_current_note;
		music_state = old_music_state; 
                current_song = old_current_song;
                break;		   
	 }
      }
      
     //determine the current note duration
      int note_duration = ( song_note_len / pgm_read_byte_near(duration + current_note));
  	  
      next_note_start_time = millis()+note_duration;
	  
	  //play the note
      tone(9,pgm_read_word_near(melody + current_note), note_duration); 
  	
      current_note++;  
    }
    break;
	
   case SONG_ENDED:
     //start the same song over automatically
     play_song(current_song);
	 break;
   
   case MUSIC_STOPPED:
     //we are idle, until a new play action is initiated
     break;
  }
}
Ejemplo n.º 18
0
// ------------------------------------------------------------------------------
static void
prvvMelodyTask (xTaskHandle xDummy __attribute__ ((unused))) {

  switch (ucMelodyState) {

    case IDLE_STATE:
    case PAUSE_STATE:
      if (pxMelodyNextNote) {
        const xNote *pxNextNote;
        static xNote xPgmNote;  // copie de la note FLASH en RAM

        if (ucMelodyFlags & PGM_FLAG) {

          memcpy_P (&xPgmNote, pxMelodyNextNote, sizeof (xNote));
          pxNextNote = &xPgmNote;
        } else {

          pxNextNote = pxMelodyNextNote;
        }

        if (pxNextNote->pitch < PITCH_MAX) {

          if (pxNextNote->pitch != PITCH_PAUSE) {

            // si la note n'est pas une pause
            vMelodyHardwarePlay (pgm_read_word_near
                                 (&pxPitchToFreq[pxNextNote->pitch]));
          } else {

            // sinon commencer à jouer une pause
            vMelodyHardwareStop ();
          }
          /* calcule la durée de la note ou de la pause, et modifie la tâche en
           * conséquence */
          vTaskSetInterval (xMelodyTimer,
                            xTaskConvertMs (xMelodyDuration *
                                            pxNextNote->length -
                                            xMelodyInternote));
          pxMelodyNextNote++; // passer à la note suivante
          ucMelodyState = PLAY_STATE;
          vTaskStart (xMelodyTimer);
          return;
        }
      }
      vMelodyStop (); // si note.pitch >= PITCH_MAX ou pointeur nul -> arrêter
                      // le son
      break;

    case PLAY_STATE:
      vMelodyHardwareStop ();
      ucMelodyState = PAUSE_STATE;
      vTaskSetInterval (xMelodyTimer, xTaskConvertMs (xMelodyInternote));
      vTaskStart (xMelodyTimer);
      break;
  }
}
Ejemplo n.º 19
0
bool TouchKeyboard::getScanCode(uint8_t &scanCode, bool wait, Point &pressPt)
{
	uint8_t row, key;
	bool result = getKeyPressed(row, key, wait, pressPt);
	if (result)
	{
		uint16_t scanCodes = pgm_read_word_near(&keyboardRow[row].codes);
		scanCode = pgm_read_byte_near(scanCodes + key);
	}
	return result;
}
Ejemplo n.º 20
0
/**
 * метод перехода к следующему шагу табличного КА во flash:
 *
 * Читает из flash текущий интервал ожидания и устанавливает номер следующего состояния,
 */
void tsc_next( TSC_Control *_tsc, TSC_Step_Count _state )
{
  // определяем место хранения структуры текущего состояния КА
  const TSC_Step * current PROGMEM = _tsc->table + _tsc->state;

  _tsc->timeout    = (TSC_Time)pgm_read_word_near( &(current->timeout) );

  _tsc->state      = _state;                            // устанавливаем следующее состояние
  _tsc->started_at = (TSC_Time)tscGetTime();           // и его стартовое время

}
Ejemplo n.º 21
0
void SpiderAuto::nextMove()
{  
    int totalSteps=0;
    if (actionType==1) {
        totalSteps = sizeof(spiderAutoAction1)/sizeof(int)/13;
        pMoveTask->tickInterval = (unsigned long)pgm_read_word_near(spiderAutoAction1+moveStep*13)*1000L;
        for (int i=0; i<NumberOfServo; i++) {
            motor.setAngle(i,pgm_read_word_near(spiderAutoAction1+moveStep*13+(i+1)));
        }
        if (++moveStep>=totalSteps) moveStep=0;
    }
    if (actionType==2) {
        totalSteps = sizeof(spiderAutoAction2)/sizeof(int)/13;
        pMoveTask->tickInterval = (unsigned long)pgm_read_word_near(spiderAutoAction2+moveStep*13)*1000L;
        for (int i=0; i<NumberOfServo; i++) {
            motor.setAngle(i,pgm_read_word_near(spiderAutoAction2+moveStep*13+(i+1)));
        }
        if (++moveStep>=totalSteps) moveStep=0;
    } 
    if (actionType==3) {
       totalSteps = sizeof(spiderAutoAction3)/sizeof(int)/13;
        pMoveTask->tickInterval = (unsigned long)pgm_read_word_near(spiderAutoAction3+moveStep*13)*1000L;
        for (int i=0; i<NumberOfServo; i++) {
            motor.setAngle(i,pgm_read_word_near(spiderAutoAction3+moveStep*13+(i+1)));
        }
        if (++moveStep>=totalSteps) moveStep=0;
    }
}
Ejemplo n.º 22
0
static uint8_t get_channel_from_eeprom() {
	uint8_t x[2];
	*(uint16_t *)x = eeprom_read_word ((uint16_t *)&eemem_channel);
    if((uint8_t)x[0]!=(uint8_t)~x[1]) {//~x[1] can promote comparison to 16 bit
/* Verification fails, rewrite everything */
    uint8_t mac[8];
#if JACKDAW_CONF_RANDOM_MAC
    PRINTA("Generating random MAC address.\n");
    generate_new_eui64(&mac);
#else
    {uint8_t i; for (i=0;i<8;i++) mac[i] = pgm_read_byte_near(default_mac_address+i);}
#endif
	eeprom_write_block(&mac,  &eemem_mac_address, 8);
  	eeprom_write_word(&eemem_panid  , pgm_read_word_near(&default_panid));
   	eeprom_write_word(&eemem_panaddr, pgm_read_word_near(&default_panaddr));
    eeprom_write_byte(&eemem_txpower, pgm_read_byte_near(&default_txpower));
    x[0] = pgm_read_byte_near(&default_channel);
    x[1]= ~x[0];
    eeprom_write_word((uint16_t *)&eemem_channel, *(uint16_t *)x);    
  }
  return x[0];
}
Ejemplo n.º 23
0
static uint16_t get_panaddr_from_eeprom(void) {
    uint16_t x;
    if (settings_check(SETTINGS_KEY_PAN_ADDR,0)) {
        x = settings_get_uint16(SETTINGS_KEY_PAN_ADDR,0);
        PRINTD("<-Get EEPROM PAN address of %04x.\n",x);
    } else {
	    x=pgm_read_word_near(&default_panaddr);
        if (settings_add_uint16(SETTINGS_KEY_PAN_ADDR,x)==SETTINGS_STATUS_OK) {
          PRINTA("->Set EEPROM PAN address to %04x.\n",x);
        }
    }        
	return x;
}
Ejemplo n.º 24
0
void Pt6311::setDigitChar(byte index, char chr)
{
	if (chr >= '0' && chr <= '9')
		chr -= '0';
	else if (chr >= 'A' && chr <= 'Z')
		chr -= 'A', chr += 10;
	else if (chr >= 'a' && chr <= 'z')
		chr -= 'a', chr += 10;
	else
		return;

	word pattern = pgm_read_word_near(SIG14_FONT + chr);
	this->setDigit(index, pattern);
}
Ejemplo n.º 25
0
// метод "шаг цикла КА" в микросекундах по 4мксек [0,4,..1024мксек]:
// параметр - указатель на состояние заданного КА.
void tsc_microStep( TSC_Control *_tsc )
{
  // если задана таблица (нет - выключен!)
  if( _tsc->table ){
    // если событие, переключающее КА - наступило:
    if( (((TSC_Time)timerCount(0))<<2) - _tsc->started_at >= _tsc->timeout )
    {
      // определяем место хранения структуры состояния КА
      const TSC_Step * current PROGMEM = _tsc->table + _tsc->state;

      // читаем и исполняем команду и получаем номер следующего состояния или нуль(+=1):
      TSC_Command    command = (TSC_Command)pgm_read_word_near( &(current->command) );
      TSC_Step_Count    next = (TSC_Step_Count)pgm_read_word_near( &(current->next) );

      // и сразу устанавливаем следующий шаг КА и начало периода
      tsc_next(_tsc, next);

      // исполнение команды - последним. Её время выполнения ВХОДИТ в ожидание,
      // допускается вызов tsc_next() из самой команды - принудительная смена состояния в команде
      if( command ) { command(_tsc); }
    }
  }
}
Ejemplo n.º 26
0
USING_NAMESPACE_KEMPER


bool KEMPER_NAMESPACE::loadStompInfo(StompInfo *dst, int stompId, int id)
{
	int indexOffset = stompId >= 6?200+10*(stompId-6):0;
	//return false;
	for (int i=0;i<AllStompsCount;i++) {
		int tmpId = pgm_read_word_near(&AllStomps[i].type);
		if (tmpId == id + indexOffset) {
			const PGM_StompInfo *src = &AllStomps[i];
			dst->PGM_index = i;
			dst->type = pgm_read_word_near(&src->type);
			memcpy_P(&dst->color, &src->color, sizeof(src->color));
			strcpy_P(dst->name, src->name);
			dst->paramCount = pgm_read_word_near(&src->paramCount);
			dst->isExpWah = pgm_read_byte_near(&src->isExpWah);
			dst->isExpPitch = pgm_read_byte_near(&src->isExpPitch);
			return true;
		}
	}
	return false;
}
Ejemplo n.º 27
0
/**
   Feuerwerk-Effekt
*/
void Effects::showFireWork(byte posX, eColors color) {
  word matrix [16];

  for (byte i = 9; i >= 3; i--) {
    renderer.clearScreenBuffer(matrix);
    ledDriver.setPixelInScreenBuffer(posX, i, matrix);
    writeToBuffer(matrix, 7, color);
  }

  for (byte i = 0; i <= 2; i++) {
    renderer.clearScreenBuffer(matrix);
    for (byte j = 0; j < 10; j++) {
      matrix[j] |= (pgm_read_word_near(&(effectMasksFireWork[i][j])) << (10 - posX)) & 0b1111111111100000;
    }
    writeToBuffer(matrix, 3 + round(10 * i / 3), color);
  }
  for (byte i = 0; i <= 10; i++) {
    renderer.clearScreenBuffer(matrix);
    for (byte j = 0; j < 10 - i; j++) {
      matrix[j + i] |= (pgm_read_word_near(&(effectMasksFireWork[3 + i % 3][j])) << (10 - posX)) & 0b1111111111100000;
    }
    writeToBuffer(matrix, 20, color);
  }
}
Ejemplo n.º 28
0
/**
   Pulsierender Herz-Effekt
*/
void Effects::showHeart(byte duration, eColors color) {
  word matrix [16];
  for (byte y = 0; y < 3; y++) {
    renderer.clearScreenBuffer(matrix);
    for (byte j = 0; j < 8; j++) {
      matrix[1 + j] |= (pgm_read_word_near(&(effectMasksHeart[0][j])) << 5);
    }
    writeToBuffer(matrix, 11 * duration, color);
    for (byte i = 0; i < 2; i++) {
      renderer.clearScreenBuffer(matrix);
      for (byte z = 0; z < 2; z++) {
        for (byte j = 0; j < 8; j++) {
          matrix[1 + j] |= (pgm_read_word_near(&(effectMasksHeart[z][j])) << 5);
        }
        writeToBuffer(matrix, 4 * duration, color);
      }
    }
  }
  renderer.clearScreenBuffer(matrix);
  for (byte j = 0; j < 8; j++) {
    matrix[1 + j] |= (pgm_read_word_near(&(effectMasksHeart[0][j])) << 5);
  }
  writeToBuffer(matrix, 14 * duration, color);
}
Ejemplo n.º 29
0
bool KEMPER_NAMESPACE::updateStompParameterValue(PartialParameter *parameter, int value) {
	if (parameter->totalOptionCount>0) {
		PGM_KemperParam** params = (PGM_KemperParam**)pgm_read_word_near(&AllStomps[parameter->stompInfo->PGM_index].params);
		PGM_KemperParam *param = (PGM_KemperParam*) pgm_read_word_near(&params[parameter->currentParam]);
		KemperParamOption** options = (KemperParamOption**)pgm_read_word_near(&param->options);
		for (int i=0;i<parameter->totalOptionCount && options;i++) {
			KemperParamOption* option = (KemperParamOption*)pgm_read_word_near(&options[i]);
			int val = pgm_read_word_near(&option->value);
			if (val == value) {
				if (parameter->currentOption != i) {
					parameter->currentOption = i;
					return true;
				}
				return false;
			}
		}
	} else {
		if (parameter->currentValue!=value) {
			parameter->currentValue = value;
			return true;
		}
	}
	return false; 
}
const uint8_t* SmallFont::getChar(unsigned char letter) {
  const uint8_t* character;
  if (letter==' ') return (uint8_t*) 3;
//  #ifndef LOWERCASE
  if (letter>=97 && letter<=122){
    letter = letter-32;
  }
//  #endif
  if (letter<fontMin || letter>fontMax) {
    return NULL;
  }

  character = (const uint8_t *)pgm_read_word_near(&normalFont[letter-fontMin]);
  return character;
}