void lcd_material_reset_defaults()
{
    //Fill in the defaults
    char buffer[8];

    strcpy_P(buffer, PSTR("PLA"));
    eeprom_write_block(buffer, EEPROM_MATERIAL_NAME_OFFSET(0), 4);
    eeprom_write_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(0), 210);
//    eeprom_write_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(0), 60);
    eeprom_write_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(0), 100);
    eeprom_write_word(EEPROM_MATERIAL_FLOW_OFFSET(0), 100);
    eeprom_write_float(EEPROM_MATERIAL_DIAMETER_OFFSET(0), 2.85);

    strcpy_P(buffer, PSTR("ABS"));
    eeprom_write_block(buffer, EEPROM_MATERIAL_NAME_OFFSET(1), 4);
    eeprom_write_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(1), 260);
//    eeprom_write_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(1), 90);
    eeprom_write_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(1), 50);
    eeprom_write_word(EEPROM_MATERIAL_FLOW_OFFSET(1), 107);
    eeprom_write_float(EEPROM_MATERIAL_DIAMETER_OFFSET(1), 2.85);

    strcpy_P(buffer, PSTR("UPET"));
    eeprom_write_block(buffer, EEPROM_MATERIAL_NAME_OFFSET(2), 5);
    eeprom_write_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(2), 250);
