/************************************************************************* Function: getJoystick() Purpose: Gets the X and Y (Pitch and Roll) Joystick data Input: None Returns: None **************************************************************************/ void getJoystick(void){ int adcval; // get right X (Roll) F1 adcval = 512-get_adc(1); if(adcval > -4 && adcval <4){ outgoing.roll = 0; }else{ outgoing.roll = adcval; } // get right Y (Pitch) F0 adcval = get_adc(0) - 512; if(adcval > -4 && adcval <4){ outgoing.pitch = 0; }else{ outgoing.pitch = adcval; } // get left X (Yaw) F5 adcval = 512-get_adc(5); if(adcval > -4 && adcval <4){ outgoing.yaw = 0; }else{ outgoing.yaw = adcval; } // get left Y (Throttle) F4 adcval = get_adc(4); if(adcval > 512){ outgoing.throttle = adcval-512; }else{ outgoing.throttle = 0; } }
void get_wave() { uint16_t i; for(i=0; i < WAVE_LENGTH; ) { start_adc(0); wave[i++] = get_adc(); start_adc(1); wave[i++] = get_adc(); } }
static int parse_input(struct hda_codec *codec) { struct cs_spec *spec = codec->spec; struct auto_pin_cfg *cfg = &spec->autocfg; int i; for (i = 0; i < AUTO_PIN_LAST; i++) { hda_nid_t pin = cfg->input_pins[i]; if (!pin) continue; spec->input_idx[spec->num_inputs] = i; spec->capsrc_idx[i] = spec->num_inputs++; spec->cur_input = i; spec->adc_nid[i] = get_adc(codec, pin, &spec->adc_idx[i]); } if (!spec->num_inputs) return 0; /* check whether the automatic mic switch is available */ if (spec->num_inputs == 2 && spec->adc_nid[AUTO_PIN_MIC] && spec->adc_nid[AUTO_PIN_FRONT_MIC]) { if (is_ext_mic(codec, cfg->input_pins[AUTO_PIN_FRONT_MIC])) { if (!is_ext_mic(codec, cfg->input_pins[AUTO_PIN_MIC])) { spec->mic_detect = 1; spec->automic_idx = AUTO_PIN_FRONT_MIC; } } else { if (is_ext_mic(codec, cfg->input_pins[AUTO_PIN_MIC])) { spec->mic_detect = 1; spec->automic_idx = AUTO_PIN_MIC; } } } return 0; }
static int parse_input(struct hda_codec *codec) { struct cs_spec *spec = codec->spec; struct auto_pin_cfg *cfg = &spec->autocfg; int i; for (i = 0; i < cfg->num_inputs; i++) { hda_nid_t pin = cfg->inputs[i].pin; spec->input_idx[spec->num_inputs] = i; spec->capsrc_idx[i] = spec->num_inputs++; spec->cur_input = i; spec->adc_nid[i] = get_adc(codec, pin, &spec->adc_idx[i]); } if (!spec->num_inputs) return 0; /* check whether the automatic mic switch is available */ if (spec->num_inputs == 2 && cfg->inputs[0].type == AUTO_PIN_MIC && cfg->inputs[1].type == AUTO_PIN_MIC) { if (is_ext_mic(codec, cfg->inputs[0].pin)) { if (!is_ext_mic(codec, cfg->inputs[1].pin)) { spec->mic_detect = 1; spec->automic_idx = 0; } } else { if (is_ext_mic(codec, cfg->inputs[1].pin)) { spec->mic_detect = 1; spec->automic_idx = 1; } } } return 0; }
// SET CALIB. VALUES //input: // s Sensor structure. // index Point to a specific sensor. //description: // function devoted to set each (x,y) // point to be used in the linear // regression. //------------------------------------------- static void set_calib_values(sensor s,unsigned int index) { unsigned int j; float v,w; for(j=0;j<NKVAL;j++){ w=0.0; v=0.0; while(OK==0){ get_adc(s); v=(float) s[index].adc*5/1023; w=counter(w); glcd_rect(0,10,90,30,YES,OFF); sprintf(text,"X[%d]= %.1f gr",j+1,w); glcd_text57(0,10, text,1,ON); sprintf(text,"Y[%d]= %.1f V ",j+1,v); glcd_text57(0,20, text,1,ON); #ifdef FAST_GLCD glcd_update(); #endif } load[j]=w; voltage[j]=v; delay_ms(600); } }
void get_sync_wave(uint8_t ch) { uint16_t i,w1,w2; start_adc(0); w1 = get_adc(); for(;;) { start_adc(0); w2 = get_adc(); if(w1 < 512-10 && w2 > 512-10) break; w1 = w2; } for(i=0; i < WAVE_LENGTH; ) { start_adc(ch); wave[i++] = get_adc(); } }
//读取键盘 uint scan_key() { uint key_flag; uint value = 0; float vol; P2DIR &= ~0x01; if (P2_0 == 1) { delay_ms(3); if (P2_0 == 1) { value = get_adc(); vol = (float)value/(float)2048*3.3; if ((vol<0.4) && (vol>0.2)) { key_flag = 0; } if ((vol<1.4) && (vol>1.1)) { key_flag = 1; } if ((vol<1.8) && (vol>1.6)) { key_flag = 2; } if ((vol<2.1) && (vol>1.9)) { key_flag = 3; } } } return key_flag; }
void adc_channel_select(int channel){ if ((channel <= 5) && (channel >= 0)) { // set the channel in ADMUX register; left-align result ADMUX = channel | _BV(ADLAR); // discard the first conversion get_adc(); } }
int lightsensor_get_adcvalue(void) { int i = 0; int j = 0; unsigned int adc_total = 0; static int adc_avr_value = 0; unsigned int adc_index = 0; static unsigned int adc_index_count = 0; unsigned int adc_max = 0; unsigned int adc_min = 0; int value =0; //get ADC //value = s3c_adc_get_adc_data(ADC_CHANNEL); /* Delay is added for bit late response , to make similar to vinsq model , if not necessary can be removed, sensor response will be fast */ /* If below delay is there , AT factory commands fail , so commented the delay */ // mdelay(200); value = get_adc(); //value = 1000; //temparary, adc value is controled in CP, //check Modem/products/76xx/services/mproc/smem/smem_ext_pc.c, "get_batt_adc();" in europa_battery.c gprintk("adc = %d \n",value); cur_adc_value = value; adc_index = (adc_index_count++)%ADC_BUFFER_NUM; if(cur_state == LIGHT_INIT) //ADC buffer initialize (light sensor off ---> light sensor on) { for(j = 0; j<ADC_BUFFER_NUM; j++) adc_value_buf[j] = value; } else { adc_value_buf[adc_index] = value; } adc_max = adc_value_buf[0]; adc_min = adc_value_buf[0]; for(i = 0; i <ADC_BUFFER_NUM; i++) { adc_total += adc_value_buf[i]; if(adc_max < adc_value_buf[i]) adc_max = adc_value_buf[i]; if(adc_min > adc_value_buf[i]) adc_min = adc_value_buf[i]; } adc_avr_value = (adc_total-(adc_max+adc_min))/(ADC_BUFFER_NUM-2); if(adc_index_count == ADC_BUFFER_NUM-1) adc_index_count = 0; return adc_avr_value; }
u32 AO2(){ // getting data from ccd1 ao1 u32 temp; int get_times = 10; for(u8 i=0;i<get_times;i++){ temp += get_adc(2); } temp=(u32)(temp/get_times); return temp; }
static int parse_digital_input(struct hda_codec *codec) { struct cs_spec *spec = codec->spec; struct auto_pin_cfg *cfg = &spec->autocfg; int idx; if (cfg->dig_in_pin) spec->dig_in = get_adc(codec, cfg->dig_in_pin, &idx); return 0; }
//------------------------------------------------------------------------- uint16_t get_magy() { uint16_t reading; DDRC |= _BV(5); PORTC |= _BV(5); reading = get_adc(MAGY_CHANNEL); DDRC &= ~_BV(5); PORTC &= ~_BV(5); return reading; }
//------------------------------------------------------------------------- uint16_t get_accy() { uint16_t reading; DDRC |= _BV(4); PORTC |= _BV(4); reading = get_adc(ACCY_CHANNEL); DDRC &= ~_BV(4); PORTC &= ~_BV(4); return reading; }
//------------------------------------------------------------------------- uint16_t get_light() { uint16_t reading; PORTE &= ~_BV(6); DDRE &= ~_BV(6); PORTE |= _BV(5); DDRE |= _BV(5); reading = get_adc(LIGHT_CHANNEL); PORTE &= ~_BV(5); DDRE &= ~_BV(5); return reading; }
//------------------------------------------------------------------------- uint16_t get_temp() { uint16_t reading; PORTE &= ~_BV(5); DDRE &= ~_BV(5); PORTE |= _BV(6); DDRE |= _BV(6); reading = get_adc(TEMP_CHANNEL); PORTE &= ~_BV(6); DDRE &= ~_BV(6); return reading; }
static ssize_t muic_show_adc(struct device *dev, struct device_attribute *attr, char *buf) { muic_data_t *pmuic = dev_get_drvdata(dev); int ret; mutex_lock(&pmuic->muic_mutex); ret = get_adc(pmuic); mutex_unlock(&pmuic->muic_mutex); if (ret < 0) { pr_err("%s:%s err read adc reg(%d)\n", MUIC_DEV_NAME, __func__, ret); return sprintf(buf, "UNKNOWN\n"); } return sprintf(buf, "%x\n", ret); }
void main(void){ M8C_EnableGInt; M8C_EnableIntMask(INT_MSK0, INT_MSK0_GPIO); I2CHW_Start(); I2CHW_EnableSlave(); I2CHW_EnableInt(); AMUX4_Start(); PGA_1_Start(PGA_1_HIGHPOWER); ADCINC_Start(ADCINC_HIGHPOWER); TX8_Start(TX8_PARITY_NONE); LED_DBG_ON(); TX8_CPutString("I2C slave addr:0x"); TX8_PutSHexByte(I2CHW_SLAVE_ADDR); TX8_PutCRLF(); LED_DBG_OFF(); for(;;){ // I2C i2c_status = I2CHW_bReadI2CStatus(); if(i2c_status & I2CHW_WR_COMPLETE){ // master->slave I2CHW_ClrWrStatus(); I2CHW_InitWrite(buf_rx, BUF_SIZE); } if(i2c_status & I2CHW_RD_COMPLETE){ // slave->master I2CHW_ClrRdStatus(); I2CHW_InitRamRead(buf_tx, BUF_SIZE); } // ADC for(ad_pin = 0; ad_pin < 4; ad_pin++){ ad = get_adc(ad_pin); weights[ad_pin] = ad; TX8_PutChar(ad_pin+'0'); TX8_CPutString(":"); TX8_PutString(intToStr(ad,buf)); TX8_PutCRLF(); } buf_tx[0] = 'a'; buf_tx[1] = 'b'; buf_tx[2] = 'c'; buf_tx[3] = 'd'; } }
/* get ADC Value */ int get_avg_adc(){ int sum = 0; int avg; int i = 0; for(i=0; i < 10; i++){ adc_data[i%5] = get_adc(); sum += adc_data[i%5]; } avg = sum/10; //_serial_write((unsigned char)(avg+0x30)); return avg; }
// вспомогательная служебная задача static void prvFlashTask( void *pvParameters ) { static unsigned short s_tmr=0; static float adc_res = 0; static unsigned short adc_max[8]; static unsigned short adc_min[8]; static unsigned short cur_adc = 0; unsigned char tmp; init_adc();init_dac(); // инициализация ацп и цап update_code(); // обновление кодового слова в FRAM FLLastExecutionTime = xTaskGetTickCount(); for( ;; ) { // фильтр АЦП if(emu_mode==0){ for(tmp=0;tmp<8;tmp++) { cur_adc = get_adc(tmp); if(s_tmr % 8 == 0) {adc_min[tmp]=adc_max[tmp]=cur_adc;} adc_sum[tmp]+=cur_adc; if(cur_adc<adc_min[tmp]) adc_min[tmp] = cur_adc; if(cur_adc>adc_max[tmp]) adc_max[tmp] = cur_adc; } s_tmr++; if(s_tmr % 8 == 0) { for(tmp=0;tmp<8;tmp++) { adc_res=(adc_sum[tmp]-adc_min[tmp]-adc_max[tmp])*16.0/(8-2)*adc_coeff+0.5; adc_sum[tmp]=0; if(adc_res>65535) adc_res=65535;_Sys_ADC[tmp]=adc_res; } } } if((s_tmr%64)==0) {get_time();toggle_led();} // обновление текущего времени и мигание светодиода vTaskDelayUntil( &FLLastExecutionTime, mainFLASH_DELAY ); } }
int main (void) { char temp; short b; ioinit(); //Setup IO pins and defaults USART_Init(10);//set up for 115200 rprintf_devopen(put_char); /* init rrprintf */ for (b = 0; b < 5; b++) { PORTB &= (~(1<<STAT));//stat on delay_ms(50); PORTB |= (1<<STAT);//stat off delay_ms(50); } asc = 0; auto_run = 0; //check for existing preset values============================================================== temp = EEPROM_read((unsigned int)FREQ_HIGH); if (temp == 255)//unwritten { cli();//Disable Interrupts EEPROM_write((unsigned int) FREQ_LOW, 100);//100Hz EEPROM_write((unsigned int) FREQ_HIGH, 0); EEPROM_write((unsigned int) SENSE_AR_MODE, 0);//1.5g, auto-run off, binary output EEPROM_write((unsigned int) ACT_CHAN, 0x3F);//all channels active sei();//Enable Interrupts freq = 100; asc = 0;//binary auto_run = 0;//auto run off //set for 1.5g sensitivity PORTB &= (~((1<<GS1) | (1<<GS2)));//GS1 low, GS2 low } //get presets else { b = EEPROM_read((unsigned int)FREQ_HIGH); b <<= 8; b |= EEPROM_read((unsigned int)FREQ_LOW); freq = (float)b; active_channels = EEPROM_read((unsigned int)ACT_CHAN); temp = EEPROM_read((unsigned int)SENSE_AR_MODE); if (temp & 0x08) PORTB |= (1<<GS2);//GS2 High if (temp & 0x04) PORTB |= (1<<GS1);//GS2 High if (temp & 0x02) auto_run = 1; if (temp & 0x01) asc = 1; } //main loop================================================================== while(1) { if (auto_run == 1) { while(1) { //This is the sampling loop. It runs in get_adc() until somebody stops it. get_adc(); //If it dumps out of the sampling loop, go to the config menu. config_menu(); //Bail out if auto run is off. if (auto_run == 0) break; } } if (UCSR0A & (1<<RXC0))//if something comes in... { temp = UDR0; if (temp == 35) //# to run { asc = 0; get_adc(); } else if (temp == 37) //% to set range to 1.5g { //set for 1.5g sensitivity PORTB &= (~((1<<GS1) | (1<<GS2)));//GS1 low, GS2 low } else if (temp == 38) //& to set range to 2g { PORTB |= (1<<GS1);//GS1 High PORTB &= (~(1<<GS2));//GS2 low } else if (temp == 39) //' to set range to 4g { PORTB &= (~(1<<GS1));//GS1 low PORTB |= (1<<GS2);//GS2 High } else if (temp == 40) //( to set range to 6g { PORTB |= ((1<<GS1) | (1<<GS2));//GS1, GS2 high } else if (temp == 41) freq = 50; //) to run at 50Hz else if (temp == 42) freq = 100;// to run at 100Hz else if (temp == 43) freq = 150;//+ to run at 150Hz else if (temp == 44) freq = 200;//, to run at 200Hz else if (temp == 45) freq = 250;//- to run at 250Hz else if (temp == 32) // { while(1) { config_menu(); if (auto_run == 0) break; get_adc(); } } temp = 0; } } while(1); }
// SENSOR TEST ROUTINE //input: // s Sensor structure. //description: // This function perform a test to // each sensor. // First, it asks to the user to connect // all the sensors, then it checks for the // value read in all the ADC channels and // compares these values with those stored // in the EEPROM memory. If the full scale // error is bigger than MAXERROR a warning // is displayed. //------------------------------------------- unsigned int test_calib(sensor s) { unsigned int op,k,i,j; unsigned int status[4]={0 0 0 0}; float Vx,error; intro: glcd_fillScreen(OFF); sprintf(text,"Conectar todos\n\r los sensores"); glcd_text57(9,0, text,1,ON); sprintf(text,"2-> Ejecutar."); glcd_text57(10,40, text,1,ON); sprintf(text,"3-> Atras."); glcd_text57(10,50, text,1,ON); op=0; j=0; command: // code to attend the user request. #ifdef FAST_GLCD glcd_update(); #endif delay_ms(200); while(op==0){ op=swap( PORTB & 0b00110000); } if(op==2) goto exit; if(op==1){ if(j) goto done; } test: delay_ms(2000); get_adc(s); // read all ADC channels. for(i=0;i<NCH;i++){ Vx = (float) s[i].adc*5.0/1023.0; // compare the read value and the stored value. error=fabs(Vx - s[i].b)/5.0; if(error >= MAXERROR) status[i]=1; } glcd_fillScreen(OFF); // display warning menssage sprintf(text,"Recalibrar Sensores\a"); glcd_text57(0,0, text,1,ON); sprintf(text,"2-> Calibrar."); glcd_text57(10,40, text,1,ON); sprintf(text,"3-> Atras."); glcd_text57(10,50, text,1,ON); k=0; for(i=0;i<NCH;i++){ if(status[i]){ sprintf(text,"S%d",i+1); glcd_text57(10+k,20, text,1,ON); k+=20; } } j=1; op=0; goto command; done: return 0; exit: return 1; }
int main(void) { ini_lcd(); clr_lcd(); int ca = 0; int cb = 0; int aa=0; int ab=0; int ma=0; int mb=0; int mina=0; int minb=0; //ADMUX |= 71; //SET_BIT(ADMUX,6); //ADCSRA|=135; //SET_BIT(ADCSRA) //ADMUX=(1<<REFS0); // For Aref=AVcc; SET_BIT(ADMUX,6); //ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); //Prescalar div factor =128 ADCSRA|=135; //wait_avr(50000); //uint8_t ch=ch&0b00000111; //ADMUX|=ch; //ADCSRA|=(1<<ADSC); //ADCSRA|=(1<<ADEN); while(1) { //TODO:: Please write your application code pos_lcd(0,0); sprintf(beg,"A:Start Sampling"); puts_lcd2(beg); pos_lcd(1, 0); sprintf(beg,"B:reset"); puts_lcd2(beg); if(key_pressed(0, 7)) { while(1) { if(key_pressed(1, 7)) { result = 1; max=0; min=9999; average=0; total=0; count=0; clr_lcd(); break; } get_adc(); clr_lcd(); pos_lcd(0, 0); //int a,b; ca = result / 100; cb = result % 100; aa=average/100; ab=average%100; ma=max/100; mb=max%100; mina=min/100; minb=min%100; sprintf(beg,"Cr:%01d.%02d Mx:%01d.%02d",ca,cb,ma,mb);//(adc/1023)*5 puts_lcd2(beg); pos_lcd(1, 0); sprintf(beg,"Avg:%01d.%02d Mn:%01d.%02d",aa,ab,mina,minb); puts_lcd2(beg); wait_avr(500); } } } }
PROCESS_THREAD(blink_process, ev, data) { static struct etimer et_blink; etimer_set(&et_blink, CLOCK_SECOND); PROCESS_BEGIN(); static char lux_value[6]; static char lux_value2[6]; static char raw_value[6]; static char raw_value2[6]; static char temperature_val[6]; static uint16_t adc_data=0; static uint16_t adc_data2=0; static float adc_lux=0; static float adc_lux2=0; static float measured_temp=0; // static int blinks = 0; ssd1306_clear(); ssd1306_set_page_address(0); ssd1306_set_column_address(2); ssd1306_write_text("Lumen in Lux:"); ssd1306_set_page_address(1); ssd1306_set_column_address(2); ssd1306_write_text("Raw ADC out :"); ssd1306_set_page_address(2); ssd1306_set_column_address(2); ssd1306_write_text("Ambient Temperature measured:"); while(1) { PROCESS_WAIT_EVENT(); if (ev==PROCESS_EVENT_TIMER) { DDRB |=(1<<PORTB4); PORTB ^= (1<<PORTB4); adc_init(); adc_data=get_adc(0); adc_lux=adc_data*0.9765625; /* amps=adc_volt/10000.0; microamps=amps/1000000; lux_data=microamps*2; */ itoa(adc_lux, lux_value, 10); ssd1306_set_page_address(0); ssd1306_set_column_address(73); ssd1306_write_text(lux_value); itoa(adc_data, raw_value, 10); ssd1306_set_page_address(1); ssd1306_set_column_address(73); ssd1306_write_text(raw_value); adc_init_full(ADC_CHAN_ADC0, ADC_TRIG_FREE_RUN, ADC_REF_AVCC, ADC_PS_64); adc_conversion_start(); adc_lux2=adc_data2*0.9765626; itoa(adc_lux2, lux_value2, 10); ssd1306_set_page_address(0); ssd1306_set_column_address(95); ssd1306_write_text(lux_value2); itoa(adc_data2, raw_value2, 10); ssd1306_set_page_address(1); ssd1306_set_column_address(95); ssd1306_write_text(raw_value2); measured_temp=ReadTempVal(); itoa(measured_temp, temperature_val, 10); ssd1306_set_page_address(2); ssd1306_set_column_address(95); ssd1306_write_text(temperature_val); } } PROCESS_END(); }
void *adc_timefunc() { os_printf("AnalogInput = %d\r\n", get_adc()); }
int main (void) { char x, y, a, temp; //short a, b; float temp_y, temp_y2, temp_x; int q; //char a = 0; ioinit(); //Setup IO pins and defaults //USART_Init( MYUBRR); //rprintf_devopen(put_char); /* init rrprintf */ //reset the display delay_ms(1); PORTC |= (1<<RST); //initialize the display display_init(); clear_screen(); //Backlight on PORTB &= (~(1<<BL_EN)); //circle(1,80,-20,142); //circle(1,80,-20,70); for (x = 0; x < 160; x++) { //temp_y = ((sqrt((r^2) - ((x - 80)*(x - 80)))) - 20) temp_y = ((sqrt((23716) - ((x - 80)*(x - 80)))) - 30); temp_y2 = ((sqrt((23409) - ((x - 80)*(x - 80)))) - 30); //temp_y *= (-1); pixel(1, x, (char)(temp_y)); pixel(1, x, (char)(temp_y2)); } for (x = 0; x < 160; x++) { //temp_y = ((sqrt((r^2) - ((x - 80)*(x - 80)))) - 20) temp_y = ((sqrt((20164) - ((x - 80)*(x - 80)))) - 30); temp_y2 = ((sqrt((19881) - ((x - 80)*(x - 80)))) - 30); //temp_y *= (-1); pixel(1, x, (char)(temp_y)); pixel(1, x, (char)(temp_y2)); } for (x = 40; x < 120; x++) { temp_y = ((sqrt((4900) - ((x - 80)*(x - 80)))) - 30); temp_y2 = ((sqrt((4761) - ((x - 80)*(x - 80)))) - 30); //temp_y *= (-1); pixel(1, x, (char)(temp_y)); pixel(1, x, (char)(temp_y2)); } //======================================================================= /* for (x = 109; x < 158; x++) { temp_y = ((sqrt((19600) - ((x - 80)*(x - 80)))) - 30); temp_y2 = ((sqrt((19321) - ((x - 80)*(x - 80)))) - 30); //temp_y *= (-1); pixel(1, x, (char)(temp_y)); pixel(1, x, (char)(temp_y2)); } */ for (x = 108; x < 156; x++) { //temp_y = ((sqrt((19044) - ((x - 80)*(x - 80)))) - 30); temp_y2 = ((sqrt((18225) - ((x - 80)*(x - 80)))) - 30); //temp_y *= (-1); //pixel(1, x, (char)(temp_y)); pixel(1, x, (char)(temp_y2)); } line(1,0,87,40,27); line(1,1,87,41,27); line(1,120,27,159,87); line(1,119,27,158,87); //cleanup================================================================ pixel(1,80,122); pixel(0,80,124); pixel(1,80,110); pixel(0,80,112); pixel(1,80,38); pixel(0,80,40); //numbers================================================================ x_offset = 1, y_offset = 99; print_char(1,'2'); y_offset = 101; print_char(1,'0'); line(1, 9, 92, 12, 86); line(1, 8, 92, 11, 86); x_offset = 24, y_offset = 111; print_char(1,'1'); y_offset = 112; print_char(1,'0'); line(1,30, 101, 32, 95); line(1, 31, 101, 33, 95); x_offset = 48, y_offset = 117; print_char(1,'7'); line(1,50, 108, 51, 101); line(1, 51, 108, 52, 101); x_offset = 66, y_offset = 119; print_char(1,'5'); line(1,68, 109, 69, 103); line(1, 69, 109, 70, 103); x_offset = 84, y_offset = 119; print_char(1,'3'); line(1,86, 109, 86, 103); line(1, 87, 109, 87, 103); x_offset = 110, y_offset = 116; print_char(1,'0'); line(1,108, 102, 109, 106); line(1,109, 102, 110, 106); x_offset = 135, y_offset = 108; print_char(1,'3'); line(1,132, 93, 135, 100); line(1,133, 93, 136, 100); //logo================================================================== y = 28; q = 0; while(q < 30) { temp = logo[q]; for (x = 72; x < 80; x++) { if (temp & 0x80) pixel(1,x,y); temp <<= 1; } q++; temp = logo[q]; for (x = 80; x < 88; x++) { if (temp & 0x80) pixel(1,x,y); temp <<= 1; } y--; q++; } x = 0; line(1, line_array[x*4], line_array[x*4+1], line_array[x*4+2], line_array[x*4+3]); while(1) { q = get_adc(); y = (char)(rnd(q / 13.5)-10); delay_ms(25); if (y != x) { line(0, line_array[x*4], line_array[x*4+1], line_array[x*4+2], line_array[x*4+3]); line(1, line_array[y*4], line_array[y*4+1], line_array[y*4+2], line_array[y*4+3]); x = y; if (y >= 50) PORTD |= (1<<PEAK); else PORTD &= (~(1<<PEAK)); } //rprintf("%d\r\n",q); /* for (x = 10; x <= 80; x += 4) { //draw new line line(1, line_array[(x-10)*4], line_array[(x-10)*4+1], line_array[(x-10)*4+2], line_array[(x-10)*4+3]); line(1, line_array[(x-10)*4]+1, line_array[(x-10)*4+1], line_array[(x-10)*4+2]+1, line_array[(x-10)*4+3]); delay_ms(3); line(0, line_array[(x-10)*4], line_array[(x-10)*4+1], line_array[(x-10)*4+2], line_array[(x-10)*4+3]); line(0, line_array[(x-10)*4]+1, line_array[(x-10)*4+1], line_array[(x-10)*4+2]+1, line_array[(x-10)*4+3]); } for (x = 80; x >= 10; x -= 4) { //draw new line line(1, line_array[(x-10)*4], line_array[(x-10)*4+1], line_array[(x-10)*4+2], line_array[(x-10)*4+3]); line(1, line_array[(x-10)*4]+1, line_array[(x-10)*4+1], line_array[(x-10)*4+2]+1, line_array[(x-10)*4+3]); delay_ms(3); line(0, line_array[(x-10)*4], line_array[(x-10)*4+1], line_array[(x-10)*4+2], line_array[(x-10)*4+3]); line(0, line_array[(x-10)*4]+1, line_array[(x-10)*4+1], line_array[(x-10)*4+2]+1, line_array[(x-10)*4+3]); } */ } while(1); //{ /* if(RX_in != RX_read) { x = RX_array[RX_read]; RX_read++; if(RX_read >= 256) RX_read = 0; //Backspace=================================================== if(x == 8) del_char(0); //Special commands else if (x == 124) { //make sure the next byte is there while(RX_in == RX_read); //0, clear screen====================================================== if(RX_array[RX_read] == 0) { clear_screen(); RX_read++; if(RX_read >= 256) RX_read = 0; } //Backlight on/off else if(RX_array[RX_read] == 2) { y = PINB; if (y & (1<<BL_EN)) PORTB &= (~(1<<BL_EN)); else PORTB |= (1<<BL_EN); RX_read++; } //demo mode else if(RX_array[RX_read] == 4) { RX_in = 0, RX_read = 0; demo(); clear_screen(); RX_in = 0; } else { //set x or y========================================================= if((RX_array[RX_read] == 24) | (RX_array[RX_read] == 25)) { RX_read++; if(RX_read >= 256) RX_read = 0; while(RX_in == RX_read);//wait for byte if (RX_array[RX_read-1] == 24) x_offset = RX_array[RX_read]; else if (RX_array[RX_read-1] == 25) y_offset = RX_array[RX_read]; RX_read++; if(RX_read >= 256) RX_read = 0; if (x_offset > 159) x_offset = 159; if (y_offset > 127) y_offset = 127; } //set pixel========================================================= if (RX_array[RX_read] == 16) { //need 3 bytes for (y = 0; y < 3; y++) { RX_read++; if(RX_read >= 256) RX_read = 0; while(RX_in == RX_read);//wait for byte } pixel(RX_array[RX_read], RX_array[RX_read-2], RX_array[RX_read-1]); RX_read++; if(RX_read >= 256) RX_read = 0; } //<ctrl>c, circle====================================================== if(RX_array[RX_read] == 3) { //need 4 bytes for (y = 0; y < 4; y++) { RX_read++; if(RX_read >= 256) RX_read = 0; while(RX_in == RX_read);//wait for byte } circle(RX_array[RX_read], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1]); RX_read++; if(RX_read >= 256) RX_read = 0; } //<ctrl>e, erase block====================================================== if(RX_array[RX_read] == 5) { //need 4 bytes for (y = 0; y < 4; y++) { RX_read++; if(RX_read >= 256) RX_read = 0; while(RX_in == RX_read);//wait for byte } erase_block(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]); RX_read++; if(RX_read >= 256) RX_read = 0; } //<ctrl>o, box, running out of meaningful letters====================================================== if(RX_array[RX_read] == 15) { //need 4 bytes for (y = 0; y < 4; y++) { RX_read++; if(RX_read >= 256) RX_read = 0; while(RX_in == RX_read);//wait for byte } box(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]); RX_read++; if(RX_read >= 256) RX_read = 0; } //<ctrl>L, line======================================================== else if (RX_array[RX_read] == 12) { //need 5 bytes for (y = 0; y < 5; y++) { RX_read++; if(RX_read >= 256) RX_read = 0; while(RX_in == RX_read);//wait for byte } line(RX_array[RX_read], RX_array[RX_read-4], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read+-1]); RX_read++; if(RX_read >= 256) RX_read = 0; } } } //print character to the screen=============================================== else { del_char(1); print_char(1, x); } } */ //} }
/********************** Function implementations *************************/ void menu_task(void *pvParameters) { menu_t *menu; INT8U i; //setup menus init_menus(); menu = menu_handler(SYSTEM_START_MENU); red_led( FALSE ); yellow_led( FALSE ); green_led( FALSE ); //setup initial system parameters parameter(PUSH,PAN_SETPOINT_P,0); parameter(PUSH,TILT_SETPOINT_P,0); parameter(PUSH,PAN_PWM_P,0); parameter(PUSH,TILT_PWM_P,0); parameter(PUSH,NEXT_POS_P,0); parameter(PUSH,SAVE_POS_P,0); // position(NEW,0); parameter(PUSH,PAN_CURRENT_P,-150); parameter(PUSH,TILT_CURRENT_P,860); position(SAVE,1); parameter(PUSH,PAN_CURRENT_P,150); parameter(PUSH,TILT_CURRENT_P,-2600); position(SAVE,2); exit_freemode(); deactivate_regulator(); deactivate_automode(); while(TRUE) { //handle inputs menu = parse_dreh_event(menu); if(menu->type.is_input) { for(i = 0 ; i < NUMBER_OF_FIELDS ; i++) { if(menu->field[i].dreh_input) parameter(ADD, menu->field[i].parameter, DREH_TO_DEG(counter(RESET,DREH_C)) ); if(menu->field[i].adc_input) parameter(PUSH, menu->field[i].parameter, ADC_TO_DEG(get_adc()) ); if(menu->field[i].numpad_input) if(event(PEEK,NUMPAD_E)) parameter(PUSH, menu->field[i].parameter, CHAR_TO_NUMBER(event(POP,NUMPAD_E) )); } } //update display buffer display_buffer_write_string(0,0,menu->text.topline); display_buffer_write_string(0,1,menu->text.bottomline); for(i=0 ; i < NUMBER_OF_FIELDS ; i++) { if(menu->field[i].show) display_buffer_write_decimal( menu->field[i].begin.x, menu->field[i].begin.y, menu->field[i].size, NUMBER_OF_DECIMALS, parameter(POP,menu->field[i].parameter)); } //handle task states if(state(POP,AUTO_WAIT_S)) { //check if wait time has lapsed if(counter(POP,TIME_C) > TIME_TO_WAIT_ON_HIT) { //change to next position and resume regulation if(parameter(ADD,NEXT_POS_P,1) > NUMBER_OF_POSITIONS) parameter(PUSH,NEXT_POS_P,1); position(GOTO,parameter(POP,NEXT_POS_P)); state(PUSH,AUTO_WAIT_S,FALSE); red_led( FALSE ); activate_automode(); activate_regulator(); } else red_led( TRUE ); } YIELD(YIELD_TIME_MENU_T) } }
int main (void) { char x, y, a, temp; //short a, b; float temp_y, temp_y2, temp_x; int q; //char a = 0; ioinit(); //Setup IO pins and defaults //USART_Init( MYUBRR); //rprintf_devopen(put_char); /* init rrprintf */ //reset the display delay_ms(1); PORTC |= (1<<RST); //initialize the display display_init(); clear_screen(); //Backlight on PORTB &= (~(1<<BL_EN)); //circle(1,80,-20,142); //circle(1,80,-20,70); //top arcs======================================================================= for (x = 0; x < 160; x++) { //temp_y = ((sqrt((radius^2) - ((x - (x offset))*(x - (x offset))))) - (y offset)) //...x ofset and y offset are NOT the test offsets. This is just here as an example. temp_y = ((sqrt((23716) - ((x - 80)*(x - 80)))) - 30); temp_y2 = ((sqrt((23409) - ((x - 80)*(x - 80)))) - 30); //temp_y *= (-1); pixel(1, x, (char)(temp_y)); pixel(1, x, (char)(temp_y2)); } for (x = 0; x < 160; x++) { //temp_y = ((sqrt((r^2) - ((x - 80)*(x - 80)))) - 20) temp_y = ((sqrt((20164) - ((x - 80)*(x - 80)))) - 30); temp_y2 = ((sqrt((19881) - ((x - 80)*(x - 80)))) - 30); //temp_y *= (-1); pixel(1, x, (char)(temp_y)); pixel(1, x, (char)(temp_y2)); } //bottom arc======================================================================= for (x = 40; x < 120; x++) { temp_y = ((sqrt((4900) - ((x - 80)*(x - 80)))) - 30); temp_y2 = ((sqrt((4761) - ((x - 80)*(x - 80)))) - 30); //temp_y *= (-1); pixel(1, x, (char)(temp_y)); pixel(1, x, (char)(temp_y2)); } //peak arc======================================================================= for (x = 108; x < 156; x++) { //temp_y = ((sqrt((19044) - ((x - 80)*(x - 80)))) - 30); temp_y2 = ((sqrt((18225) - ((x - 80)*(x - 80)))) - 30); //temp_y *= (-1); //pixel(1, x, (char)(temp_y)); pixel(1, x, (char)(temp_y2)); } //lines on the meter sides======================================================================= line(1,0,87,40,27); line(1,1,87,41,27); line(1,120,27,159,87); line(1,119,27,158,87); //little cleanup================================================================ pixel(1,80,122); pixel(0,80,124); pixel(1,80,110); pixel(0,80,112); pixel(1,80,38); pixel(0,80,40); //numbers================================================================ x_offset = 1, y_offset = 99; print_char(1,'2'); y_offset = 101; print_char(1,'0'); line(1, 9, 92, 12, 86); line(1, 8, 92, 11, 86); x_offset = 24, y_offset = 111; print_char(1,'1'); y_offset = 112; print_char(1,'0'); line(1,30, 101, 32, 95); line(1, 31, 101, 33, 95); x_offset = 48, y_offset = 117; print_char(1,'7'); line(1,50, 108, 51, 101); line(1, 51, 108, 52, 101); x_offset = 66, y_offset = 119; print_char(1,'5'); line(1,68, 109, 69, 103); line(1, 69, 109, 70, 103); x_offset = 84, y_offset = 119; print_char(1,'3'); line(1,86, 109, 86, 103); line(1, 87, 109, 87, 103); x_offset = 110, y_offset = 116; print_char(1,'0'); line(1,108, 102, 109, 106); line(1,109, 102, 110, 106); x_offset = 135, y_offset = 108; print_char(1,'3'); line(1,132, 93, 135, 100); line(1,133, 93, 136, 100); //logo================================================================== y = 28; q = 0; while(q < 30) { temp = logo[q]; for (x = 72; x < 80; x++) { if (temp & 0x80) pixel(1,x,y); temp <<= 1; } q++; temp = logo[q]; for (x = 80; x < 88; x++) { if (temp & 0x80) pixel(1,x,y); temp <<= 1; } y--; q++; } x = 0; line(1, line_array[x*4], line_array[x*4+1], line_array[x*4+2], line_array[x*4+3]); while(1) { q = get_adc(); y = (char)(rnd(q / 13.5)-10); delay_ms(10); if (y != x) { line(0, line_array[x*4], line_array[x*4+1], line_array[x*4+2], line_array[x*4+3]); line(1, line_array[y*4], line_array[y*4+1], line_array[y*4+2], line_array[y*4+3]); x = y; if (y >= 50) PORTD |= (1<<PEAK); else PORTD &= (~(1<<PEAK)); } } while(1); }
static void read_adc (int mode) { /* Read ARM ADC Output */ if (mode == MIB_READ) { AdcIn = get_adc(); } }
int getSliderPos(int slider) { return get_adc(SOMETHING); }