/* Soil Sensor Firmware * Light Measurement & LED Status Indication * Sensiplicity Systems * * Copyright 2015 * * Department of Botany and Plant Pathology * Center for Genome Research and Biocomputing * Oregon State University * Corvallis, OR 97331 * * This program is not free software; you can not redistribute it and/or * modify it at all. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include /* This module measures ambient light and provides state indication * via the LED on the top of the soil sensor. To measure light, * the photodiode is reverse biased, charging the capacitor in parallel with it. * The pins connected to it are placed in a high impedance state * and the time taken for the photo current to discharge the * capacitor is measured with TIM1. */ /* Set the LED state. This function will only set * LED_OFF, LED_RED, and LED_GREEN. * This function can be safely called while a measurement is * in progress; the state will be set when the measurement is * complete. */ enum led_state_t {LED_OFF, LED_RED, LED_GREEN, LED_MEASURING}; void set_led(enum led_state_t state); /* Setup pins for the LED. */ void init_led(void); /* Perform a light measurement. This function returns * immediately, but the measurement can take up to * 260 ms to complete. * If result is not NULL, it will be set to the result of the measurement. */ void measure_light(uint16_t volatile *result); /* Get the result of a previous light measurement. * A low value indicates bright light. * If no previous measurement is available, or if a measurement * is in progress, 0 is returned. */ uint16_t read_light(void);