コード例 #1
0
ファイル: ADC.c プロジェクト: FitnessMonitor/Fitness-Monitor
extern void ADC_start_single_conversion()
{
	//start an ADC
	ADC_enable();	
	ADC_interrupt_enable();
	ADC_start_conversion();
}
コード例 #2
0
ファイル: main.c プロジェクト: sufzoli/suf-electronics-tm001
void _worker()
{
	unsigned int temp;
	ADC_refon();	// Start ADC reference, the temp readout and the display will give enough time to stabilize
	temp = MCP9808_read_temp();	// Read actual temperature value

	// Multiple by 10 then shift right 4 bits
	temp = (temp << 2) + temp; // * 5
	temp >>= 3;	// *2, shift right 4 bits

    lcd35_write(temp);	// Write the temperature value to the LCD

    if(ADC_value < 550)		// The supply voltage is below ~2,7V
    {
    	LCDFL |= LCD_LOW_BAT;	// Switch on the Low Battery indicator
    }
    else
    {
		LCDFL &= ~LCD_LOW_BAT;	// switch of the Low Battery indicator
    }

    lcd35_send();	// send the data to the LCD
    ADC_start_conversion();	// start the ADC conversion cycle
}
コード例 #3
0
void inline radio_state() {
	if (init) {
		schedule_insert(system_schedule, 0, ms_clock, get_time);
		schedule_insert(system_schedule, 0, ms_clock, get_rbds);
		schedule_insert(system_schedule, 0, ms_clock, get_status);
		schedule_insert(system_schedule, 0, ms_clock, display_radio_screen);
		schedule_insert(system_schedule, 0, ms_clock, display_radio_channel);
		schedule_insert(system_schedule, 0, ms_clock, display_rbds_information);
		schedule_insert(system_schedule, 0, ms_clock, start_ADC_conversion);
		
		if (!radio_is_on) {		
			si4705_power_on();
			si4705_set_channel(channel);
			set_volume(ADC_values[0]);
		}
		radio_is_on = true;
		what_the_beep = false;
		nokia5110_clear();
		wd_clock = 0; //second counter
		#ifndef USING_PRINTF
		PORTD &= ~_BV(0); // Turn the radio LED on
		PORTD |= _BV(1); // Turn the stereo status LED off
		#endif
	}
	if(bns[0]) {
		bns[0] = false;
		if (radio_activity == 1) {
			channel -= 2;
			if (channel%2 == 0) {
				channel += 1;
			}
			if (channel < SI4705_FM_LOW) channel = SI4705_FM_HIGH;
			si4705_set_channel(channel);
			clear_radio_strings();
		}
		radio_activity = 1;
		wd_clock = 0; //reset activity
		schedule_insert(system_schedule, 200, ms_clock, button_down);
	}
	if(bns[1]) {
		bns[1] = false;
		eeprom_update_word(&saved_channel, channel);
		state = menu;
	}
	if(bns[2]) {
		//printf("I was pressed up\n");
		bns[2] = false;
		if (radio_activity == 2) {
			channel += 2;
			if (channel%2 == 0) {
				channel -= 1;
			}
			if (channel < SI4705_FM_LOW) channel = SI4705_FM_HIGH;
			si4705_set_channel(channel);
			clear_radio_strings();
		}
		radio_activity = 2;
		wd_clock = 0; //reset activity
		////printf("event scheduled\n");
		schedule_insert(system_schedule, 200, ms_clock, button_up);
	}
	if (event_is_ready) {
		switch(next_event.id) {
			case start_ADC_conversion:
				ADC_start_conversion();
				set_brightness(photo_avg/PHOTO_AVG_RESOLUTION);
				set_volume(ADC_values[0]);
				schedule_insert(system_schedule, 20, ms_clock, start_ADC_conversion);
				break;
			
			case get_time:
				ds1307_getdate_s(&time);
				schedule_insert(system_schedule, 1000, ms_clock, get_time);
				//printf("%d:%d:%d\n", time.hour, time.minute, time.second);
				break;
			
			case get_rbds:
				si4705_get_rdbs(station_text, scroll_text);
				schedule_insert(system_schedule, 200, ms_clock, get_rbds);
				break;
			
			case get_status:
				si4705_get_tune_status(&radio_tune_status);
				si4705_get_rsq_status(&radio_rsq_status);
				channel = radio_tune_status.tuneFrequency;
				//printf("%u\n", channel);
				schedule_insert(system_schedule, 100, ms_clock, get_status);
				break;
			
			case display_radio_screen:
				nokia5110_gotoXY(14,0);
				snprintf(line, 10, "%02d:%02d %s", time.hour - 12*(time.hour>12), time.minute, time.hour<12?"am":"pm");
				nokia5110_writeString(line);
				
				schedule_insert(system_schedule, 1000, ms_clock, display_radio_screen);
				break;
			
			case display_radio_channel:
				nokia5110_gotoXY(8-8*(channel>=1000),1);
				snprintf(line, 8, " %d.%d ", channel/10, channel%10);
				nokia5110_writeString_megaFont(line);
				
				nokia5110_gotoXY(0, 2);
				snprintf(line, 2, "%c", 124+(ADC_values[0]>80)+(ADC_values[0]>180));
				nokia5110_writeString(line);
				
				nokia5110_gotoXY(0, 3);
				snprintf(line, 2, "%c", 128 + (radio_rsq_status.rssi>22) + (radio_rsq_status.rssi>35));
				nokia5110_writeString(line);
				
				nokia5110_gotoXY(70, 3);
				snprintf(line, 3, "%s", radio_rsq_status.pilot?"st":"  ");
				nokia5110_writeString(line);
				
				#ifndef USING_PRINTF
				if (radio_rsq_status.pilot) {
					PORTD &= ~(_BV(1)); // Turn the stereo status on
				} else {
					PORTD |= _BV(1); // Turn the stereo status off
				}
				#endif
				
				schedule_insert(system_schedule, 100, ms_clock, display_radio_channel);
				break;
			
			case display_rbds_information:
				rbds_pixel_offset = (rbds_pixel_offset+1) % 7;
				if (rbds_pixel_offset == 0) {
					text_index = (text_index + 1) % (strlen(scroll_text));
				}
				if (strlen(scroll_text) > DISPLAY_OFFSET+1) { // we have a radio string
					nokia5110_gotoXY(0,5);
					nokia5110_writeString_L(&scroll_text[text_index], rbds_pixel_offset);
					//nokia5110_writeString_C(&scroll_text[text_index]);
				} else if (strlen(station_text) > 0) { // we don't have a radio string, but we have program service!
					snprintf(line, 12, "%s            ", station_text);
					nokia5110_gotoXY(14,5);
					nokia5110_writeString_C(line);
				} else { // we got nothing
					nokia5110_gotoXY(0,5);
					nokia5110_writeString("            ");
				}
				
				schedule_insert(system_schedule, 100, ms_clock, display_rbds_information);
				break;
			
			case button_down:
				if (hol[0]) {
					si4705_seek(DOWN);
					clear_radio_strings();
				} else {
					channel -= 2;
					if (channel%2 == 0) {
						channel += 1;
					}
					if (channel < SI4705_FM_LOW) channel = SI4705_FM_HIGH;
					si4705_set_channel(channel);
					clear_radio_strings();
				}
				radio_activity = 0;
				break;
			
			case button_up:
				//printf("handling event - ");
				if (hol[2]) {
					//printf("you were holding\n");
					si4705_seek(UP);
					clear_radio_strings();
				} else {
					//printf("you were tapping\n");
					channel += 2;
					if (channel%2 == 0) {
						channel -= 1;
					}
					if (channel > SI4705_FM_HIGH) channel = SI4705_FM_LOW;
					si4705_set_channel(channel);
					clear_radio_strings();
				}
				radio_activity = 0;
				break;
			
			default:
				break;
		}
	}
	
	if (wd_clock == 3599) {
		state = last_state;
	}
}
コード例 #4
0
void inline preset_state() {
	if (init) {
		schedule_insert(system_schedule, 0, ms_clock, start_ADC_conversion);
		
		menu_index = 0;
		nokia5110_clear();
		
		for (err = 0; err < NUMBER_OF_PRESETS; err++) {
			nokia5110_gotoXY(0, err);
			snprintf(line, 12, " %u.%u", presets[err]/10, presets[err]%10);
			nokia5110_writeString(line);
		}
		nokia5110_gotoXY(0,0);
		nokia5110_writeString(">");
		nokia5110_gotoXY(0,5);
		nokia5110_writeString(" Back");
	}
	if (bns[0]) {
		bns[0] = false;
		nokia5110_gotoXY(0, menu_index);
		nokia5110_writeString(" ");
		menu_index = (menu_index+1) % 6;
		nokia5110_gotoXY(0, menu_index);
		nokia5110_writeString(">");
		wd_clock = 0; // reset activity
		watchdog_feed();
	}
	if (bns[1]) {
		bns[1] = false;
		if(menu_index == 5) {
			state = last_state;
		} else {
			// choose preset
			if (last_state == home) {
				nokia5110_gotoXY(0,menu_index);
				nokia5110_writeString(" ");
				err = set_preset_variable(menu_index);
				if (err) {
					state = last_state;
				}
				nokia5110_gotoXY(0,menu_index);
				snprintf(line, 12, ">%u.%u", presets[menu_index]/10, presets[menu_index]%10);
				nokia5110_writeString(line);
			} else {	
				if (channel != presets[menu_index]) {
					channel = presets[menu_index];
					si4705_set_channel(channel);
					clear_radio_strings();
				}
				state = radio;
			}
		}
	}
	if (bns[2]) {
		bns[2] = false;
		nokia5110_gotoXY(0, menu_index);
		nokia5110_writeString(" ");
		menu_index = (menu_index+5) % 6;
		nokia5110_gotoXY(0, menu_index);
		nokia5110_writeString(">");
		wd_clock = 0; //reset activity
		watchdog_feed();
	}
	if (event_is_ready) {
		switch(next_event.id) {
			case start_ADC_conversion:
				ADC_start_conversion();
				set_brightness(photo_avg/PHOTO_AVG_RESOLUTION);
				schedule_insert(system_schedule, 20, ms_clock, start_ADC_conversion);
				break;
			
			default:
				break;
		}
	}
	if(wd_clock == 60) {
		wd_clock = 0;
		state = last_state;
	}
}
コード例 #5
0
void inline alarm_state() {
	if (init) {
		nokia5110_clear();
		nokia5110_drawSplash();
		
		schedule_insert(system_schedule, 0, ms_clock, get_time);
		schedule_insert(system_schedule, 0, ms_clock, start_ADC_conversion);
		
		if (state == alarm_A) {
			if (alarm_A_is_beep) {
				radio_is_on = false;
				what_the_beep = true;
				schedule_insert(system_schedule, 250, ms_clock, beep_off);
			} else {
				#ifndef USING_PRINTF
				PORTD &= ~_BV(0); // Turn the radio LED on
				#endif
				
				what_the_beep = false;
				radio_is_on = true;
				si4705_power_on();
				si4705_set_channel(channel);
				schedule_insert(system_schedule, 100, ms_clock, radio_volume_change);
			}
		} else {
			if (alarm_B_is_beep) {
				radio_is_on = false;
				what_the_beep = true;
				schedule_insert(system_schedule, 250, ms_clock, beep_off);
			} else {
				#ifndef USING_PRINTF
				PORTD &= ~_BV(0); // Turn the radio LED on
				#endif
				
				what_the_beep = false;
				radio_is_on = true;
				si4705_power_on();
				si4705_set_channel(channel);
				schedule_insert(system_schedule, 100, ms_clock, radio_volume_change);
			}
		}
		err = 25;
		set_volume(25);
		wd_clock = 0;
	}
	if(bns[0] || bns[2]) { // sleep
		bns[0] = bns[2] = false;
		if (state==alarm_A) {
			time_alarm_A.hour = time.hour;
			time_alarm_A.minute = time.minute + ALARM_SLEEP_TIME;
			if (time_alarm_A.minute >= 60) {
				time_alarm_A.minute -= 60;
				time_alarm_A.hour += 1;
				if (time_alarm_A.hour >= 24) {
					time_alarm_A.hour -= 24;
				}
			}
		}
		if (state==alarm_B) {
			time_alarm_B.hour = time.hour;
			time_alarm_B.minute = time.minute + ALARM_SLEEP_TIME;
			if (time_alarm_B.minute >= 60) {
				time_alarm_B.minute -= 60;
				time_alarm_B.hour += 1;
				if (time_alarm_B.hour >= 24) {
					time_alarm_B.hour -= 24;
				}
			}
		}
		state = last_state;
	}
	if(bns[1] || ((state == alarm_A) && !hol[3]) || ((state == alarm_B) && !hol[4])) { // silence....... or did we have that backwards
		bns[1] = false;
		if (state==alarm_A) {
			alarm_A_went_off_today = true;
		}
		if (state==alarm_B) {
			alarm_B_went_off_today = true;
		}
		state = last_state;
	}
	if (event_is_ready) {
		switch(next_event.id) {
			case start_ADC_conversion:
				ADC_start_conversion();
				set_brightness(photo_avg/PHOTO_AVG_RESOLUTION);
				schedule_insert(system_schedule, 20, ms_clock, start_ADC_conversion);
				break;
			
			case get_time:
				ds1307_getdate_s(&time);
				schedule_insert(system_schedule, 1000, ms_clock, get_time);
				break;
			
			case radio_volume_change:
				if (err < 175 || err < ADC_values[0]) {
					err ++;
					set_volume(err);
				} else {
					if (ADC_values[0] > 175) {
						set_volume(ADC_values[0]);
					} else {
						set_volume(175);
					}
				}
				schedule_insert(system_schedule, 100, ms_clock, radio_volume_change);
				break;
			
			case beep_off:
				set_volume(0);
				schedule_insert(system_schedule, 500, ms_clock, beep_on);
				break;
				
			case beep_on:
				if (err < 175 || err < ADC_values[0]) {
					err += 5;
					set_volume(err);
				} else {
					if (ADC_values[0] > 175) {
						set_volume(ADC_values[0]);
					} else {
						set_volume(175);
					}
				}
				schedule_insert(system_schedule, 250, ms_clock, beep_off);
				break;
			
			default:
				break;
		}
	}
	if (wd_clock == 3599) {
		if (state==alarm_A) {
			alarm_A_went_off_today = true;
		}
		if (state==alarm_B) {
			alarm_B_went_off_today = true;
		}
		state = last_state;
	}
}
コード例 #6
0
void inline menu_state() {
	if (init) {
		schedule_insert(system_schedule, 0, ms_clock, start_ADC_conversion);
		
		menu_index = 0;
		nokia5110_clear();
		nokia5110_gotoXY(0,0);
		if (last_state == home) {
			nokia5110_writeString(">Radio");
		} else {
			nokia5110_writeString(">Radio Off");
		}
		nokia5110_gotoXY(0,1);
		nokia5110_writeString(" Time-Set");
		nokia5110_gotoXY(0,2);
		nokia5110_writeString(" Set AlarmA");
		nokia5110_gotoXY(0,3);
		nokia5110_writeString(" Set AlarmB");
		nokia5110_gotoXY(0,4);
		if (last_state == home) {
			nokia5110_writeString(" Set Presets");
		} else {
			nokia5110_writeString(" FM Presets");
		}
		
		nokia5110_gotoXY(0,5);
		nokia5110_writeString(" Back");
	}
	if (bns[0]) {
		bns[0] = false;
		nokia5110_gotoXY(0, menu_index);
		nokia5110_writeString(" ");
		menu_index = (menu_index+1) % 6;
		nokia5110_gotoXY(0, menu_index);
		nokia5110_writeString(">");
		wd_clock = 0; //reset activity
		watchdog_feed();
	}
	if(bns[1]) {
		bns[1] = false;
		switch(menu_index) {
			case 0:
				if (last_state == home) {
					state = radio; 
				} else {
					state = home; 
				} 
				break;
			case 1:
				state = set_clock; break;
			case 2:
				state = set_alarm_A; break;
			case 3:
				state = set_alarm_B; break;
			case 4:
				state = preset; break;
			default: 
				state = last_state; break;
		}	
	}
	if (bns[2]) {
		bns[2] = false;
		nokia5110_gotoXY(0, menu_index);
		nokia5110_writeString(" ");
		menu_index = (menu_index+5) % 6;
		nokia5110_gotoXY(0, menu_index);
		nokia5110_writeString(">");
		wd_clock = 0; //reset activity
		watchdog_feed();
	}
	if (event_is_ready) {
		switch(next_event.id) {
			case start_ADC_conversion:
				ADC_start_conversion();
				set_brightness(photo_avg/PHOTO_AVG_RESOLUTION);
				schedule_insert(system_schedule, 20, ms_clock, start_ADC_conversion);
				break;
			
			default:
				break;
		}
	}
	if(wd_clock == 60) {
		wd_clock = 0;
		state = last_state;
	}
}
コード例 #7
0
void inline home_state() {
	if (init) {
		schedule_insert(system_schedule, 0, ms_clock, get_time);
		schedule_insert(system_schedule, 0, ms_clock, display_home_screen);
		schedule_insert(system_schedule, 0, ms_clock, display_temp_and_alarm_settings);
		schedule_insert(system_schedule, 0, ms_clock, start_ADC_conversion);
		
		nokia5110_clear();
		if (radio_is_on) {
			si4705_power_off();
			radio_is_on = false;
		}
		what_the_beep = false;
		set_volume(0);
		
		#ifndef USING_PRINTF
		PORTD |= _BV(0); // Turn the radio LED off
		PORTD |= _BV(1); // Turn the stereo status LED off
		#endif
	}
	if(bns[0]) {
		bns[0] = false;
	}
	if(bns[1]) {
		bns[1] = false;
		state = menu;
	}
	if(bns[2]) {
		bns[2] = false;
	}
	if (event_is_ready) {
		switch(next_event.id) {
			case start_ADC_conversion:
				ADC_start_conversion();
				set_brightness(photo_avg/PHOTO_AVG_RESOLUTION);
				schedule_insert(system_schedule, 20, ms_clock, start_ADC_conversion);
				break;
		
			case get_time:
				ds1307_getdate_s(&time);
				err = ds1307_getdayofweek(time.year, time.month, time.day);
				schedule_insert(system_schedule, 1000, ms_clock, get_time);
				//printf("%d:%d:%d\n", time.hour, time.minute, time.second);
				break;
		
			case display_home_screen:
				snprintf(line, 12, "%02d:%02d", time.hour - 12*(time.hour>12), time.minute);
				nokia5110_gotoXY(12,1);
				nokia5110_writeString_megaFont(line);
		
				snprintf(line, 12, " %s  ", days_of_week[err]);
				nokia5110_gotoXY(day_pixel_offsets[err],0);
				nokia5110_writeString(line);
		
				snprintf(line, 12, "%s", time.hour<12?"am":"pm");
				nokia5110_gotoXY(68,3);
				nokia5110_writeString(line);
		
				snprintf(line, 9, "%d/%d/%d   ", time.month, time.day, time.year);
				nokia5110_gotoXY(0,4);
				nokia5110_writeString(line);
		
				schedule_insert(system_schedule, 1000, ms_clock, display_home_screen);
				break;
		
			case display_temp_and_alarm_settings:
				init = false;
				snprintf(line, 8, "%02d.%01d%cF  ", (uint8_t)(temperature_avg/THERM_AVG_RESOLUTION/10), (uint8_t)(temperature_avg/THERM_AVG_RESOLUTION%10), 123);
				nokia5110_gotoXY(0,5);
				nokia5110_writeString(line);
			
				nokia5110_gotoXY(63,4);
				if (hol[3]) {
					snprintf(line, 4, "A:%c", alarm_A_is_beep?124+(ADC_values[0]>80)+(ADC_values[0]>180):127);
				} else {
					snprintf(line, 4, "A: ");
				}
				nokia5110_writeString(line);
				nokia5110_gotoXY(63,5);
				if (hol[4]) {
					snprintf(line, 4, "B:%c", alarm_B_is_beep?124+(ADC_values[0]>80)+(ADC_values[0]>180):127);
				} else {
					snprintf(line, 4, "B: ");
				}
				nokia5110_writeString(line);
				schedule_insert(system_schedule, 100, ms_clock, display_temp_and_alarm_settings);
				break;
			
			default:
				break;
		}
	}
	watchdog_feed();
}