Files
c_state_pattern/src/device.c
sirlilpanda d4e72630e9 init
2025-08-28 21:19:47 +12:00

29 lines
687 B
C

#include "device.h"
#include <string.h>
static void pressPwrMethod(Device_t *device) {
device->state.methods.pressPwr(device);
}
static void pressStrInputMethod(Device_t *device) {
device->state.methods.pressStrInput(device);
}
static void pressLockMethod(Device_t *device) {
device->state.methods.pressLock(device);
}
void initDevice(Device_t* device) {
*device = (Device_t){
.state = NULL,
.entered_string = "frogs",
.entered_string_len = 6,
.methods = (DeviceInterface_t){
.pressPwr = &pressPwrMethod,
.pressStrInput = &pressStrInputMethod,
.pressLock = &pressLockMethod,
},
};
}