// SPDX-License-Identifier: Apache-2.0 // Copyright (c) 2012-2024 Scott Penrose and WII5 Buoy contributors // // This file is part of WII5 Buoy firmware. // See LICENSE for full terms. /** * @file WII5Power.h * @brief Base class for power-managed peripherals (powerOn/powerOff state). */ #ifndef WII5Power_h #define WII5Power_h #include class WII5Power : public WII5 { public: WII5Power() { powerData_Pin = 0; powerData_PinOff = 0; powerData_Pulse = 0; powerData_OnIsHigh = false; powerData_On = false; powerData_Elapsed = 0; powerData_Last = 0; powerData_LastTotal = 0; powerData_Input = true; } virtual WII5_DRIVERS driverId() {return WII5DRIVER_POWER;} void powerSetPin(uint8_t p, bool onHigh = true, uint8_t pOff = 0, uint8_t pulse = 0); void powerSetShared(WII5Power *s); virtual void powerOn(bool force = false); virtual void powerOff(bool force = false); virtual void powerInput(); bool powerStatus(); uint32_t powerLast(); uint32_t powerElapsed(); uint32_t powerLastTotal(); protected: // PIN and which way high uint8_t powerData_Pin; uint8_t powerData_PinOff; // If this is set, assume Pin to turn on, PinOff to turn off uint8_t powerData_Pulse; // Numbers of 10s of milliseconds, from 10 to 2550 bool powerData_OnIsHigh; // Shared pin - see WII5PowerShared (note it can just be a PIN but Shared counts) WII5Power *powerData_Shared; // Current status bool powerData_On; bool powerData_Input; // Pin is currently input - e.g. bootup or sleep // How long since on (millisecond timer, not effected by time changes) elapsedMillis powerData_Elapsed; // Actual time truned on (effected by tim echange) time_t powerData_Last; // Number of seconds it was on for uint32_t powerData_LastTotal; }; #endif