- USB CDC 경로 복원: #define Serial Serial1 우회 제거 - rp2040js/avr8js/codemirror/xterm/monaco-editor vendor화 - /vendor 정적 라우팅 추가 (Express 5 catch-all 우회) - 부팅 완료 타임아웃 감지 (Serial 출력 없어도 8초 후 RAF 전환) - 리셋 시 Simulator 재생성으로 주변 장치 상태 초기화 - 시리얼 패널의 내부 메시지를 console.log로 이동
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
export class FIFO {
|
|
constructor(size) {
|
|
this.start = 0;
|
|
this.used = 0;
|
|
this.buffer = new Uint32Array(size);
|
|
}
|
|
get size() {
|
|
return this.buffer.length;
|
|
}
|
|
get itemCount() {
|
|
return this.used;
|
|
}
|
|
push(value) {
|
|
const { length } = this.buffer;
|
|
const { start, used } = this;
|
|
if (this.used < length) {
|
|
this.buffer[(start + used) % length] = value;
|
|
this.used++;
|
|
}
|
|
}
|
|
pull() {
|
|
const { start, used } = this;
|
|
const { length } = this.buffer;
|
|
if (used) {
|
|
this.start = (start + 1) % length;
|
|
this.used--;
|
|
return this.buffer[start];
|
|
}
|
|
return 0;
|
|
}
|
|
peek() {
|
|
return this.used ? this.buffer[this.start] : 0;
|
|
}
|
|
reset() {
|
|
this.used = 0;
|
|
}
|
|
get empty() {
|
|
return this.used == 0;
|
|
}
|
|
get full() {
|
|
return this.used === this.buffer.length;
|
|
}
|
|
get items() {
|
|
const { start, used, buffer } = this;
|
|
const { length } = buffer;
|
|
const result = [];
|
|
for (let i = 0; i < used; i++) {
|
|
result[i] = buffer[(start + i) % length];
|
|
}
|
|
return result;
|
|
}
|
|
}
|