devices working

This commit is contained in:
2026-07-16 14:05:01 +10:00
parent 42fab467f1
commit fb3efc77c3
7 changed files with 123 additions and 25 deletions

View File

@@ -2,11 +2,37 @@
Device* createDevice(
const char* name,
void (*sendToDevice)(uint16_t number),
uint16_t (*receiveFromDevice)(),
void (*update)()
void (*update)(Device* self)
) {
Device* new = malloc(sizeof(Device));
if (!new)
return NULL;
size_t nameLen = strlen(name) + 1;
nameLen = nameLen < 32 ? nameLen : 32;
memcpy(new->name, name, nameLen);
new->name[nameLen] = 0;
new->update = update;
return new;
}
uint16_t deviceRead(Device* self) {
if (self->inPos == 0)
return 0;
return self->in[--self->inPos];
}
void deviceSend(Device* self, uint16_t value) {
if (self->outPos == DEVICE_BUFFER_LENGTH)
return;
self->out[self->outPos++] = value;
}
bool deviceCanRead(Device* self) {
return self->inPos > 0;
}