void SomaFMService::RefreshStreamsFinished(QNetworkReply* reply, int task_id) { app_->task_manager()->SetTaskFinished(task_id); reply->deleteLater(); if (reply->error() != QNetworkReply::NoError) { // TODO: Error handling qLog(Error) << reply->errorString(); return; } StreamList list; QXmlStreamReader reader(reply); while (!reader.atEnd()) { reader.readNext(); if (reader.tokenType() == QXmlStreamReader::StartElement && reader.name() == "channel") { ReadChannel(reader, &list); } } streams_.Update(list); // Only update the item's children if it's already been populated if (!root_->data(InternetModel::Role_CanLazyLoad).toBool()) PopulateStreams(); emit StreamsChanged(); }
void TemperatureReader::Read(TemperatureItem* temperatureItem) { currentTemperatureItem = temperatureItem; for(auto iter = currentTemperatureItem->Channels.begin(); iter != currentTemperatureItem->Channels.end(); ++iter) { ReadChannel(currentTemperatureItem->Address, *iter); } }
void GetTouch(int *X,int *Y) { double Ux,Uy; int x,y; //x DDRA |= (1<<PA1); //PA0: 5V DDRA |= (1<<PA0); //PA1: 0V PORTA |= (1<<PA0); _delay_ms(16); //adc(PORT) liefert gemesse Spanung in V Uy = ReadChannel(2); Uy = ((Uy*5.0)/1024.0); y = ((Uy-Uy1) / (Uy2-Uy1)) * WIDTH; PORTA &= ~(1<<PA0); //PA0 und DDRA &= ~(1<<PA0); //PA1 wiedr DDRA &= ~(1<<PA1); //Eingang //y DDRA |= (1<<PA3); //PA3: 5V DDRA |= (1<<PA2); //PA2: 0V PORTA |= (1<<PA2); _delay_ms(16); //adc(PORT) liefert gemesse Spanung in V Ux = ReadChannel(0); Ux = ((Ux*5.0)/1024.0); x = (((Ux-Ux1) / (Ux2-Ux1))*HEIGHT); PORTA &= ~(1<<PA2); //PA2 und DDRA &= ~(1<<PA2); //PA1 wiedr DDRA &= ~(1<<PA3); //Eingang _delay_ms(100); *X = x; *Y = y; }
int main (void) { DDRC = 0xFF; uint16_t adcval = 0; while(1){ adcval = ReadChannel(0); if(adcval <400) { PORTC = 0; } else { PORTC = 0xFF; } } }
uint16_t ReadPressure() { return ReadChannel(1, 0); }
uint16_t ReadHumidity() { return ReadChannel(0, 0); }
int t4012___store(int *niddsc, InStoreStruct *setup) { int channels; int pts; int memPerChannel; int channels_read; int dig; int dig_nid; static int memsize=0; static unsigned short *mem; int idxmin; int idxmax; char digname[512]; char *nodename; int chan_nid = 0; struct _t4012_status { unsigned sampling : 1; unsigned calibrate : 1; unsigned master_armed : 1; unsigned master_enabled : 1; unsigned stop_received : 1; unsigned triggered : 1; unsigned t4012p : 1; unsigned cal_mem : 1; unsigned : 24; } dig_status; int status; static short offset; static float coefficient; static float f[2]; static DESCRIPTOR_A_BOUNDS(raw,sizeof(short),DTYPE_W,0,1,0); static int *lbound = &raw.bounds[0].l; static int *ubound = &raw.bounds[0].u; static unsigned int *acoef = &raw.m[0]; static DESCRIPTOR_A(f2_d,sizeof(f[0]),DTYPE_NATIVE_FLOAT,f,8); static DESCRIPTOR(counts_str,"counts"); static DESCRIPTOR(volts_str,"volts"); static DESCRIPTOR(seconds_str,"seconds"); static DESCRIPTOR_LONG(start_d,&raw.bounds[0].l); static DESCRIPTOR_LONG(end_d,&raw.bounds[0].u); static int trigger_nid; static DESCRIPTOR_NID(stop_d,&trigger_nid); static int switch_trig_nid; static DESCRIPTOR_NID(swi_d,&switch_trig_nid); static int extern_clock_nid; static DESCRIPTOR_NID(ext_clock_d,&extern_clock_nid); static struct descriptor offset_d = {2,DTYPE_W, CLASS_S, (char *)&offset}; static DESCRIPTOR_FLOAT(coef_d,&coefficient); static DESCRIPTOR_FLOAT(f1_d,f); static int _roprand = 32768; static DESCRIPTOR_FLOAT(roprand,&_roprand); static FUNCTION(1) value = {2,DTYPE_FUNCTION,CLASS_R,(unsigned char *)&OpcValue,0,0}; static DESCRIPTOR_FUNCTION_2(subtract_exp,(unsigned char *)&OpcSubtract,&value,&offset_d); static DESCRIPTOR_FUNCTION_2(mult_exp,(unsigned char *)&OpcMultiply,&coef_d,&subtract_exp); static DESCRIPTOR_WITH_UNITS(counts,&raw,&counts_str); static DESCRIPTOR_WITH_UNITS(volts,&mult_exp,&volts_str); static DESCRIPTOR_FUNCTION_2(rangesub,(unsigned char *)&OpcSubtract,0,&f1_d); static DESCRIPTOR_WINDOW(window,&start_d,&end_d,&stop_d); static struct descriptor *begin_ptrs[] = {&roprand,0}; static struct descriptor *end_ptrs[] = {(struct descriptor *)&rangesub,&roprand}; static DESCRIPTOR_APD(begin_apd,0,begin_ptrs,2); static DESCRIPTOR_APD(end_apd,0,end_ptrs,2); static DESCRIPTOR_RANGE(int_clock1_d,0,0,&f1_d); static DESCRIPTOR_RANGE(int_clock2_d,&begin_apd,&end_apd,&f2_d); static int clock_out_nid; static DESCRIPTOR_NID(clock_out_d,&clock_out_nid); static DESCRIPTOR_DIMENSION(dimension,&window,&clock_out_d); static DESCRIPTOR_WITH_UNITS(seconds,&dimension,&seconds_str); static DESCRIPTOR_SIGNAL_1(signal,&volts,&counts,&seconds); void *ctx = 0; max_time=-1; trigger_nid = setup->head_nid + T4012_N_TRIGGER; switch_trig_nid = setup->head_nid + T4012_N_SWITCH_TRIG; extern_clock_nid = setup->head_nid + T4012_N_EXTERN_CLOCK; clock_out_nid = setup->head_nid + T4012_N_CLOCK_OUT; pio(8,0,0); status = Input(setup,14); dig_status = *(struct _t4012_status *)&status; if (dig_status.sampling) { return DEV$_NOT_TRIGGERED; } channels = Input(setup,1); pts = Input(setup,2); memPerChannel = Input(setup,3) * 1024; if (Input(setup,7) == 1) TreePutRecord(clock_out_nid,(struct descriptor *)&ext_clock_d,0); else { int shift = Input(setup,6); f[0] = freqs[Input(setup,4)]; if (shift) { f[1] = freqs[Input(setup,5)]; rangesub.arguments[0] = begin_ptrs[1] = (shift == 1) ? &swi_d : &stop_d; TreePutRecord(clock_out_nid,(struct descriptor *)&int_clock2_d,0); } else TreePutRecord(clock_out_nid,(struct descriptor *)&int_clock1_d,0); } idxmin = (pts - 8.)/8. * memPerChannel; idxmax = idxmin + memPerChannel - 1; if (memsize < (memPerChannel * 2)) { if (memsize) free(mem); memsize = memPerChannel * 2; mem = malloc(memsize); } return_on_error(AccessTraq(setup,0x8001,16,0,0),status); /* Remote control */ nodename = TreeGetPath(setup->head_nid); strcpy(digname,nodename); TreeFree(nodename); strcat(digname,":T28%%_%%"); status = TreeFindNodeWild(digname,&dig_nid,&ctx,1 << TreeUSAGE_DEVICE); for (dig=1,channels_read=0;(channels_read < channels) && (status & 1);dig++) { static int dig_nids[1+8*T28XX_K_NODES_PER_INP]; static int nidlen; static NCI_ITM itmlst[] = {{sizeof(dig_nids),NciCONGLOMERATE_NIDS,(unsigned char *)&dig_nids,&nidlen}, {0,NciEND_OF_LIST,0,0}}; if (status & 1) { int i; int digchannels; status = TreeGetNci(dig_nid,itmlst); digchannels = (nidlen/sizeof(dig_nid)-1)/T28XX_K_NODES_PER_INP; for (i=0;i<digchannels && (status & 1) && channels_read < channels;i++) { if (TreeIsOn(CNID(i,HEAD))&1) { int channel_select = 0x0A000 | (channels_read + 1); AccessTraq(setup,channel_select,24,0,0); if (chan_nid && (*acoef > 1)) { return_on_error(TreePutRecord(chan_nid,(struct descriptor *)&signal,0),status); chan_nid = 0; } else DevWait((float).005); chan_nid = CNID(i,HEAD); *lbound = (DevLong(&CNID(i,STARTIDX),(int *)lbound) & 1) ? min(idxmax,max(idxmin,*lbound)) : idxmin; *ubound = (DevLong(&CNID(i,ENDIDX), (int *)ubound) & 1) ? min(idxmax,max(idxmin,*ubound)) : idxmax; *acoef = *ubound - *lbound + 1; if (*acoef > 0) { int points_read = 0; int first_sample_offset = *lbound-idxmin; int chunk = first_sample_offset/1024; int chunk_offset = first_sample_offset % 1024; float calib[]={0,0}; status = ReadChannel(setup, chunk,*acoef+chunk_offset,mem,&points_read,&CNID(i,CALIBRATION),calib); if (status & 1) { offset = calib[0]; if (calib[0] == calib[1]) coefficient = (offset > 1000) ? 10./4096 : 5./4096.; else coefficient = calib[1]; raw.pointer = (char *)(mem + chunk_offset); raw.a0 = raw.pointer - *lbound * sizeof(*mem); *ubound = (points_read - chunk_offset) + *lbound - 1; *acoef = (points_read - chunk_offset); raw.arsize = *acoef * 2; } } } channels_read++; } } if (channels_read < channels && (status & 1)) status = TreeFindNodeWild(digname,&dig_nid,&ctx,1 << TreeUSAGE_DEVICE); } TreeFindNodeEnd(&ctx); if (chan_nid && (*acoef > 1)) return_on_error(TreePutRecord(chan_nid,(struct descriptor *)&signal,0),status); return status; }
uint16_t ReadTemperature() { return ReadChannel(0, 0); }
int l8210___store(struct descriptor *niddsc_ptr, InStoreStruct *setup) { static DESCRIPTOR_A_BOUNDS(raw,sizeof(short),DTYPE_W,0,1,0); static DESCRIPTOR(counts_str,"counts"); static DESCRIPTOR_WITH_UNITS(counts,&raw,&counts_str); static DESCRIPTOR_LONG(start_d,&raw.bounds[0].l); static DESCRIPTOR_LONG(end_d,&raw.bounds[0].u); static int stop_trig_nid; static DESCRIPTOR_NID(trigger_d,&stop_trig_nid); static float frequency; static DESCRIPTOR_FLOAT(frequency_d,&frequency); static DESCRIPTOR_RANGE(int_clock_d,0,0,&frequency_d); static int ext_clock_in_nid; static DESCRIPTOR_NID(ext_clock_d,&ext_clock_in_nid); static float coefficient = 10.0/1024; static DESCRIPTOR_FLOAT(coef_d,&coefficient); static short offset = -512; static struct descriptor offset_d = {2,DTYPE_W,CLASS_S,(char *)&offset}; #define DESCRIPTOR_VALUE(name)\ struct descriptor_function_0 { RECORD_HEAD } name =\ {2, DTYPE_FUNCTION, CLASS_R, (unsigned char *)&OpcValue, 0} static DESCRIPTOR_VALUE(value); static DESCRIPTOR_FUNCTION_2(add_exp,(unsigned char *)&OpcAdd,&offset_d,&value); static DESCRIPTOR_FUNCTION_2(mult_exp,(unsigned char *)&OpcMultiply,&coef_d,&add_exp); static DESCRIPTOR(volts_str,"volts"); static DESCRIPTOR_WITH_UNITS(volts,&mult_exp,&volts_str); static DESCRIPTOR_WINDOW(window,&start_d,&end_d,&trigger_d); static int clock_out_nid; static DESCRIPTOR_NID(clock_out,&clock_out_nid); static DESCRIPTOR_DIMENSION(dimension,&window,&clock_out); static DESCRIPTOR(time_str,"seconds"); static DESCRIPTOR_WITH_UNITS(time,&dimension,&time_str); static DESCRIPTOR_SIGNAL_1(signal,&volts,&counts,&time); int samples_per_channel; int min_idx; int max_idx; int num_chans; int vm_size; short *channel_data_ptr; int status; int chan; int samples_to_read; int i; float wait_time; stop_trig_nid = setup->head_nid + L8210_N_STOP_TRIG; ext_clock_in_nid = setup->head_nid + L8210_N_EXT_CLOCK_IN; clock_out_nid = setup->head_nid + L8210_N_CLOCK_OUT; pio(26,0,0); wait_time = setup->memories*30E-3; DevWait(wait_time); pio(8,0,0); if ((CamXandQ(0)&1) == 0) return DEV$_NOT_TRIGGERED; return_on_error(ReadSetup(setup, &setup->memories, setup->header, &samples_per_channel, &min_idx, &max_idx, &frequency, &num_chans), status); channel_data_ptr = malloc(samples_per_channel * sizeof(short)); status = TreePutRecord(clock_out_nid, (struct descriptor *)(frequency == 0.0) ? &ext_clock_d : (struct descriptor *)(&int_clock_d),0); for (chan=0;((chan<num_chans) && (status & 1));chan++) { int channel_nid = setup->head_nid + L8210_N_INPUT_1 + chan * (L8210_N_INPUT_2 - L8210_N_INPUT_1); int usetimes_nid = channel_nid + L8210_N_INPUT_1_USETIMES - L8210_N_INPUT_1; int startidx_nid = channel_nid + L8210_N_INPUT_1_STARTIDX - L8210_N_INPUT_1; int endidx_nid = channel_nid + L8210_N_INPUT_1_ENDIDX - L8210_N_INPUT_1; if (TreeIsOn(channel_nid) & 1) { int use_times = 0; DevLong(&usetimes_nid,&use_times); if(use_times) { float start_time, end_time; raw.bounds[0].l = min_idx; raw.bounds[0].u = max_idx; status = DevFloat(&startidx_nid,&start_time); if (~status&1) start_time = -1; status = DevFloat(&endidx_nid,&end_time); if (~status&1) end_time = -1; status = DevXToI(start_time, end_time, &dimension, min_idx, max_idx, &raw.bounds[0].l, &raw.bounds[0].u); if (~status&1) { raw.bounds[0].l = min_idx; raw.bounds[0].u = max_idx; } } else { status = DevLong(&startidx_nid,(int *)&raw.bounds[0].l); if (status&1) raw.bounds[0].l = min(max_idx,max(min_idx,raw.bounds[0].l)); else raw.bounds[0].l = min_idx; status = DevLong(&endidx_nid, (int *)&raw.bounds[0].u); if (status&1) raw.bounds[0].u = min(max_idx,max(min_idx,raw.bounds[0].u)); else raw.bounds[0].u = max_idx; } raw.m[0] = raw.bounds[0].u - raw.bounds[0].l + 1; if (raw.m[0] > 0) { samples_to_read = raw.bounds[0].u - min_idx + 1; status = ReadChannel(setup,&samples_per_channel,chan,&samples_to_read,channel_data_ptr); if (status & 1) { raw.pointer = (char *)(channel_data_ptr + (raw.bounds[0].l - min_idx)); raw.a0 = raw.pointer - raw.bounds[0].l * sizeof(*channel_data_ptr); raw.arsize = raw.m[0] * 2; status = TreePutRecord(channel_nid,(struct descriptor *)&signal,0); } } } } free(channel_data_ptr); return status; }
uint16_t ReadUV() { return ReadChannel(3,6); }
uint16_t ReadGreen() { return ReadChannel(3,4); }
uint16_t ReadYellow() { return ReadChannel(3,2); }
uint16_t ReadRed() { return ReadChannel(3,0); }
uint16_t ReadSound() { return ReadChannel(1,0); }
uint16_t ReadLight() { return ReadChannel(2, 0); }
uint16_t ReadGas() { return ReadChannel(2,0); }
uint16_t ReadDust() { return ReadChannel(3,0); }
int l6810___store(struct descriptor *niddsc_ptr, InStoreStruct *in_struct) { #undef return_on_error #define return_on_error(f) if (!((status = f) & 1)) return status; #undef pio #define pio(f,a,d,q) return_on_error(DevCamChk(CamPiow(in_struct->name, a, f, d, 16, 0), &one, &q)) #define CHAN_NID(chan, field) c_nids[L6810_N_CHANNELS+chan*L6810_K_NODES_PER_CHANNEL+field] static int one = 1; static int c_nids[L6810_K_CONG_NODES]; static DESCRIPTOR_A_BOUNDS(raw,sizeof(short),DTYPE_W,0,1,0); static DESCRIPTOR(counts_str,"counts"); static DESCRIPTOR_WITH_UNITS(counts,&raw,&counts_str); static DESCRIPTOR_LONG(one_d,&one); static DESCRIPTOR_LONG(start_d,&raw.bounds[0].l); static DESCRIPTOR_FUNCTION_2(start_expr_d,(unsigned char *)&OpcAdd,&start_d,&one_d); static DESCRIPTOR_LONG(end_d,&raw.bounds[0].u); static DESCRIPTOR_FUNCTION_2(end_expr_d,(unsigned char *)&OpcAdd,&end_d,&one_d); static DESCRIPTOR_NID(trigger_d,&c_nids[L6810_N_STOP_TRIG]); static float frequency = 4E-6; static DESCRIPTOR_FLOAT(frequency_d,&frequency); static DESCRIPTOR_RANGE(int_clock_d,0,0,&frequency_d); static DESCRIPTOR_NID(ext_clock_d,&c_nids[L6810_N_EXT_CLOCK_IN]); static float coeffs[] = {100E-6, 250E-6, 500E-6, 1E-3, 2.5E-3, 6.26E-3, 12.5E-3, 25E-3}; static float coefficient; static DESCRIPTOR_FLOAT(coef_d,&coefficient); static short offset = -2048; static struct descriptor_s offset_d = {2,DTYPE_W,CLASS_S,(char *)&offset}; static DESCRIPTOR_FUNCTION_1(dvalue,(unsigned char *)&OpcValue,0); static DESCRIPTOR_FUNCTION_2(add_exp,(unsigned char *)&OpcAdd,&offset_d,&dvalue); static DESCRIPTOR_FUNCTION_2(mult_exp,(unsigned char *)&OpcMultiply,&coef_d,&add_exp); static DESCRIPTOR(volts_str,"volts"); static DESCRIPTOR_WITH_UNITS(volts,&mult_exp,&volts_str); static DESCRIPTOR_WINDOW(window,&start_expr_d,&end_expr_d,&trigger_d); static DESCRIPTOR_DIMENSION(dimension,&window,0); static DESCRIPTOR(time_str,"seconds"); static DESCRIPTOR_WITH_UNITS(time,&dimension,&time_str); static DESCRIPTOR_SIGNAL_1(signal,&volts,&counts,&time); short *channel_data; int status; int chan; int samples_to_read; int i; int min_idx; int max_idx; int post_trig; int samples_per_channel; struct setup setup; return_on_error(DevNids(niddsc_ptr,sizeof(c_nids),c_nids)); dvalue.ndesc = 0; return_on_error(DevCamChk(CamPiow(in_struct->name, 0, 8, 0, 16, 0), &one, 0)); if ((CamXandQ(0)&1) == 0) return DEV$_NOT_TRIGGERED; pio(18, 0, &zero, one); /* prepare to read setup information */ stop(2,1,33,&setup); /* read the setup information */ if (setup.f1_freq == 0) { dimension.axis = (struct descriptor *)(&ext_clock_d); } else { static float freqs[] = {0.0, 1/20., 1/50., 1/100., 1/200., 1/500., 1/1000., 1/2000., 1/5000., 1/10000., 1/20000., 1/50000., 1/100000., 1/200000., 1/500000., 1/1000000., 1/2000000., 1/5000000.}; dimension.axis = (struct descriptor *)(&int_clock_d); frequency = freqs[setup.f1_freq]; } samples_per_channel = (1<<setup.samps_per_seg)*1024; post_trig = samples_per_channel; min_idx = 0; max_idx = post_trig - 2; channel_data = (short *)malloc(samples_per_channel*sizeof(short)); #undef return_on_error #define return_on_error(f) if (!((status = f) & 1)) {free(channel_data); return status;} for (chan=0;((chan < 4) && (status & 1));chan++) { if (TreeIsOn(CHAN_NID(chan,L6810_N_CHAN_HEAD)) & 1) { status = DevLong(&CHAN_NID(chan,L6810_N_CHAN_STARTIDX),(int *)&raw.bounds[0].l); if (status&1) raw.bounds[0].l = min(max_idx,max(min_idx,raw.bounds[0].l)); else raw.bounds[0].l = min_idx; status = DevLong(&CHAN_NID(chan,L6810_N_CHAN_ENDIDX), (int *)&raw.bounds[0].u); if (status&1) raw.bounds[0].u = min(max_idx,max(raw.bounds[0].l,raw.bounds[0].u)); else raw.bounds[0].u = max_idx; raw.m[0] = raw.bounds[0].u - raw.bounds[0].l + 1; if (raw.m[0] > 0) { samples_to_read = raw.bounds[0].u - min_idx + 1; status = ReadChannel(in_struct->name,chan,&samples_to_read,channel_data); if (status & 1) { coefficient = coeffs[setup.sensitivity[chan]]; raw.pointer = (char *)(channel_data + (raw.bounds[0].l - min_idx)); raw.a0 = raw.pointer - (raw.bounds[0].l * sizeof(channel_data[0])); raw.arsize = raw.m[0] * 2; status = TreePutRecord(CHAN_NID(chan,L6810_N_CHAN_HEAD),(struct descriptor *)&signal,0); } } } } free(channel_data); return status; }