clean ups, hopefully no real code changes

This commit is contained in:
Staars 2020-02-05 16:56:41 +01:00
parent 47ead336cb
commit e8f8b48c77
1 changed files with 33 additions and 35 deletions

View File

@ -48,7 +48,7 @@ struct {
uint8_t current_task_delay; // number of 100ms-cycles
uint8_t last_command;
uint16_t firmware;
uint32_t period; // set manually in addition to TELE-period
uint32_t period; // set manually in addition to TELE-period, is set to TELE-period after start
uint32_t serialSpeed;
struct {
uint32_t init:1;
@ -68,7 +68,7 @@ struct {
struct {
uint16_t temp;
uint8_t hum;
} LYWSD03;
} LYWSD03_HT;
#pragma pack(0)
struct mi_sensor_t{
@ -169,6 +169,10 @@ void HM10_TaskReplaceInSlot(uint8_t task, uint8_t slot){
HM10_TASK_LIST[slot][0] = task;
}
/*********************************************************************************************\
* chained tasks
\*********************************************************************************************/
void HM10_Reset(void) { HM10_Launchtask(TASK_HM10_DISCONN,0,1); // disconnect
HM10_Launchtask(TASK_HM10_ROLE1,1,1); // set role to 1
HM10_Launchtask(TASK_HM10_IMME1,2,1); // set imme to 1
@ -191,7 +195,6 @@ void HM10_Read_Sensor(void) {
HM10_Launchtask(TASK_HM10_DISCONN,5,5); // disconnect
}
/**
* @brief Return the slot number of a known sensor or return create new sensor slot
*
@ -276,16 +279,16 @@ void HM10SerialInit(void) {
return;
}
/*********************************************************************************************\
* create the HM10 commands payload, and send it via serial interface to the HM10 module
\*********************************************************************************************/
/**
* @brief convert Mac-String to byte array
*
* @param string Hex-string, must contain 12 chars (no error checking)
* @param _mac Must be a uint8_t[6], filled with zeros
*/
void HM10datahex(const char* string, uint8_t _mac[]) {
uint32_t slength = 12;
// uint8_t _mac[6] = {0};
void HM10MACStringToBytes(const char* string, uint8_t _mac[]) {
uint32_t index = 0;
DEBUG_SENSOR_LOG(PSTR("HM10: mac-string %s"), string);
while (index < slength) {
while (index < 12) {
char c = string[index];
uint32_t value = 0;
if(c >= '0' && c <= '9')
@ -303,6 +306,7 @@ void HM10datahex(const char* string, uint8_t _mac[]) {
/*********************************************************************************************\
* parse the response
\*********************************************************************************************/
void HM10ParseResponse(char *buf) {
if (!strncmp(buf,"OK",2)) {
DEBUG_SENSOR_LOG(PSTR("HM10: got OK"));
@ -320,7 +324,7 @@ void HM10ParseResponse(char *buf) {
memcpy((void *)_mac,(void *)(_pos+4),12);
DEBUG_SENSOR_LOG(PSTR("HM10: found Mac: %s"), _mac);
uint8_t _newMacArray[6] = {0};
HM10datahex(_mac, _newMacArray);
HM10MACStringToBytes(_mac, _newMacArray);
DEBUG_SENSOR_LOG(PSTR("HM10: MAC-array: %x%x%x%x%x%x"),_newMacArray[0],_newMacArray[1],_newMacArray[2],_newMacArray[3],_newMacArray[4],_newMacArray[5]);
MIBLEgetSensorSlot(_newMacArray, 0xff);
}
@ -332,21 +336,19 @@ void HM10ParseResponse(char *buf) {
void HM10readTempHum(char *_buf){
DEBUG_SENSOR_LOG(PSTR("HM10: raw data: %x%x%x%x%x%x%x"),_buf[0],_buf[1],_buf[2],_buf[3],_buf[4],_buf[5],_buf[6]);
if(_buf[0] != 0 && _buf[1] != 0){
memcpy(&LYWSD03,(void *)_buf,3);
DEBUG_SENSOR_LOG(PSTR("HM10: Temperature * 100: %u, Humidity: %u"),LYWSD03.temp,LYWSD03.hum);
// uint8_t _serial[6] = {0};
// uint32_t _slot = MIBLEgetSensorSlot(HM10Mac[HM10.state.sensor], 4);
memcpy(&LYWSD03_HT,(void *)_buf,3);
DEBUG_SENSOR_LOG(PSTR("HM10: Temperature * 100: %u, Humidity: %u"),LYWSD03_HT.temp,LYWSD03_HT.hum);
uint32_t _slot = HM10.state.sensor;
DEBUG_SENSOR_LOG(PSTR("MIBLE: Sensor slot: %u"), _slot);
static float _tempFloat;
_tempFloat=(float)(LYWSD03.temp)/100.0f;
_tempFloat=(float)(LYWSD03_HT.temp)/100.0f;
if(_tempFloat<60){
MIBLEsensors.at(_slot).temp=_tempFloat;
HM10.mode.awaitingHT = false;
HM10.current_task_delay = 0;
}
_tempFloat=(float)LYWSD03.hum;
_tempFloat=(float)LYWSD03_HT.hum;
if(_tempFloat<100){
MIBLEsensors.at(_slot).hum = _tempFloat;
DEBUG_SENSOR_LOG(PSTR("LYWSD03: hum updated"));
@ -371,7 +373,7 @@ void HM10readBat(char *_buf){
\*********************************************************************************************/
bool HM10SerialHandleFeedback(){ // every 50 milliseconds
bool success = false; // true disables possible repetition of commands, set to false only for debugging
bool success = false;
uint32_t i = 0;
char ret[HM10_MAX_RX_BUF] = {0}; // reset array with zeros
@ -407,7 +409,6 @@ bool HM10SerialHandleFeedback(){ // every 50 milliseconds
\*********************************************************************************************/
void HM10_TaskEvery100ms(){
// HM10SerialHandleFeedback();
if (HM10.current_task_delay == 0) {
uint8_t i = 0;
bool runningTaskLoop = true;
@ -525,7 +526,6 @@ void HM10_TaskEvery100ms(){
HM10.mode.awaitingHT = true;
runningTaskLoop = false;
break;
case TASK_HM10_DONE: // this entry was already handled
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%sFound done HM10_TASK"),D_CMND_HM10);
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%snext slot:%u, i: %u"),D_CMND_HM10, HM10_TASK_LIST[i+1][0],i);
@ -538,9 +538,7 @@ void HM10_TaskEvery100ms(){
HM10_TASK_LIST[j][1] = 0; // reset all delays
}
runningTaskLoop = false; // return to main loop
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%sUpdate GUI via AJAX"),D_CMND_HM10);
// HM10_GUI_NEEDS_UPDATE = true;
HM10.mode.pending_task = 0;
HM10.mode.pending_task = 0; // back to main loop control
break;
}
}
@ -552,9 +550,10 @@ void HM10_TaskEvery100ms(){
}
}
/*
|* Loops
\* */
/**
* @brief Main loop of the driver, "high level"-loop
*
*/
void HM10EverySecond(){
if(HM10.firmware == 0) return;
@ -574,7 +573,6 @@ void HM10EverySecond(){
_nextSensorSlot= 0;
_counter++;
}
DEBUG_SENSOR_LOG(PSTR("%s active sensor now: %u"),D_CMND_HM10, HM10.state.sensor);
}
else _counter++;