You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
esp-link/user/user_funcs.c

41 lines
1000 B

9 years ago
#include "user_funcs.h"
9 years ago
bool ICACHE_FLASH_ATTR
pwmPinStateForSchedule(uint8_t onHour, uint8_t onMinute, uint8_t offHour, uint8_t offMinute) {
9 years ago
uint16_t NumMinsToday = totalMinutes(hour(), minute());
bool state = false;
if (totalMinutes(offHour, offMinute) > totalMinutes(onHour, onMinute)) {
state = (NumMinsToday >= totalMinutes(onHour, onMinute)) ? true : false;
if (NumMinsToday >= totalMinutes(offHour, offMinute))
state = false;
}
else {
state = (NumMinsToday >= totalMinutes(offHour, offMinute)) ? false : true;
if (NumMinsToday >= totalMinutes(onHour, onMinute))
state = true;
}
return state;
}
9 years ago
const char* ICACHE_FLASH_ATTR
byteToBin(uint8_t num) {
9 years ago
static char b[9];
b[0] = '\0';
int z;
for (z = 128; z > 0; z >>= 1) {
strcat(b, ((num & z) == z) ? "1" : "0");
}
return b;
}
9 years ago
const uint8_t ICACHE_FLASH_ATTR
binToByte(char* bin_str) {
9 years ago
char * tmp;
long x = strtol(bin_str, &tmp, 2);
return (x <= 255) ? (uint8_t)x : -1;
}