/////////////////////////////////////////////////////////////////////////////// // write_app_register // void write_app_register( uint08_t reg, uint08_t val ) { SendMsg.priority = VSCP_PRIORITY_MEDIUM; SendMsg.vscp_class = VSCP_CLASS1_PROTOCOL; SendMsg.vscp_type = VSCP_TYPE_PROTOCOL_RW_RESPONSE; SendMsg.length = 2; SendMsg.data[0] = reg; SendMsg.data[1] = ~val; // error return switch ( reg ) { // Zone case 0x23: writeEEPROM( REG_APP_ZONE, val); SendMsg.data[1] = readEEPROM( REG_APP_ZONE); break; // SubZone case 0x24: writeEEPROM( REG_DOOR_SUBZONE, val); SendMsg.data[1] = readEEPROM( REG_DOOR_SUBZONE); break; default: SendMsg.data[1] = ~val; // error return break; } // Send data VSCP_enqMsgTx( &SendMsg, FALSE); }
void main(void) { byte evalue; initSquareWear(); setModeOutput(pinC7); latC7 = 0; delayMilliseconds(250); // short delay for EEPROM to stablize evalue = readEEPROM(0x0); // read EEPROM address 0 switch(evalue) { case 0: writeEEPROM(0x0, 1); // write next index to EEPROM address 0 busyEEPROM(); // wait till write completes while(1) { latC7 = !latC7; delayMilliseconds(100); } break; case 1: writeEEPROM(0x0, 2); busyEEPROM(); while(1) { latC7 = !latC7; delayMilliseconds(500); } break; default: writeEEPROM(0x0, 0); busyEEPROM(); while(1) { latC7 = !latC7; delayMilliseconds(1000); } break; } }
unsigned char savePassword(long g){ if(g>0){ processNumber(g); unsigned char ca=getFCell(); writeEEPROM(ca,num1); writeEEPROM((ca+1),num2); writeEEPROM((ca+2),num3); } return 1; }
//Initialise l'EEPROM avec des valeurs par défaut void initEEPROM() { //Charge les coeffs PID par défaut defaultPID(); //Charge les trims par défaut (consignes utilisées en mode failsafe également) defaultTrim(); //Angles à 0 memset(&anglesOffsets, 0, sizeof(IMU_ANGLES_VITESSES)); //Ecrit les données en EEPROM writeEEPROM (&coeffsPID, EEPROM_BASE, MAX_PID * sizeof(COEFFS_PID)); writeEEPROM (&telecommandeOffsets, EEPROM_BASE + EEPROM_OFFSET_TRIMS, sizeof(TELECOMMANDE_DATA)); writeEEPROM (&anglesOffsets, EEPROM_BASE + EEPROM_OFFSET_ANGLES, sizeof(IMU_ANGLES_VITESSES)); printf("->Initialisation EEPROM\n"); }
/* * Save the settings in EEPROM */ void Network::writeSettings() { int j = 1; j+= writeEEPROM(mac_oui, j, sizeof(mac_oui) * sizeof(uint8_t)); j+= writeEEPROM(mac, j, sizeof(mac) * sizeof(uint8_t)); j+= writeEEPROM(&use_dhcp, j, sizeof(bool)); j+= writeEEPROM(&ip, j); j+= writeEEPROM(&subnet, j); j+= writeEEPROM(&gateway, j); j+= writeEEPROM(&dns, j); j+= writeEEPROM(&httpPort, j, sizeof(httpPort)); j+= writeEEPROM(&websocketPort, j,sizeof(websocketPort)); }
/** @Brief 电位器\旋钮获取中值 * @ 多次采用取平均 * * @Note * 1) 调用此程序前,各电位器拨到中间位置 */ void stickKnobCalibrationMiddle(void) { uint32_t currentTime; uint8_t i, count; uint16_t adc; uint32_t adcSum[STICK_KNOB_SUM]; for(i=0; i<STICK_KNOB_SUM; i++) { adcSum[i] = 0; StickKnob[i].adcLimitMiddle = 2048; } count = 0; //1) 每20ms采样一次,1s后计算均值 currentTime = micros() + 300000; while((int32_t)(currentTime - micros()) >= 0) { for(i=0; i<STICK_KNOB_SUM; i++) { adc = adcGetChannel(StickKnob[i].adcChannel); adcSum[i] += adc; } count++; delay(20); LED0_TOGGLE; } for(i=0; i<STICK_KNOB_SUM; i++) { StickKnob[i].adcLimitMiddle = adcSum[i]/count; } //2) 保存至EEPROM for(i = 0; i < STICK_KNOB_SUM; i++) { cfg.adcLimitMiddle[i] = StickKnob[i].adcLimitMiddle; } writeEEPROM(1, 1); }
void changeProfile(uint8_t profileIndex) { masterConfig.current_profile_index = profileIndex; writeEEPROM(); readEEPROM(); beeperConfirmationBeeps(profileIndex + 1); }
static void cliSave(char *cmdline) { cliPrint("Saving..."); copyCurrentProfileToProfileSlot(masterConfig.current_profile_index); writeEEPROM(); cliReboot(); }
//Function that control the specific brightness of the led conected to specific pwmpin. //the structure of the command is pwmpin:brightness int controlPWM(String command) { int index=command.indexOf(":"); String pwmpin=command.substring(0,index); String val=command.substring(index+1); int pin=pwmpin.toInt(); int value=val.toInt(); if (value<256&&value>=0){ analogWrite(pin,value); if (pin==10){ EEPROMData.outputData.pwmoutput[2].pin=pin; EEPROMData.outputData.pwmoutput[2].value=value; } else if (pin==11){ EEPROMData.outputData.pwmoutput[3].pin=pin; EEPROMData.outputData.pwmoutput[3].value=value; } else if (pin>13&&pin<18){ EEPROMData.outputData.pwmoutput[pin-10].pin=pin; EEPROMData.outputData.pwmoutput[pin-10].value=value; } else if (pin<2){ EEPROMData.outputData.pwmoutput[pin].pin=pin; EEPROMData.outputData.pwmoutput[pin].value=value; } writeEEPROM(); return value; } else{ return -1;// return -1 if the pin sended on the command is not the PWM output ones } }
void osdHardwareInit(void) { LED0_ON; delay(500); max7456_hardwareReset(); LED0_OFF; osdHardwareApplyConfiguration(osdVideoConfig()->videoMode); max7456_extiConfigure(&max7456LOSExtiConfig, &max7456VSYNCExtiConfig, &max7456HSYNCExtiConfig); if (osdFontConfig()->fontVersion != FONT_VERSION) { // before max7456_showFont(); delay(5000); // give the user a chance to power off before changing max7456_resetFont(); // after max7456_showFont(); delay(5000); // give the user a chance to power off after changing osdFontConfig()->fontVersion = FONT_VERSION; writeEEPROM(); max7456_clearScreen(); max7456_ensureDisplayClearIsComplete(); } }
void changeProfile(uint8_t profileIndex) { masterConfig.current_profile_index = profileIndex; writeEEPROM(); readEEPROM(); blinkLedAndSoundBeeper(2, 40, profileIndex + 1); }
/////////////////////////////////////////////////////////////////////////////// // setVSCPControlByte // void vscp_setControlByte( uint08_t ctrl ) { if (GetResource(RESOURCE_EE_ID) == E_OK) { writeEEPROM( VSCP_EEPROM_CONTROL, ctrl ); ReleaseResource(RESOURCE_EE_ID); } }
/////////////////////////////////////////////////////////////////////////////// // setSegmentCRC // void vscp_setSegmentCRC( uint08_t crc ) { if (GetResource(RESOURCE_EE_ID) == E_OK) { writeEEPROM( VSCP_EEPROM_SEGMENT_CRC, crc ); ReleaseResource(RESOURCE_EE_ID); } }
/////////////////////////////////////////////////////////////////////////////// // setVSCPManufacturerId // // Set Manufacturer id and subid to EEPROM // void vscp_setManufacturerId( uint08_t idx, uint08_t data ) { if (GetResource(RESOURCE_EE_ID) == E_OK) { writeEEPROM( VSCP_EEPROM_REG_MANUFACTUR_ID0 + idx, data ); ReleaseResource(RESOURCE_EE_ID); } }
/////////////////////////////////////////////////////////////////////////////// // setNickname // void vscp_setNickname( uint08_t nickname ) { if (GetResource(RESOURCE_EE_ID) == E_OK) { writeEEPROM( VSCP_EEPROM_NICKNAME, nickname ); ReleaseResource(RESOURCE_EE_ID); } }
static void cliSave(char *cmdline) { cliPrint("Saving..."); writeEEPROM(0, true); cliPrint("\r\nRebooting..."); delay(10); systemReset(false); }
/////////////////////////////////////////////////////////////////////////////// // setVSCPUserID // void vscp_setUserID( uint08_t idx, uint08_t data ) { if (GetResource(RESOURCE_EE_ID) == E_OK) { writeEEPROM( idx + VSCP_EEPROM_REG_USERID, data ); ReleaseResource(RESOURCE_EE_ID); } }
/** * @brief Deauthorise all tags by clearing the EEPROM memory * Warning: This is slow at 9600 baud * * @returns True if commands could be sent to device */ bool RWDH2::deauthoriseAllTags() { uint8_t data[] = { 0x0, 0x0, 0x0, 0x0 }; for (uint8_t page = 0; page < 60; page++) { if (!writeEEPROM(12+4*page, data, 4)) { return false; } } return true; }
void vscp_goBootloaderMode( void ) { // OK, We should enter boot loader mode // First, activate bootloader mode writeEEPROM( VSCP_EEPROM_BOOTLOADER_FLAG, VSCP_BOOT_FLAG ); //_asm goto _startup reset _endasm _asm reset _endasm }
void checkFirstTime(bool reset) { // check the EEPROM integrity before resetting values if (!validEEPROM() || reset) { resetConf(); // no need to memcpy profile again, we just did it in resetConf() above writeEEPROM(0, false); } }
BOOL writeStrEEPROM(char addr, char length, char *str) { unsigned char i; for(i=0;i<length;i++) if(!writeEEPROM(addr+i, str[i])) return -1; return 1; }
void vscp_goBootloaderMode( uint8_t algo ) { writeEEPROM( VSCP_EEPROM_BOOTLOADER_FLAG, BTL_LOAD ); #ifdef PRINT_VSCP_EVENTS uart_puts( "\n #####jumping to bootloader!\n" ); #endif //reboot using WD cli(); wdt_enable(WDTO_1S); while(1); }
/******************************************************************** * Function: void ProcessMenu(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: This function parses the input string given * by the user. * * Note: None *******************************************************************/ void ProcessMenu(void) { int i; // Debug // If the line is empty return. if(RS232cp == 0) return; // Strip the CR/NL character. RS232_Out_Data[RS232cp] = '\0'; // Test different menu options if(strcmpram2pgm("help", RS232_Out_Data) == 0) putrsUSBUSART("\r\nAvailable commands:\r\n\r\n* help - Displays this message, recursive style!\r\n* setMessage <text> - Defines a new message to be displayed on the POV.\r\n* showMessage - Shows the current message\r\n* version - Displays firmware version."); else if(strncmpram2pgm("setMessage ", RS232_Out_Data, 10) == 0) { // Copy message strncpy(message, &RS232_Out_Data[11], MESSAGE_LENGTH); message[MESSAGE_LENGTH] = '\0'; writeEEPROM(0x00, crc(0x00, (char) strlen(message))); writeEEPROM(0x01, (char) strlen(message)); writeStrEEPROM(0x03, strlen(message), message); writeEEPROM(0x02, strcrc(message)); // Display confirmation strcpypgm2ram(RS232_Out_Data, "\r\nYour message is now defined as:\r\n\t"); strcat(RS232_Out_Data, message); putsUSBUSART(RS232_Out_Data); } else if(strcmpram2pgm("showMessage", RS232_Out_Data) == 0) { sprintf(RS232_Out_Data, "\r\nYour message is defined as:\r\n\t%s", message); putsUSBUSART(RS232_Out_Data); } else if(strcmpram2pgm("version", RS232_Out_Data) == 0) putrsUSBUSART("\r\nPOV serial configuration. Version 0.9"); else putrsUSBUSART("\r\nUnknown command. Type 'help' for the list of available commands."); clearRS232Buffer = 1; }
int Mag_getADC(void) { static uint32_t t, tCal = 0; static int16_t magZeroTempMin[3]; static int16_t magZeroTempMax[3]; uint32_t axis; if ((int32_t)(currentTime - t) < 0) return 0; //each read is spaced by 100ms t = currentTime + 100000; // Read mag sensor mag.read(magADC); if (f.CALIBRATE_MAG) { tCal = t; for (axis = 0; axis < 3; axis++) { mcfg.magZero[axis] = 0; magZeroTempMin[axis] = magADC[axis]; magZeroTempMax[axis] = magADC[axis]; } f.CALIBRATE_MAG = 0; } if (magInit) { // we apply offset only once mag calibration is done magADC[X] -= mcfg.magZero[X]; magADC[Y] -= mcfg.magZero[Y]; magADC[Z] -= mcfg.magZero[Z]; } if (tCal != 0) { if ((t - tCal) < 30000000) { // 30s: you have 30s to turn the multi in all directions LED0_TOGGLE; for (axis = 0; axis < 3; axis++) { if (magADC[axis] < magZeroTempMin[axis]) magZeroTempMin[axis] = magADC[axis]; if (magADC[axis] > magZeroTempMax[axis]) magZeroTempMax[axis] = magADC[axis]; } } else { tCal = 0; for (axis = 0; axis < 3; axis++) mcfg.magZero[axis] = (magZeroTempMin[axis] + magZeroTempMax[axis]) / 2; // Calculate offsets writeEEPROM(1, true); } } return 1; }
//Function for open/close pin //The structure of the receive command is pin: state where state is on or off int controlPin(String command) { int index=command.indexOf(":"); String pinout=command.substring(0,index); String state=command.substring(index+1); int pin=pinout.toInt(); if (state=="on") { digitalWrite(pin,HIGH); EEPROMData.outputData.digitalPin[pin]=1; writeEEPROM(); return 1; } else if (state=="off") { digitalWrite(pin,LOW); EEPROMData.outputData.digitalPin[pin]=0; writeEEPROM(); return 0; } else { //EEPROMData.eevar.state[pin]=-1; return -1;//return -1 if the command received has not the correct structure } }
unsigned char deletePassword(long number){ if(number>0){ processNumber(number); for(int i=0;i<1024;i++){ if(i%3==0){ unsigned char a=readEEPROM(i); if(a==num1){ unsigned char b=readEEPROM((i+1)); if(b==num2){ unsigned char c=readEEPROM((i+2)); if(c==num3){ writeEEPROM(i,0); writeEEPROM((i+1),0); writeEEPROM((i+2),0); return 1; } } } } i+=3; } } return 0; }
ISR(TIM1_COMPA_vect, ISR_NOBLOCK) { ledPin.toggle(); if (++ticks > timeoutTicks) { // Timeout occured, record the timestamp and reset the machine. FAST_CLR(TIMSK, OCIE1A); ticks = timeoutTicks; byte n = strlen(lastTimestamp); writeEEPROM(0, lastTimestamp, n); write1EEPROM(n, 0); ledPin.high(); resetPin.output(); _delay_ms(1000); resetPin.input(); } }
void cmd_eeprom_write(uint8_t argc, char **argv) { uint8_t val; // Try to convert supplied address to an integer int32_t addr32; getNumber (argv[0], &addr32); // Check for invalid values (getNumber may complain about this as well) if (addr32 < 0 || addr32 > CFG_EEPROM_SIZE) { printf("Address out of range %s", CFG_PRINTF_NEWLINE); return; } // Make sure this isn't in the reserved system config space if (addr32 <= CFG_EEPROM_RESERVED) { printf("ERROR: Reserved address (0x%04X-0x%04X)%s", 0, CFG_EEPROM_RESERVED, CFG_PRINTF_NEWLINE); return; } // Try to convert supplied data to an integer int32_t val32; getNumber (argv[1], &val32); // Check for invalid values (getNumber may complain about this as well) if (val32 < 0 || val32 > 0xFF) { printf("Invalid Data: 0-255 or 0x00-0xFF required.%s", CFG_PRINTF_NEWLINE); return; } // Data seems to be OK val = (uint8_t)val32; // Write data at supplied address error_t error = writeEEPROM((uint8_t*)addr32, (uint8_t *)&val, 1); if (error) { printf("Error reading EEPROM: %d%s", error, CFG_PRINTF_NEWLINE); } else { printf("0x%02X written at 0x%04X%s", val, (uint16_t)addr32 & 0xFFFF, CFG_PRINTF_NEWLINE); } }
/** @Brief 电位器\旋钮矫正上下边缘 * */ void stickKnobCalibrationEdge(void) { uint32_t currentTime; uint8_t i; uint16_t adc; int16_t def; for(i=0; i<STICK_KNOB_SUM; i++) { StickKnob[i].adcLimitHigh = 2048; StickKnob[i].adcLimitLow = 2048; } //1) 读取电位器ADC数值,更新上下边缘 //2) 30s后退出 currentTime = micros() + 30000000; while((int32_t)(currentTime - micros()) >= 0) { for(i=0; i<STICK_KNOB_SUM; i++) { adc = adcGetChannel(StickKnob[i].adcChannel); if(adc > StickKnob[i].adcLimitHigh){ StickKnob[i].adcLimitHigh = adc; } if(adc < StickKnob[i].adcLimitLow){ StickKnob[i].adcLimitLow = adc; } } delay(20); LED0_TOGGLE; } //3) 上下边缘各留出5%的虚位 for(i=0; i<STICK_KNOB_SUM; i++) { def = StickKnob[i].adcLimitHigh - StickKnob[i].adcLimitLow; def /= 20; if(def < 0) def = 0; StickKnob[i].adcLimitHigh -= def; StickKnob[i].adcLimitLow += def; } //4) 保存至EEPROM for(i = 0; i < STICK_KNOB_SUM; i++) { cfg.adcLimitHigh[i] = StickKnob[i].adcLimitHigh; cfg.adcLimitLow[i] = StickKnob[i].adcLimitLow; } writeEEPROM(1, 1); }
static void cliProfile(char *cmdline) { uint8_t len; int i; len = strlen(cmdline); if (len == 0) { printf("Current profile: %d\r\n", mcfg.current_profile); return; } else { i = atoi(cmdline); if (i >= 0 && i <= 2) { mcfg.current_profile = i; writeEEPROM(0, false); cliProfile(""); } } }