약간의 수정

This commit is contained in:
2025-12-09 02:34:41 +09:00
parent 0697b5ab31
commit d3a2802333
22 changed files with 406 additions and 25 deletions

43
ccs/state.c Normal file → Executable file
View File

@@ -35,4 +35,45 @@ void senbuf_get(SensorBuffer *sb, uint8_t *out, int lookahead) {
int index = (sb->rear - 1 - lookahead + STATE_SENSOR_BUFFER_SIZE) % STATE_SENSOR_BUFFER_SIZE;
*out = sb->buffer[index];
}
}
}
// History Buffer
void hisbuf_init(HistoryBuffer *sb) {
sb->front = 0;
sb->rear = 0;
sb->size = 0;
}
int hisbuf_is_full(HistoryBuffer *sb) {
return sb->size == HISTORY_SIZE;
}
int hisbuf_push(HistoryBuffer *sb, uint8_t value) {
if (sb->size < HISTORY_SIZE) {
sb->buffer[sb->rear] = value;
sb->rear = (sb->rear + 1) % HISTORY_SIZE;
sb->size++;
return 1; // Success
}
return 0; // Buffer full
}
int hisbuf_pop(HistoryBuffer *sb) {
if (sb->size > 0) {
sb->front = (sb->front + 1) % HISTORY_SIZE;
sb->size--;
return 1; // Success
}
return 0; // Buffer empty
}
void hisbuf_get(HistoryBuffer *sb, uint8_t *out, int lookahead) {
if (lookahead >= 0 && lookahead < sb->size) {
// 가장 최근에 넣은 것(rear - 1)을 기준으로 lookahead
int index = (sb->rear - 1 - lookahead + HISTORY_SIZE) % HISTORY_SIZE;
*out = sb->buffer[index];
}
}