//    eeprom_write_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(2), 60);
    eeprom_write_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(2), 50);
    eeprom_write_word(EEPROM_MATERIAL_FLOW_OFFSET(2), 100);
    eeprom_write_float(EEPROM_MATERIAL_DIAMETER_OFFSET(2), 2.85);

    eeprom_write_byte(EEPROM_MATERIAL_COUNT_OFFSET(), 3);
}
Example #2
0
void AlgorithmRepository::writeToEEPROM()
{
#ifndef DEBUGGING

#ifdef ENABLE_DEBUG_UART
	Comm::printf_P( PSTR("Store in EEPROM"));
#endif
	WORD addr= 0;
	eeprom_write_byte( (uint8_t *)addr++, 'J' );
	eeprom_write_byte( (uint8_t *)addr++, 'P' );
	eeprom_write_byte( (uint8_t *)addr++, ((RECEIVER_CHANNELS << 5) | OUTPUT_CHANNELS) );

	eeprom_write_block( (const void *)&programArray, (void *)addr, (size_t)sizeof( programArray ) );
	addr += sizeof( programArray );
	eeprom_write_block( (const void *)&inputChannel, (void *)addr, (size_t)sizeof( inputChannel ) );
	addr += sizeof( inputChannel );

	for( BYTE i = 0; i < RECEIVER_CHANNELS; i++)
	{
		eeprom_write_word( (uint16_t *)addr, Receiver::getChannelMin( i ));
		addr += sizeof( WORD );
		eeprom_write_word( (uint16_t *)addr, Receiver::getChannelMax( i ));
		addr += sizeof( WORD );
	}

	eeprom_write_byte( (uint8_t *) addr, Receiver::getChannelModeByte( ));
  addr++;
  eeprom_write_word((uint16_t *) addr, Adc::getLimit());
 #endif
}
Example #3
0
inline void SaveSettings ()
{
	/*
	RegulationSettingsExtract te,he;
	te = regSettingsTemp.GetExtract();
	he = regSettingsHum.GetExtract();
	
	// EEPROM is not valid, make it valid
	uint8_t isInvalid = (eeprom_read_byte(&EEvalid) != EEvalidValue);
	
	RegulationSettingsExtract t,h;
	eeprom_read_block(&t, &EeTempConfig, sizeof(RegulationSettingsExtract));
	eeprom_read_block(&h, &EeHumConfig, sizeof(RegulationSettingsExtract));
	
	if(isInvalid || !te.Equals(&t))
	{
	eeprom_write_block(&te, &EeTempConfig, sizeof(RegulationSettingsExtract));
	}
	
	if (isInvalid || !he.Equals(&h))
	{
	eeprom_write_block(&he, &EeHumConfig, sizeof(RegulationSettingsExtract));
	}
	
	if (isInvalid)
	{
	eeprom_write_byte(&EEvalid, EEvalidValue);
	}*/
	
	eeprom_write_block(&regSettingsTemp, &EeTempConfig, sizeof(RegulationSettings));
	eeprom_write_block(&regSettingsHum, &EeHumConfig, sizeof(RegulationSettings));
	eeprom_write_byte(&EEvalid, EEvalidValue);
}
Example #4
0
uint8_t battery_read() // Returns 0-100 //
{
  uint16_t raw = battery_read_raw();
  uint16_t high, low, percent;
  char status = battery_status();

  if(status == 0)
  {
    eeprom_read_block((void *) &low, &battery_low, sizeof(uint16_t));
    if(raw < low) eeprom_write_block((const void *) &raw, &battery_low, sizeof(uint16_t));
    eeprom_read_block((void *) &high, &battery_high, sizeof(uint16_t));
    if(high == 0xFFFF) high = 0;
    if(raw > high) eeprom_write_block((const void *) &raw, &battery_high, sizeof(uint16_t));
    percent = ((raw - low) * 100) / (high - low);
  }
  else
  {
    eeprom_read_block((void *) &low, &battery_low_charging, sizeof(uint16_t));
    if(raw < low) eeprom_write_block((const void *) &raw, &battery_low, sizeof(uint16_t));
    eeprom_read_block((void *) &high, &battery_high_charging, sizeof(uint16_t));
    if(raw > high) eeprom_write_block((const void *) &raw, &battery_high, sizeof(uint16_t));
    percent = ((raw - low) * 100) / (high - low);
    if(status == 1 && percent > 99) percent = 99;
    if(status == 2) percent = 100;
  }

  return percent;
}
Example #5
0
void write_user_settings_to_eeprom() {
    int magicnumber=MAGICNUMBER;
    int size=sizeof(settingsstruct);
   
    eeprom_write_block((const void*)&magicnumber, (void*)0, sizeof(magicnumber));
    eeprom_write_block((const void*)&size, (void*)2, sizeof(size));
    eeprom_write_block((const void*)&settings, (void*)4, size);
}
Example #6
0
void EepromWriteConfig(void * baseadr, void * buf, uint8_t len)
{
  struct netCheckSum_t checksum;
  eeprom_write_block(buf, baseadr, len);

  checksum.positive = calculateCheckSum(buf, len);
  checksum.negative = ~checksum.positive;
  eeprom_write_block(&checksum, baseadr+len, sizeof(checksum));
}
Example #7
0
void cfg_save()
{
  eeprom_busy_wait();
  eeprom_write_byte((uint8_t *)EEPROM_MAGIC_ADDR, EEPROM_MAGIC);
  eeprom_busy_wait();
  eeprom_write_block(profile1, (void *)EEPROM_PROF1_ADDR, TC_NUM_PARAMS);
  eeprom_busy_wait();
  eeprom_write_block(profile2, (void *)EEPROM_PROF2_ADDR, TC_NUM_PARAMS);
}
Example #8
0
void store_in_eeprom(void)
{
	eeprom_write_byte((uint8_t *)0x0,19); // magic number
	eeprom_write_block((uint8_t *)myip,(void *)1,sizeof(myip));
	eeprom_write_block((uint8_t *)monitoredhost,(void *)6,sizeof(monitoredhost));
	eeprom_write_byte((uint8_t *)11,pinginterval);
	eeprom_write_byte((uint8_t *)12,sendping);
	password[7]='\0'; // make sure it is terminated, should not be necessary
	eeprom_write_block((char *)password,(void *)13,sizeof(password));
}
Example #9
0
void writeusersettingstoeeprom(void)
{
    uint16_t magicnumber = MAGICNUMBER;
    int size = sizeof(usersettingsstruct);

    eeprom_write_block((const void *)&magicnumber, 0, sizeof(magicnumber));
    eeprom_write_block((const void *)&size, 2, sizeof(size));
    eeprom_write_block((const void *)&usersettings, 4, size);
    eeprom_commit();
}
Example #10
0
//*******************************************************************************************
//
// Function : key_dw_process
// Description : 
//
//*******************************************************************************************
void key_dw_process ( void )
{
	BYTE temp;
	
	// standby display, display board status
	if(menu_index == 0)
	{
		if(standby_cursor==1){
			turn_devices(ind_device_cur);
			return;
		}
		if ( -- standby_cursor == 0 )
			standby_cursor = sizeof(standby_list)/2;
		flag1.bits.update_display = 1;
	}
	// main menu
	else if(menu_index == 1)
	{
		if( --submenu_index == 0 )
		{
			submenu_index = (sizeof(menu_list)/2)-1;
		}
	}
	// setup avr ip
	else if( menu_index == 2 )
	{
		avr_ip.byte [ setting_cursor ]--;
		eeprom_write_block ( &avr_ip, ee_avr_ip, 4 );
	}
	// setup server ip
	else if( menu_index == 3 )
	{
		server_ip.byte [ setting_cursor ]--;
		eeprom_write_block ( &server_ip, ee_server_ip, 4 );
	}
	// setup countdown timer
	else if( menu_index == 4 )
	{
		temp = pgm_read_byte ( (PGM_P)(count_time_max + setting_cursor) );
		if ( --count_time [ setting_cursor ] == 0xff )
			count_time [ setting_cursor ] = temp;
		eeprom_write_block ( count_time, ee_count_time, 4 );
	}else if(menu_index == 6){
		if(screen_timeout == 0){
			screen_timeout=240;
		}else{
			screen_timeout--;
		}
		timeout_cur_screen=screen_timeout;
		
		
	}
}
void data2eeprom(void)
{
	eeprom_write_byte((uint8_t *)40,19); // magic number
	eeprom_write_block((uint8_t *)gwip,(void *)41,sizeof(gwip));
	eeprom_write_block((uint8_t *)udpsrvip,(void *)45,sizeof(udpsrvip));
	eeprom_write_word((void *)49,udpsrvport);
	eeprom_write_byte((uint8_t *)51,alarmOn);
	eeprom_write_word((void *)52,heartbeat_timeout_sec);
	eeprom_write_byte((uint8_t *)54,dhcpOn);
	eeprom_write_block((uint8_t *)myip,(void *)55,sizeof(myip));
	eeprom_write_block((uint8_t *)myname,(void *)59,sizeof(myname));	
}
Example #12
0
//*******************************************************************************************
//
// Function : key_up_process
// Description : 
//
//*******************************************************************************************
void key_up_process ( void )
{
	BYTE temp;
	
	// standby display, display board status
	if(menu_index == 0)
	{
		if(standby_cursor==1){
			if(++ind_device_cur !=6){
				return;
			}else{
				ind_device_cur=0;
			}
		}
		if ( ++ standby_cursor == ((sizeof(standby_list)/2)+1) )
			standby_cursor = 1;
		flag1.bits.update_display = 1;
	}
	// main menu
	else if(menu_index == 1)
	{
		if( ++submenu_index == (sizeof(menu_list)/2) )
		{
			submenu_index = 1;
		}
	}
	// setup avr ip
	else if( menu_index == 2 )
	{
		avr_ip.byte [ setting_cursor ]++;
		eeprom_write_block ( &avr_ip, ee_avr_ip, 4 );
	}
	// setup server ip
	else if( menu_index == 3 )
	{
		server_ip.byte [ setting_cursor ]++;
		eeprom_write_block ( &server_ip, ee_server_ip, 4 );
	}
	// setup countdown timer
	else if( menu_index == 4 )
	{
		temp = pgm_read_byte ( (PGM_P)(count_time_max + setting_cursor) );
		if ( ++count_time [ setting_cursor ] == temp )
			count_time [ setting_cursor ] = 0;
		eeprom_write_block ( count_time, ee_count_time, 4 );
	}else if(menu_index == 6){
		screen_timeout++;
		if(screen_timeout > 240){
			screen_timeout=0;
		}
		timeout_cur_screen=screen_timeout;
	}
}
Example #13
0
int apply_power(void){
	if(unlock_stage>0){
		RED_ON;
	}
	if(unlock_stage==3){ //unlock finished
		power_mode = MODE_IDLE;
		unlock_stage = 0;
	}
	if(power_mode==255){power_mode=MODE_IDLE;}
	if(power_mode>MODE_FULL){power_mode=MODE_FULL;}

	if(power_mode==MODE_OFF){
		DRIVER_OFF;
		OCR0B=0;
	}else{
		DRIVER_ON;
		set_sleep_mode(SLEEP_MODE_IDLE);
		sleep_disable();
		// stop_timer();
		start_timer();
	}
	// if(power_mode==MODE_IDLE)		{OCR0B=0;  }
	// if(power_mode==MODE_LOW_VOLTAGE){OCR0B=0; }
	// if(power_mode==MODE_OVERTEMP)	{OCR0B=0;  }
	// if(power_mode==MODE_LOW)		{OCR0B=16; }
	// if(power_mode==MODE_HALF)		{OCR0B=0;}
	// if(power_mode==MODE_FULL)		{OCR0B=0;}
	if(power_mode==MODE_IDLE)		{OCR0B=0;  }
	if(power_mode==MODE_LOW_VOLTAGE){OCR0B=16; }
	if(power_mode==MODE_OVERTEMP)	{OCR0B=8;  }
	if(power_mode==MODE_LOW)		{OCR0B=64; }
	if(power_mode==MODE_HALF)		{OCR0B=127;}
	if(power_mode==MODE_FULL)		{OCR0B=255;}

	if(prev_power_mode!=power_mode){
		seconds_on[prev_power_mode] += seconds;
		times_on[prev_power_mode] += 1;
		if(max_on[prev_power_mode] < seconds){
			max_on[prev_power_mode] = seconds;
		}
		if(power_mode==MODE_LOW_VOLTAGE||power_mode==MODE_OFF){
			//will store data only on power off or low batt to save eeprom
			eeprom_write_block(&seconds_on, &nv_seconds_on, sizeof(seconds_on));
			eeprom_write_block(&times_on,   &nv_times_on,   sizeof(times_on) );
			eeprom_write_block(&max_on,     &nv_max_on,     sizeof(max_on)   );
		}
		prev_power_mode=power_mode;
		seconds=0;
	}

	return 0;
}
void settings_save()
{
    if(conf.camera.cameraMake == PANASONIC) conf.camera.halfPress = HALF_PRESS_DISABLED;
    if(settings_camera_index > 0)
    {
        eeprom_write_block((const void*)&conf.camera, &camera_settings_eep[settings_camera_index - 1], sizeof(camera_settings_t));
        eeprom_read_block((void*)&conf.camera, &conf_eep.camera, sizeof(camera_settings_t));
    }
    conf.camera.autoConfigured = 0;
    eeprom_write_block((const void*)&conf, &conf_eep, sizeof(settings_t));
    lcd.init(conf.lcdContrast);
    lcd.update();
}
Example #15
0
void TLE_Handler_SetNewTLE(char * l0, char * l1, char * l2)
{
	if (l0 && l1 && l2)
	{
		strncpy(line0, l0, TLE_TITLE_LENGTH);
		strncpy(line1, l1, TLE_LINE_LENGTH);
		strncpy(line2, l2, TLE_LINE_LENGTH);
		
		eeprom_write_block(line0, eeprom_line0, TLE_TITLE_LENGTH);
		eeprom_write_block(line1, eeprom_line1, TLE_LINE_LENGTH);
		eeprom_write_block(line2, eeprom_line2, TLE_LINE_LENGTH);
		
		updateTLEData();
	}
}
Example #16
0
void
run_graph (void)
{
	static uint32_t lastsec = 0, lastmin = 0, lasthour = 0, lastday = 0;
	static int32_t pLastMin = 0, pLastHour = 0, pLastDay = 0;
	static uint8_t mincount = 0;


	// see if a second has passed, if so add power into minute accumulator
	if (uptime() >= lastsec + 1)
	{
		pLastMin += gPower;
		lastsec = uptime();
	}

	// see if a minute has passed, if so advance the pointer to track the last 60 minutes
	if (uptime() >= lastmin + 60)
	{
		pLastHour += pLastMin / 60;
		if (++mincount >= 3)
		{
			median_add(&PowerMins, (int16_t)(pLastMin / 60));
			mincount = 0;
		}
		pLastMin = 0;
		lastmin = uptime();
	}

	// see if an hour has passed, if so advance the pointer to track the last 20 of them
	if (uptime() >= lasthour + 3600)
	{
		pLastDay += pLastHour / 60;
		median_add(&PowerHours, (int16_t)(pLastHour / 60));
		eeprom_write_block ((const void *) &PowerHours, (void *) &eePowerHours, sizeof (PowerHours));
		pLastHour = 0;
		lasthour = uptime();
	}

	// see if a day has passed, if so advance the pointer to track the last 20 days
	if (uptime() >= lastday + 86400)
	{
		// track daily totals in watt-hours
		median_add(&PowerDays, (int16_t)pLastDay);
		eeprom_write_block ((const void *) &PowerDays, (void *) &eePowerDays, sizeof (PowerDays));
		pLastDay = 0;
		lastday = uptime();
	}
}
Example #17
0
/**
 * \brief Saves the random seed to EEPROM.
 *
 * During system startup, noise sources typically won't have accumulated
 * much entropy.  But startup is usually the time when the system most
 * needs to generate random data for session keys, IV's, and the like.
 *
 * The purpose of this function is to pass some of the accumulated entropy
 * from one session to the next after a loss of power.  Thus, once the system
 * has been running for a while it will get progressively better at generating
 * random values and the accumulated entropy will not be completely lost.
 *
 * Normally it isn't necessary to call save() directly.  The loop() function
 * will automatically save the seed on a periodic basis (default of 1 hour).
 *
 * The seed that is saved is generated in such a way that it cannot be used
 * to predict random values that were generated previously or subsequently
 * in the current session.  So a compromise of the EEPROM contents of a
 * captured device should not result in compromise of random values
 * that have already been generated.  However, if power is lost and the
 * system restarted, then there will be a short period of time where the
 * random state will be predictable from the seed.  For this reason it is
 * very important to stir() in new noise data at startup.
 *
 * \sa loop(), stir()
 */
