增加内存检查机制 Increased EEPROM memory check

增加内存检查机制
Increased EEPROM memory check
This commit is contained in:
createskyblue
2020-11-14 23:55:49 +08:00
parent fc5bf053a9
commit 54b96fa36f
5 changed files with 3950 additions and 13 deletions

View File

@@ -162,7 +162,7 @@ bool BeepEnable = BEEP_ENABLE;
#define TempP3 -0.0033245713
#define TempP4 0.0000045338
float PTemp[4] = {TempP1, TempP2, TempP3, TempP4}; //温度拟合系数
const uint16_t CalTemp[9] = {50,100,150,200,250,300,350,400,450};
const uint16_t CalTemp[9] = {50, 100, 150, 200, 250, 300, 350, 400, 450};
char TipName[TIPNAMELENGTH] = {TIPNAME};
uint8_t CurrentTip = 0;
uint8_t NumberOfTips = 1;
@@ -218,7 +218,7 @@ byte Line[4];
bool RotaryD = false;
//开机非线性动画
byte BootAnimationY=64;
byte BootAnimationY = 64;
// Specify the links and initial PID tuning parameters
PID ctrl(&Input, &Output, &Setpoint, aggKp, aggKi, aggKd, REVERSE);
@@ -283,7 +283,7 @@ void setup() {
//设置屏幕亮度
SetOLEDLightLevel(32); //降低屏幕亮度 延长OLED使用寿命
//初始化屏幕保护动画
for (byte a = 0; a < 4; a++) Line[a] = 32 * a;
@@ -311,7 +311,7 @@ void setup() {
setRotary(TEMP_MIN, TEMP_MAX, TEMP_STEP, DefaultTemp);
// reset sleep timer
Sleepmillis = millis();
// long beep for setup completion
beep(); beep();
ShowVersion();

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,60 @@
/*EEPROM可用性检查
作用防止因为EEPROM损坏而载入了错误的运行参数导致参数生产安全事故
*/
void CheckEEPROM() {
byte w, r;
int pass = 0, fail = 0;
for (int i = 0; i < EEPROM.length(); i++) {
//内存测试程序
w = random(0, 255);
EEPROM[i] = w;
r = EEPROM[i];
if (w == r) pass++; else fail++;
//显示测试数据
arduboy.clear();
arduboy.setTextSize(2);
SetTextColor(0);
arduboy.setCursor(0, 0);
arduboy.print(F(" MEM CHECK "));
arduboy.setTextSize(1);
arduboy.setCursor(8, 40);
arduboy.print(i); arduboy.print(F("/")); arduboy.print(EEPROM.length());
SetTextColor(1);
arduboy.setCursor(0 + 8, 24); arduboy.print(F("PASS-")); arduboy.print(pass);
arduboy.setCursor(64 + 8, 24); arduboy.print(F("FAIL-")); arduboy.print(fail);
arduboy.setCursor(0 + 8, 32); arduboy.print(F("W -> ")); arduboy.print(w);
arduboy.setCursor(64 + 8, 32); arduboy.print(F("R -> ")); arduboy.print(r);
//进度标
arduboy.setCursor(map(i, 0, EEPROM.length(), 0, 92), 52);
arduboy.print(((float)i / EEPROM.length())*100); arduboy.print(F("%"));
//进度条
arduboy.fillRect(0, 60, map(i, 0, EEPROM.length(), 0, 127), 4, 1);
arduboy.display();
}
//EEPROM存储器可用性检查失败
while (fail == 0) {
arduboy.clear();
arduboy.setTextSize(2);
SetTextColor(1);
arduboy.setCursor(22, 16);
arduboy.print(F("DAMAGED"));
arduboy.setTextSize(1);
arduboy.setCursor(31, 44);
SetTextColor(0);
if (millis() / 1000 % 2 == 0)arduboy.print(F("BOOT FAILED"));
arduboy.display();
}
}
/*查看EEPROM内存
通过板载的旋转编码器可以上下滚动翻阅EEPROM中的数据
*/
void ViewEEPRom() {
setRotary(0, 1023, 16, 0);
lastbutton = (!digitalRead(BUTTON_PIN));
@@ -98,6 +155,7 @@ void GetEEPROM() {
RotaryD = EEPROM.read(20);
}
else {
CheckEEPROM();
EEPROM.update(0, EEPROM_IDENT >> 8); EEPROM.update(1, EEPROM_IDENT & 0xFF);
UpdateEEPROM();
}

View File

@@ -74,15 +74,8 @@ uint16_t getVCC() {
// get supply voltage in mV
uint16_t getVIN() {
long result;
result = denoiseAnalog (VIN_PIN); {
if (result < 540) return (result * Vcc / 184.416 + 86.987);
else if (result < 660) return (result * Vcc / 173.204 - 878.29);
else if (result < 745) return (result * Vcc / 143.579 - 4875);
else if (result < 781) return (result * Vcc / 119.109 - 10260);
else if (result < 800) return (result * Vcc / 86.178 - 23013);
else return (result * Vcc / 86.178 - 23113);
} // read supply voltage via voltage divider
//return (result * Vcc / 179.474); // 179.474 = 1023 * R13 / (R12 + R13)
result = denoiseAnalog (VIN_PIN); // read supply voltage via voltage divider
return (result * Vcc / 179.474); // 179.474 = 1023 * R13 / (R12 + R13)
}
//ADC中断服务