Files
c_state_pattern/src/states/off_state.c

36 lines
858 B
C

#include "state.h"
#include "../device.h"
#include <stdio.h>
// this is me being lazy
const char off_state_name[] = __FILE_NAME__;
static void pressPwrMethod(Device_t *device) {
printf("turning on device\n");
setDeviceStateToLock(device);
}
static void pressStrInputMethod(Device_t *device) {
// cast it to void since its unused
(void) device;
printf("nothing happens\n");
}
static void pressLockMethod(Device_t *device) {
// cast it to void since its unused
(void) device;
printf("nothing happens\n");
}
void setDeviceStateToOff(Device_t *device) {
device->state = (DeviceState_t){
.state_name = off_state_name,
.methods = (DeviceInterface_t){
.pressPwr = &pressPwrMethod,
.pressStrInput = &pressStrInputMethod,
.pressLock = &pressLockMethod,
},
};
}