|
83 | 83 | <script lang="ts" setup> |
84 | 84 | import { reactive } from 'vue'; |
85 | 85 | import { useAppStore } from '@/store'; |
86 | | - import { eeprom_write, eeprom_reboot, eeprom_init, eeprom_read } from '@/utils/serial.js'; |
| 86 | + import { eeprom_write, eeprom_reboot, eeprom_init, eeprom_read, check_eeprom } from '@/utils/serial.js'; |
87 | 87 | import { useI18n } from 'vue-i18n'; |
88 | 88 | const { t } = useI18n(); |
89 | 89 |
|
|
103 | 103 | } |
104 | 104 |
|
105 | 105 | const checkEeprom = async () => { |
106 | | - let eepromSize = t('workplace.unk'); |
107 | | - const random = [ |
108 | | - Math.round(Math.random() * 256), |
109 | | - Math.round(Math.random() * 256), |
110 | | - Math.round(Math.random() * 256), |
111 | | - Math.round(Math.random() * 256), |
112 | | - Math.round(Math.random() * 256), |
113 | | - Math.round(Math.random() * 256), |
114 | | - Math.round(Math.random() * 256), |
115 | | - Math.round(Math.random() * 256) |
116 | | - ] |
117 | | - await eeprom_init(appStore.connectPort); |
118 | | - const rawEEPROM = new Uint8Array(random); |
119 | | - if(appStore.configuration?.uart == 'official'){ |
120 | | - const bk1 = await eeprom_read(appStore.connectPort, 0, 0x08, appStore.configuration?.uart); |
121 | | - await eeprom_write(appStore.connectPort, 0, rawEEPROM, 0x08, appStore.configuration?.uart); |
122 | | - const check1 = await eeprom_read(appStore.connectPort, 0, 0x08, appStore.configuration?.uart); |
123 | | - if(rawEEPROM.toString() == check1.toString()){ |
124 | | - eepromSize = t('global.8kb') |
125 | | - } |
126 | | - await eeprom_write(appStore.connectPort, 0, bk1, 0x08, appStore.configuration?.uart); |
127 | | - }else{ |
128 | | - const bk1 = await eeprom_read(appStore.connectPort, 0, 0x08, appStore.configuration?.uart); |
129 | | - await eeprom_write(appStore.connectPort, 0, rawEEPROM, 0x08, appStore.configuration?.uart); |
130 | | - const check1 = await eeprom_read(appStore.connectPort, 0, 0x08, appStore.configuration?.uart); |
131 | | - if(rawEEPROM.toString() == check1.toString()){ |
132 | | - eepromSize = t('global.8kb') |
133 | | - } |
134 | | - await eeprom_write(appStore.connectPort, 0, bk1, 0x08, appStore.configuration?.uart); |
135 | | -
|
136 | | - const bk2 = await eeprom_read(appStore.connectPort, 0x1FFF8, 0x08, appStore.configuration?.uart); |
137 | | - await eeprom_write(appStore.connectPort, 0x1FFF8, rawEEPROM, 0x08, appStore.configuration?.uart); |
138 | | - const check2 = await eeprom_read(appStore.connectPort, 0x1FFF8, 0x08, appStore.configuration?.uart); |
139 | | - if(rawEEPROM.toString() == check2.toString()){ |
140 | | - eepromSize = t('global.128kb') |
141 | | - } |
142 | | - await eeprom_write(appStore.connectPort, 0x1FFF8, bk2, 0x08, appStore.configuration?.uart); |
143 | | -
|
144 | | - const bk3 = await eeprom_read(appStore.connectPort, 0x3FFF8, 0x08, appStore.configuration?.uart); |
145 | | - await eeprom_write(appStore.connectPort, 0x3FFF8, rawEEPROM, 0x08, appStore.configuration?.uart); |
146 | | - const check3 = await eeprom_read(appStore.connectPort, 0x3FFF8, 0x08, appStore.configuration?.uart); |
147 | | - if(rawEEPROM.toString() == check3.toString()){ |
148 | | - eepromSize = t('global.256kb') |
149 | | - } |
150 | | - await eeprom_write(appStore.connectPort, 0x3FFF8, bk3, 0x08, appStore.configuration?.uart); |
151 | | -
|
152 | | - const bk5 = await eeprom_read(appStore.connectPort, 0x5FFF8, 0x08, appStore.configuration?.uart); |
153 | | - await eeprom_write(appStore.connectPort, 0x5FFF8, rawEEPROM, 0x08, appStore.configuration?.uart); |
154 | | - const check5 = await eeprom_read(appStore.connectPort, 0x5FFF8, 0x08, appStore.configuration?.uart); |
155 | | - if(rawEEPROM.toString() == check5.toString()){ |
156 | | - eepromSize = t('global.384kb') |
157 | | - } |
158 | | - await eeprom_write(appStore.connectPort, 0x5FFF8, bk5, 0x08, appStore.configuration?.uart); |
159 | | -
|
160 | | - const bk4 = await eeprom_read(appStore.connectPort, 0x7FFF8, 0x08, appStore.configuration?.uart); |
161 | | - await eeprom_write(appStore.connectPort, 0x7FFF8, rawEEPROM, 0x08, appStore.configuration?.uart); |
162 | | - const check4 = await eeprom_read(appStore.connectPort, 0x7FFF8, 0x08, appStore.configuration?.uart); |
163 | | - if(rawEEPROM.toString() == check4.toString()){ |
164 | | - eepromSize = t('global.512kb') |
165 | | - } |
166 | | - await eeprom_write(appStore.connectPort, 0x7FFF8, bk4, 0x08, appStore.configuration?.uart); |
| 106 | + const eepromSize = await check_eeprom(appStore.connectPort, appStore.configuration?.uart); |
| 107 | + switch(eepromSize){ |
| 108 | + case 0x2000: |
| 109 | + state.eepromSize = t('global.8kb'); |
| 110 | + break; |
| 111 | + case 0x10000: |
| 112 | + state.eepromSize = t('global.64kb'); |
| 113 | + break; |
| 114 | + case 0x20000: |
| 115 | + state.eepromSize = t('global.128kb'); |
| 116 | + break; |
| 117 | + case 0x40000: |
| 118 | + state.eepromSize = t('global.256kb'); |
| 119 | + break; |
| 120 | + case 0x80000: |
| 121 | + state.eepromSize = t('global.512kb'); |
| 122 | + break; |
| 123 | + default: |
| 124 | + state.eepromSize = t('workplace.unk'); |
| 125 | + break; |
167 | 126 | } |
168 | | - state.eepromSize = eepromSize; |
169 | 127 | } |
170 | 128 | </script> |
171 | 129 |
|
|
0 commit comments