unsigned int oi_want_temp;
unsigned int oi_want_hum;
unsigned int oi_want_light;
-unsigned int oi_want_dark;
+unsigned int oi_grow_cykl;
+unsigned int lighting;
+unsigned int last = 0;
+float res = 10;
-int hyst_temp = 1;
+float hyst_temp = 0.5;
int hyst_hum = 10;
unsigned int fan = 0;
unsigned int hum = 0;
unsigned int light = 0;
-int temperature;
-int humidity;
+float temperature;
+float humidity;
// OBJECT INTERFACE FUNCTIONS
int oi_cid_fan_wrfnc(ULOI_PARAM_coninfo void *context){
return 1;
}
+int oi_want_light_wrfnc(ULOI_PARAM_coninfo void *context){
+ uloi_uint_wrfnc(ULOI_ARG_coninfo context);
+
+ if (oi_want_light != 0){
+ if (last != oi_want_light){
+ last = oi_want_light;
+ l3time = current_time();
+ }
+ lighting = 1;
+ } else {
+ lighting = 0;
+ last = 0;
+ }
+
+ return 1;
+}
+
+int oi_grow_cykl_wrfnc(ULOI_PARAM_coninfo void *context){
+ uloi_uint_wrfnc(ULOI_ARG_coninfo context);
+ return 1;
+}
+
void send_data() {
int msgsend;
static const int MAX_CID_CNT = 4;
cid_data_t cids[MAX_CID_CNT];
- if (oi_period == 1){
+ if (oi_period == HEART_PERIOD){
cids[cid_cnt].cid = HEART_CID;
cids[cid_cnt].value = status_val;
cid_cnt++;
buff_len += 2;
}
- msgsend = ul_send_query(ul_fd, 0, UL_CMD_PDO, UL_BFL_NORE, (void*) buf, buff_len);
+ msgsend = ul_send_command(ul_fd, 0, UL_CMD_PDO, UL_BFL_NORE, (void*) buf, buff_len);
printf("[I] DATA\n");
ul_freemsg(ul_fd);
}
void check_PDO(int cid, int data){
printf("CID: %i\n", cid);
if (cid == oi_slot_temp){
- temperature = data;
- printf("temperature: %i\n", temperature);
+ temperature = data/res;
+ printf("temperature: %f\n", temperature);
}
if (cid == oi_slot_hum){
- humidity = data;
- printf("humidity: %i\n", humidity);
+ humidity = data/res;
+ printf("humidity: %f\n", humidity);
}
}
void regulate(void){
- if (((oi_want_temp + hyst_temp) > temperature) && fan != 1) fan = 1;
- if (((oi_want_temp - hyst_temp) < temperature) && fan != 0) fan = 0;
+ if (temperature > (oi_want_temp/res + hyst_temp)) fan = 1;
+ if (temperature < (oi_want_temp/res - hyst_temp)) fan = 0;
- if (((oi_want_hum + hyst_hum) > humidity) && hum != 1) hum = 1;
- if (((oi_want_hum - hyst_hum) < humidity) && hum != 0) hum = 0;
+ if (humidity < (oi_want_hum/res + hyst_hum)) hum = 1;
+ if (humidity > (oi_want_hum/res - hyst_hum)) hum = 0;
- if(((current_time()-l3time) < oi_want_light*3600*1000) && light == 0) {
- light = 1;
- l3time = current_time();
- }
- if(((current_time()-l3time) < oi_want_dark*3600*1000) && light == 1) {
- light = 0;
- l3time = current_time();
+ if (lighting == 1){
+ if((current_time()-l3time) < oi_want_light/res/* *3600*/*1000) {
+ light = 1;
+ } else if((current_time()-l3time) < oi_grow_cykl/res/* *3600*/*1000){
+ light = 0;
+ } else l3time = current_time();
}
}
void work_with(void){
}
-
-