changed from setXState to a more discripive setDeviceStateToX

This commit is contained in:
sirlilpanda
2025-08-29 00:12:44 +12:00
parent aead22a646
commit 0ed9111af3
5 changed files with 26 additions and 17 deletions

View File

@@ -7,19 +7,20 @@ const char debug_state_name[] = __FILE_NAME__;
static void pressPwrMethod(Device_t *device) {
printf("turning off device\n");
setOffState(device);
setDeviceStateToOff(device);
}
static void pressStrInputMethod(Device_t *device) {
(void) device;
printf("nothing happens\n");
}
static void pressLockMethod(Device_t *device) {
printf("locking device\n");
setOffState(device);
setDeviceStateToOff(device);
}
void setDebugState(Device_t *device) {
void setDeviceStateToDebug(Device_t *device) {
device->state = (DeviceState_t){
.state_name = debug_state_name,
.device = device,

View File

@@ -8,18 +8,18 @@ const char lock_state_name[] = __FILE_NAME__;
static void pressPwrMethod(Device_t *device) {
printf("turning off device\n");
setOffState(device);
setDeviceStateToOff(device);
}
static void pressStrInputMethod(Device_t *device) {
if (strcmp(device->entered_string, "dbg") == 0) {
printf("entering debug state\n");
setDebugState(device);
setDeviceStateToDebug(device);
return;
}
if (strcmp(device->entered_string, "pwd") == 0) {
printf("entering unlock state\n");
setUnlockState(device);
setDeviceStateToUnlock(device);
return;
}
@@ -28,10 +28,11 @@ static void pressStrInputMethod(Device_t *device) {
}
static void pressLockMethod(Device_t *device) {
(void) device;
printf("nothing happens\n");
}
void setLockState(Device_t *device) {
void setDeviceStateToLock(Device_t *device) {
device->state = (DeviceState_t){
.state_name = lock_state_name,
.device = device,

View File

@@ -6,18 +6,20 @@ const char off_state_name[] = __FILE_NAME__;
static void pressPwrMethod(Device_t *device) {
printf("turning on device\n");
setLockState(device);
setDeviceStateToLock(device);
}
static void pressStrInputMethod(Device_t *device) {
(void) device;
printf("nothing happens\n");
}
static void pressLockMethod(Device_t *device) {
(void) device;
printf("nothing happens\n");
}
void setOffState(Device_t *device) {
void setDeviceStateToOff(Device_t *device) {
device->state = (DeviceState_t){
.state_name = off_state_name,
.device = device,

View File

@@ -1,7 +1,9 @@
#pragma once
#include "../device.h"
void setLockState(Device_t *device);
void setUnlockState(Device_t *device);
void setDebugState(Device_t *device);
void setOffState(Device_t *device);
// why nothing working?
// each of these are each state
void setDeviceStateToLock(Device_t *device);
void setDeviceStateToUnlock(Device_t *device);
void setDeviceStateToDebug(Device_t *device);
void setDeviceStateToOff(Device_t *device);

View File

@@ -3,27 +3,30 @@
#include <stdio.h>
#include <string.h>
// this is me being lazy
const char name[] = __FILE_NAME__;
// so when a button is pressed it updates the state to the new one
static void pressPwrMethod(Device_t *device) {
printf("turning off device\n");
setOffState(device);
setDeviceStateToOff(device);
}
static void pressStrInputMethod(Device_t *device) {
if (strcmp(device->entered_string, "dbg") == 0) {
printf("entering debug state\n");
setDebugState(device);
setDeviceStateToDebug(device);
return;
}
printf("unknown string %s\n", device->entered_string);
}
static void pressLockMethod(Device_t *device) {
printf("locking device\n");
setLockState(device);
setDeviceStateToLock(device);
}
void setUnlockState(Device_t *device) {
void setDeviceStateToUnlock(Device_t *device) {
device->state = (DeviceState_t){
.state_name = name,
.device = device,