Last active
December 29, 2018 22:14
-
-
Save CelliesProjects/ca23719c128b9e681500ae768b9320b6 to your computer and use it in GitHub Desktop.
brainstorm of brainfart to get some kind of global recognizable variable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define NUMBER_OF_CHANNELS 5 | |
| #define MAX_TIMERS 50 | |
| #define MAX_NUMBER_OF_SENSORS 3 | |
| /************************************************************************** | |
| type definitions | |
| **************************************************************************/ | |
| enum lightStatus_t | |
| { | |
| LIGHTS_OFF, LIGHTS_ON, LIGHTS_AUTO | |
| }; | |
| const char *lightStatusToString( const lightStatus_t status ) | |
| { | |
| switch ( status ) | |
| { | |
| case LIGHTS_OFF: return PSTR(" LIGHTS OFF"); | |
| case LIGHTS_ON: return PSTR(" LIGHTS ON "); | |
| case LIGHTS_AUTO: return PSTR("LIGHTS AUTO"); | |
| default: return PSTR(" UNDEFINED "); | |
| } | |
| } | |
| struct lightTimer_t | |
| { | |
| time_t time; /* time in seconds since midnight so range is 0-86400 */ | |
| uint8_t percentage; /* in percentage so range is 0-100 */ | |
| }; | |
| struct channelData_t | |
| { | |
| lightTimer_t timer[MAX_TIMERS]; | |
| char name[15]; /* initially set to 'channel 1' 'channel 2' etc. */ | |
| char color[8]; /* interface color, not light color! in hex format*/ | |
| /* Example: '#ff0000' for bright red */ | |
| float currentPercentage; /* what percentage is this channel set to */ | |
| uint8_t pin; /* which ESP32 pin is this channel on */ | |
| uint8_t numberOfTimers; /* actual number of timers for this channel */ | |
| float minimumLevel; /* never dim this channel below this percentage */ | |
| }; | |
| struct sensorData_t /* struct to keep track of Dallas DS18B20 sensors */ | |
| { | |
| byte addr[8]; | |
| float tempCelcius; | |
| char name[15]; | |
| }; | |
| struct aquaControl_t | |
| { | |
| private: | |
| lightStatus_t _lightStatus = LIGHTS_OFF; | |
| channelData_t _channel[NUMBER_OF_CHANNELS] = {}; | |
| public: | |
| const uint8_t dimmerTaskPriority = 8; | |
| channelData_t channel[NUMBER_OF_CHANNELS] = {}; | |
| sensorData_t sensor[MAX_NUMBER_OF_SENSORS] = {}; | |
| lightStatus_t lightStatus(){ return _lightStatus; }; | |
| void setStatus( const lightStatus_t status ) | |
| { | |
| portMUX_TYPE myMutex = portMUX_INITIALIZER_UNLOCKED; | |
| portENTER_CRITICAL(&myMutex); | |
| _lightStatus = status; | |
| portEXIT_CRITICAL(&myMutex); | |
| }; | |
| lightTimer_t timer( const uint8_t channel, const uint8_t number ) | |
| { | |
| lightTimer_t value = { 3600, 67 }; /* seconds since midnight, percentage */ | |
| return value; | |
| }; | |
| bool insertTimer( const uint8_t channel, const uint8_t number, const float percentage ) | |
| { | |
| //find position in timer list | |
| //insert timer | |
| }; | |
| }; | |
| aquaControl_t global; | |
| void setup() { | |
| // put your setup code here, to run once: | |
| Serial.begin(115200); | |
| global.setStatus( LIGHTS_AUTO ); | |
| Serial.println( lightStatusToString( global.lightStatus() ) ); | |
| lightTimer_t aTimer = global.timer(13,4); | |
| Serial.println( aTimer.percentage ); | |
| } | |
| void loop() { | |
| // put your main code here, to run repeatedly: | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment