/* 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 "light.h" #include #include #ifndef BREV #error "No board revision specified. Please provide -DBREV=2 or -DBREV=4 on the command line." #endif #if BREV != 2 && BREV != 4 #error "Incorect board revision specified. Please provide -DBREV=2 or -DBREV=4 on the command line." #endif static volatile enum led_state_t LedState, RequestedState; #if BREV == 2 /* Set the led to a visible state. */ void set_led(enum led_state_t state){ /* Turn the anode on. */ PORTD |= _BV(PD4); /* Turn LED off, then selectively turn on the required bits. */ PORTD |= _BV(PD3); PORTE |= _BV(PE0); switch (state){ case(LED_OFF): break; case(LED_GREEN): PORTE &= ~_BV(PE0); break; case(LED_RED): PORTD &= ~_BV(PD3); break; } } #elif BREV == 4 /* Set the led to a visible state. */ void set_led(enum led_state_t state){ init_led(); /* Turn the anode on. */ DDRD |= _BV(PD4); PORTD |= _BV(PD4); /* Make the photodiode high impedance. */ DDRD &= ~_BV(PD3); DDRE |= _BV(PE0); if(state == LED_GREEN || state == LED_RED){ PORTE &= ~_BV(PE0); } else { PORTE |= _BV(PE0); } } #endif /* Setup pins for the LED. */ void init_led(void){ DDRD |= _BV(PD4); DDRD |= _BV(PD3); DDRE |= _BV(PE0); }