void RNGClass::save()
{
    // Generate random data from the current state and save
    // that as the seed.  Then force a rekey.
    ++(block[12]);
    ChaCha::hashCore(stream, block, RNG_ROUNDS);
#if defined(RNG_EEPROM)
    // We shorten the seed from 48 bytes to 47 to leave room for
    // the CRC-8 value.  We do this to align the data on an 8-byte
    // boundary in EERPOM.
    int address = RNG_EEPROM_ADDRESS;
    eeprom_write_block(stream, (void *)address, SEED_SIZE - 1);
    eeprom_write_byte((uint8_t *)(address + SEED_SIZE - 1),
                      crypto_crc8('S', stream, SEED_SIZE - 1));
#elif defined(RNG_DUE_TRNG)
    unsigned posn;
    ((uint32_t *)(RNG_SEED_ADDR))[0] = crypto_crc8('S', stream, SEED_SIZE);
    for (posn = 0; posn < 12; ++posn)
        ((uint32_t *)(RNG_SEED_ADDR))[posn + 1] = stream[posn];
    for (posn = 13; posn < (RNG_FLASH_PAGE_SIZE / 4); ++posn)
        ((uint32_t *)(RNG_SEED_ADDR))[posn + 13] = 0xFFFFFFFF;
    eraseAndWriteSeed();
#elif defined(RNG_ESP_NVS)
    // Save the seed into ESP non-volatile storage (NVS).
    nvs_handle handle = 0;
    if (nvs_open("rng", NVS_READWRITE, &handle) == 0) {
        nvs_erase_all(handle);
        nvs_set_blob(handle, "seed", stream, SEED_SIZE);
        nvs_commit(handle);
        nvs_close(handle);
    }
#endif
    rekey();
    timer = millis();
}
Example #18
0
void clear_events()
{
	events_count = 0;
	
	// clear all data
	for (int i = 0; i < EVENTS_SIZE; i++)
	{
		events[i].pin = -1;
		events[i].time = 0;
		events[i].pin_state = 0;
		events[i].inc = 0;
		events[i].duration = 0;
		events[i].type = 0;
		
	}
	
	// save event to eeprom
	eeprom_busy_wait();
	eeprom_write_block(&events, &events_ee, sizeof(struct Event) * EVENTS_SIZE);
	
	// save count
	eeprom_busy_wait();
	eeprom_write_byte(&events_count_ee, events_count);
	
	event_mode = MANUAL_MODE;
}
Example #19
0
void add_event(int pin, int32_t time, int pin_state)
{
	// don't add if no space
	if (events_count >= EVENTS_SIZE - 1)
	return;
	
	events[events_count].pin = pin;
	events[events_count].time = time;
	events[events_count].pin_state = pin_state;
	
	if (pin_state > 1)
	events[events_count].type = PWM;
	else
	events[events_count].type = EXP;
	
	events_count++;
	
	// save event to eeprom
	eeprom_busy_wait();
	eeprom_write_block(&events, &events_ee, sizeof(struct Event) * EVENTS_SIZE);
	
	// save count
	eeprom_busy_wait();
	eeprom_write_byte(&events_count_ee, events_count);
}
Example #20
0
void store_side_state(uint8_t *side_state_src, uint8_t bank_num)
{
    // Calculate the address of the side state being writen
    uint8_t *bank_state_address = STATE_STORAGE_START_ADDRESS + bank_num * STATE_BANK_LEN;

    eeprom_write_block((const void*) side_state_src, (void*) bank_state_address, STATE_BANK_LEN);
}
Example #21
0
void writeGlobalSet(uint8_t b) {
  global_conf.checksum = calculate_sum((uint8_t*)&global_conf, sizeof(global_conf));
  eeprom_write_block((const void*)&global_conf, (void*)0, sizeof(global_conf));
  if (b == 1) blinkLED(15,20,1);
  SET_ALARM_BUZZER(ALRM_FAC_CONFIRM, ALRM_LVL_CONFIRM_1);

}
Example #22
0
//write data on eeprom
int8_t CfgCmd(char *inbuffer)
{
	int adresa = 18;
	//char *scriu;
	char comanda[7];
	int8_t i;

	for (i = 0; i < 20; ++i)
	{
		strcpy_P(comanda, (char*) pgm_read_word(&(comenzi[i]))); // Necessary casts and dereferencing, just copy.
		if (strstr(inbuffer, comanda) != 0)
		{

			inbuffer += strlen(comanda) + 1;
			adresa = 18 * (2 + i);
//#if DEBUG
			//Serial.print("Scriu la adresa ");
			Serial.print(adresa);
			//Serial.print(": ");
			Serial.println(inbuffer);
//#endif
			eeprom_write_block(inbuffer, (int*) adresa, 18);
			//EEPROM.updateBlock(inbuffer, adresa, 18);
			return 1;
		}
	}
	return 0;
}
Example #23
0
void writeParams(uint8_t b) {
  global_conf.currentSet=0;
  conf.checksum = calculate_sum((uint8_t*)&conf, sizeof(conf));
  eeprom_write_block((const void*)&conf, (void*)(global_conf.currentSet * sizeof(conf) + sizeof(global_conf)), sizeof(conf));
  readEEPROM();
  if (b == 1) blinkLED(15,20,1);
}
Example #24
0
bool 
OWI::Driver::update_rom()
{
  if (ROM == NULL) return (false);
  eeprom_write_block(ROM, m_rom, sizeof(m_rom));
  return (true);
}
Example #25
0
// Save the variable to EEPROM, if supported
//
bool AP_Var::save(void)
{
    uint8_t vbuf[k_size_max];
    size_t size;

    // if the variable is a group member, save the group
    if (_group) {
        return _group->save();
    }

    debug("save: %S", _name ? _name : PSTR("??"));

    // locate the variable in EEPROM, allocating space as required
    if (!_EEPROM_locate(true)) {
        debug("locate failed");
        return false;
    }

    // serialize the variable into the buffer and work out how big it is
    size = serialize(vbuf, sizeof(vbuf));
    if (0 == size) {
        // variable cannot be serialised into the buffer
        debug("cannot save (too big or not supported)");
        return false;
    }

    // if it fit in the buffer, save it to EEPROM
    if (size <= sizeof(vbuf)) {
        debug("saving %u to %u", size, _key);
        eeprom_write_block(vbuf, (void *)_key, size);
        return true;
    }
    return false;
}
Example #26
0
// This routine is called by usbFunctionWrite every time the keyboard LEDs
// toggle - basically we count 4 toggles and then start regenerating
void caps_toggle() {
    if(capsState == CAPS_COUNTING) {    
        if(capsCount++ < 4)
            return;
        
        capsCount = 0;
        capsState = CAPS_MEASURING;

        // Type a message to the PC that we're regenerating the password
        memcpy_P(messageBuffer, measuring_message, sizeof(measuring_message));
        messagePtr = 0;
        messageState = STATE_SEND;
    } else {
        messageBuffer[capsCount++] = generate_character();
        
        if(capsCount >= PASS_LENGTH) { // enough characters generated
#if SEND_ENTER
            messageBuffer[capsCount++] = '\n';
#endif
            messageBuffer[capsCount] = '\0';
            
            // Store password to EEPROM - might lose the USB connection, but so what
            eeprom_write_block(messageBuffer, stored_password, sizeof(messageBuffer));
            
            // Type a message to the PC that new password has been generated
            memcpy_P(messageBuffer, finish_message, sizeof(finish_message));
            messagePtr = 0;
            messageState = STATE_SEND;
            
            capsCount = 0;
            capsState = CAPS_COUNTING;
        }
    }    
}
Example #27
0
void ApplicationSettings::saveToFlash(){
  eeprom_unlock();
  //   if(eeprom_erase(APPLICATION_SETTINGS_ADDR) == 0)
  eeprom_erase_sector(APPLICATION_SETTINGS_SECTOR);
  eeprom_write_block(APPLICATION_SETTINGS_ADDR, this, sizeof(*this));
  eeprom_lock();
}
Example #28
0
void SMDLEDShield::message(const char *_text, bool store) {
  int i, j;
  int temp;
  //save a private copy of the text string
  strcpy(text, _text);
  //save to eeprom
  if (store)
    eeprom_write_block(text, _store, strlen(text)+1);
  buffer_width = strlen(_text)*4 + 16;
  memset(buffer,0,128*8);
  //Preprocess the message into font indeces
  for(i=0; i< strlen(text); i++) {
    if((64 < text[i])  && (text[i] < 91))//upper case
      temp = text[i] - 65;
    else if((96 < text[i]) && (text[i] < 123))//lower case
      temp = text[i] - 97;
    else //unmapped
      temp = -1;
    //Render the buffer
    for(j=0; j<8; j++) {
      buffer[j][(i/2)+1] |= (temp > -1)?pgm_read_byte(&(charset[(int)temp][j])) << 4*(i%2):0;
    }
  }
  
  left_bit = 0;
  //Render the initial window buffer
  renderWindow();
}
Example #29
0
//write data on eeprom
int CfgCmd(char *inbuffer)
{
	int adresa = 18;
	//char *scriu;
	char comanda[7];

	for (int8_t i = 0; i < 19; ++i)
	{
		strcpy_P(comanda, (char*) pgm_read_word(&(comenzi[i]))); // Necessary casts and dereferencing, just copy.
		if (strstr(inbuffer, comanda) != 0)
		{

			inbuffer += strlen(comanda) + 1;
			adresa = 18 * (2 + i);
#if DEBUG
			//Serial.print("Scriu la adresa ");
			UWriteInt(adresa);
			UWriteString(": ");
			UWriteString(inbuffer);
			UWriteData(0x0D);
			UWriteData(0x0A);
#endif
			eeprom_write_block(inbuffer, (int*) adresa, 18);
			return adresa;
		}
	}
	return 0;
}
void lcd_material_reset_defaults()
{
    //Fill in the defaults
    SERIAL_ECHO_START;
    SERIAL_ECHOLNPGM("Materials reset");
    char buffer[MATERIAL_NAME_LENGTH];
    for (int a= 0; a< MATERIAL_PRESETS; a++)
        {
            strncpy_P(buffer, (char PROGMEM *) presets[a].name,MATERIAL_NAME_LENGTH);		// this will pad out the whole length with 0 as needed.
            eeprom_write_block(buffer                                  , EEPROM_MATERIAL_NAME_OFFSET(a), MATERIAL_NAME_LENGTH);
            material_preset temp;
            memcpy_P((void*) &temp,&presets[a],sizeof (material_preset));
            eeprom_write_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(a)    ,temp.temperature);
            eeprom_write_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(a),temp.bed);
            eeprom_write_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(a)      ,temp.fan_speed);
            eeprom_write_word(EEPROM_MATERIAL_FLOW_OFFSET(a)           ,temp.flow);
            eeprom_write_float(EEPROM_MATERIAL_DIAMETER_OFFSET(a)      ,temp.diameter);
        }
    uint8_t e;
    for(e=0; e<EXTRUDERS; e++)
        {
            makeCustomName(e);
            strcpy(material_name[e],material_name_buf);
            lcd_material_store_current_material();
        }

    eeprom_write_byte(EEPROM_MATERIAL_COUNT_OFFSET(), MATERIAL_PRESETS);
    lcd_lib_beep_ext(500,150);
    lcd_lib_beep_ext(750,100);
}