get rid of strings

This commit is contained in:
J. Nick Koston 2023-06-07 10:06:51 -05:00
parent 69ef18362a
commit ab270ac08b
No known key found for this signature in database
4 changed files with 152 additions and 71 deletions

View File

@ -22,76 +22,6 @@ namespace ratgdo {
static const char* const TAG = "ratgdo";
static const int STARTUP_DELAY = 2000; // delay before enabling interrupts
const char* door_state_to_string(DoorState state)
{
switch (state) {
case DOOR_STATE_OPEN:
return "OPEN";
case DOOR_STATE_CLOSED:
return "CLOSED";
case DOOR_STATE_STOPPED:
return "STOPPED";
case DOOR_STATE_OPENING:
return "OPENING";
case DOOR_STATE_CLOSING:
return "CLOSING";
case DOOR_STATE_UNKNOWN:
default:
return "UNKNOWN";
}
}
const char* light_state_to_string(LightState state)
{
switch (state) {
case LIGHT_STATE_OFF:
return "OFF";
case LIGHT_STATE_ON:
return "ON";
case LIGHT_STATE_UNKNOWN:
default:
return "UNKNOWN";
}
}
const char* lock_state_to_string(LockState state)
{
switch (state) {
case LOCK_STATE_UNLOCKED:
return "UNLOCKED";
case LOCK_STATE_LOCKED:
return "LOCKED";
case LOCK_STATE_UNKNOWN:
default:
return "UNKNOWN";
}
}
const char* motion_state_to_string(MotionState state)
{
switch (state) {
case MOTION_STATE_CLEAR:
return "CLEAR";
case MOTION_STATE_DETECTED:
return "DETECTED";
default:
return "CLEAR";
}
}
const char* obstruction_state_to_string(ObstructionState state)
{
switch (state) {
case OBSTRUCTION_STATE_CLEAR:
return "CLEAR";
case OBSTRUCTION_STATE_OBSTRUCTED:
return "OBSTRUCTED";
case OBSTRUCTION_STATE_UNKNOWN:
default:
return "UNKNOWN";
}
}
/*************************** DRY CONTACT CONTROL OF LIGHT & DOOR
* ***************************/
void IRAM_ATTR HOT RATGDOStore::isrDoorOpen(RATGDOStore* arg)

View File

@ -3,13 +3,14 @@
#include "esphome/core/helpers.h"
#include "ratgdo.h"
#include "ratgdo_state.h"
namespace esphome {
namespace ratgdo {
// Forward declare RATGDOComponent
class RATGDOComponent;
class RATGDOClient : public Parented<RATGDOComponent> {
public:
virtual void on_door_state(esphome::ratgdo::DoorState state) = 0;

View File

@ -0,0 +1,79 @@
#include "ratgdo_state.h"
#include "esphome/core/log.h"
namespace esphome {
namespace ratgdo {
const char* door_state_to_string(DoorState state)
{
switch (state) {
case DOOR_STATE_OPEN:
return "OPEN";
case DOOR_STATE_CLOSED:
return "CLOSED";
case DOOR_STATE_STOPPED:
return "STOPPED";
case DOOR_STATE_OPENING:
return "OPENING";
case DOOR_STATE_CLOSING:
return "CLOSING";
case DOOR_STATE_UNKNOWN:
default:
return "UNKNOWN";
}
}
const char* light_state_to_string(LightState state)
{
switch (state) {
case LIGHT_STATE_OFF:
return "OFF";
case LIGHT_STATE_ON:
return "ON";
case LIGHT_STATE_UNKNOWN:
default:
return "UNKNOWN";
}
}
const char* lock_state_to_string(LockState state)
{
switch (state) {
case LOCK_STATE_UNLOCKED:
return "UNLOCKED";
case LOCK_STATE_LOCKED:
return "LOCKED";
case LOCK_STATE_UNKNOWN:
default:
return "UNKNOWN";
}
}
const char* motion_state_to_string(MotionState state)
{
switch (state) {
case MOTION_STATE_CLEAR:
return "CLEAR";
case MOTION_STATE_DETECTED:
return "DETECTED";
default:
return "CLEAR";
}
}
const char* obstruction_state_to_string(ObstructionState state)
{
switch (state) {
case OBSTRUCTION_STATE_CLEAR:
return "CLEAR";
case OBSTRUCTION_STATE_OBSTRUCTED:
return "OBSTRUCTED";
case OBSTRUCTION_STATE_UNKNOWN:
default:
return "UNKNOWN";
}
}
} // namespace ratgdo
} // namespace esphome

View File

@ -0,0 +1,71 @@
/************************************
* Rage
* Against
* The
* Garage
* Door
* Opener
*
* Copyright (C) 2022 Paul Wieland
*
* GNU GENERAL PUBLIC LICENSE
************************************/
#pragma once
#include "esphome/components/uart/uart.h"
#include "esphome/core/component.h"
#include "esphome/core/gpio.h"
#include "esphome/core/log.h"
#include "esphome/core/preferences.h"
extern "C" {
#include "secplus.h"
}
#include "ratgdo_child.h"
#define CODE_LENGTH 19
namespace esphome {
namespace ratgdo {
/// Enum for all states a the door can be in.
enum DoorState : uint8_t {
DOOR_STATE_UNKNOWN = 0,
DOOR_STATE_OPEN = 1,
DOOR_STATE_CLOSED = 2,
DOOR_STATE_STOPPED = 3,
DOOR_STATE_OPENING = 4,
DOOR_STATE_CLOSING = 5
};
const char* door_state_to_string(DoorState state);
/// Enum for all states a the light can be in.
enum LightState : uint8_t {
LIGHT_STATE_OFF = 0,
LIGHT_STATE_ON = 1,
LIGHT_STATE_UNKNOWN = 2,
};
const char* light_state_to_string(LightState state);
/// Enum for all states a the lock can be in.
enum LockState : uint8_t {
LOCK_STATE_UNLOCKED = 0,
LOCK_STATE_LOCKED = 1,
LOCK_STATE_UNKNOWN = 2,
};
/// Enum for all states a the motion can be in.
enum MotionState : uint8_t {
MOTION_STATE_CLEAR = 0,
MOTION_STATE_DETECTED = 1,
};
/// Enum for all states a the obstruction can be in.
enum ObstructionState : uint8_t {
OBSTRUCTION_STATE_OBSTRUCTED = 0,
OBSTRUCTION_STATE_CLEAR = 1,
OBSTRUCTION_STATE_UNKNOWN = 2,
};
} // namespace ratgdo
} // namespace esphome