void userTask(void *param) { char_t buffer[40]; //Point to the network interface NetInterface *interface = &netInterface[0]; //Initialize LCD display lcdSetCursor(1, 0); printf("IPv4 Addr\r\n"); lcdSetCursor(4, 0); printf("IPv6 Link-Local Addr\r\n"); lcdSetCursor(7, 0); printf("IPv6 Global Addr\r\n"); //Endless loop while(1) { #if (IPV4_SUPPORT == ENABLED) //Display IPv4 host address lcdSetCursor(2, 0); printf("%-16s\r\n", ipv4AddrToString(interface->ipv4Config.addr, buffer)); #endif #if (IPV6_SUPPORT == ENABLED) //Display IPv6 link-local address lcdSetCursor(5, 0); printf("%-40s\r\n", ipv6AddrToString(&interface->ipv6Config.linkLocalAddr, buffer)); //Display IPv6 global address lcdSetCursor(8, 0); printf("%-40s\r\n", ipv6AddrToString(&interface->ipv6Config.globalAddr, buffer)); #endif //Start A/D conversion adcValue = (1023 - adcGetValue()) * 4; //Loop delay osDelayTask(500); } }
/** * \brief Module executive. Call once for each iteration of the * main processing loop. Drives the module state machine. */ void sensorHub_exec(void) { int16_t data_XYZ[3]; GPIO_PinState chamberBit; // Read ADC snd.adcL1Val += adcGetValue(ADC_RSVR_HIGH); snd.adcL2Val += adcGetValue(ADC_RSVR_LOW); // Average the ADC values for the Level sensors snd.adcLevelAvgCounter++; if (snd.adcLevelAvgCounter >= SYS_TICKS_PER_LEVEL_UPDATE) { snd.adcLevelAvgCounter = 0; bool L1_is_high = false; bool L2_is_high = false; snd.adcL1AvgVal = snd.adcL1Val/SYS_TICKS_PER_LEVEL_UPDATE; snd.adcL2AvgVal = snd.adcL2Val/SYS_TICKS_PER_LEVEL_UPDATE; if (snd.adcL1AvgVal > snd.adcL1Thresh) { L1_is_high = true; } if (snd.adcL2AvgVal > snd.adcL2Thresh) { L2_is_high = true; } // Level Logic // L1 ADC reading Low+L2 ADC High= butter full // L1 ADC reading high+L2 ADC high= butter half full // L1 ADC reading high +L2 ADC low= butter empty if (!L1_is_high && L2_is_high) { snd.LevelStatus = SH_LEVEL_STATUS_FULL; } else if (L1_is_high && L2_is_high) { snd.LevelStatus = SH_LEVEL_STATUS_HALF_FULL; } else if (L1_is_high && !L2_is_high) { snd.LevelStatus = SH_LEVEL_STATUS_EMPTY; } Log_User_SetLev(snd.LevelStatus); Log_User_SetL1Adc(snd.adcL1AvgVal); Log_User_SetL2Adc(snd.adcL2AvgVal); // printf("\r\n%03d: L1 ADC VAL: 0x%03x, L2 ADC VAL: 0x%03x\r\n", snd.adcLevelMeasCount, snd.adcL1AvgVal, snd.adcL2AvgVal); snd.adcL1Val = 0; snd.adcL2Val = 0; snd.adcLevelMeasCount++; } // Read Tilt Status BSP_ACCELERO_GetXYZ(data_XYZ); // If the angle is too high, then set tilt snd.TiltStatus = ComputeTilt(data_XYZ); #ifdef USE_STM32F4_SPRAYER // Read Chamber Status chamberBit = BSP_GpioRead(GP_CHAMB); if (chamberBit == GPIO_PIN_SET) { snd.TiltStatus = SH_CHAMBER_STATUS_CLOSED; } else { snd.ChamberStatus = SH_CHAMBER_STATUS_OPEN; } #endif }