static void flip_layer( float *data, int rows, int cols, float missing_value ) { int i, j; float temp[MAXROWS*MAXCOLUMNS]; #define DATA(R,C) data[R*cols+C] #define TEMP(R,C) temp[C*rows+rows-R-1] for (i=0;i<rows;i++) { for (j=0;j<cols;j++) { /* NOTE: floating-point errors on next line probably indicate improperly byteswapped data file! How to catch in program??? */ if (DATA(i,j)==missing_value) { TEMP(i,j) = MISSING; } else { TEMP(i,j) = DATA(i,j); } } } memcpy( data, temp, rows*cols*sizeof(float) ); #undef DATA #undef TEMP }
void radiator_loop_new() { temp_t tab [] = { DS18B20_RADIATOR_U, DS18B20_RADIATOR_D, DS18B20_HOUSE_S_T, }; ds18b20_temp_tab_fill(RESOLUTION_11, 7, tab); CONFIG static temp_t ambient_temp = TEMP(23); CONFIG static uint8_t heating_f = 4.0 * 0x10; CONFIG static temp_t storage_off = TEMP(10); temp_t goal = CONFIG_GET(ambient_temp); goal += (uint32_t)(tab[0] - tab[1]) * CONFIG_GET(heating_f) / 0x10; goal = MIN(goal, tab[2] - storage_off); valve_state_t amount = VALVE_STATE_MAX * 5 / 100; if (goal > tab[1]) valve_open_for (VALVE_RADIATOR, amount); else valve_close_for(VALVE_RADIATOR, amount); if (valve_closed(VALVE_RADIATOR)) relay_off(RELAY_PUMP_RADIATOR); else relay_on (RELAY_PUMP_RADIATOR); }
cg_buffer2D<float> DiffGausY(cg_buffer2D<float> &X) { cg_buffer2D<float> TEMP(X.get_width(), X.get_height(), X.get_stride()); float *fp1 = X.get_data(); float *fp2 = X.get_data()+X.get_stride(); float *fp3 = X.get_data()+(X.get_stride()*2); float *fp4 = X.get_data()+(X.get_stride()*3); float *fp5 = X.get_data()+(X.get_stride()*4); float *fp = TEMP.get_data()+(X.get_stride()*2); for(unsigned int i=0;i<X.get_stride();i++) { for (unsigned int j=0;j<X.get_height()-4;j++) { *fp = DG3[0]*(float)*fp1 + DG3[1]*(float)*fp2 + DG3[2]*(float)*fp3 + DG3[3]*(float)*fp4 + DG3[4]*(float)*fp5; fp += X.get_stride(); fp1 += X.get_stride(); fp2 += X.get_stride(); fp3 += X.get_stride(); fp4 += X.get_stride(); fp5 += X.get_stride(); } fp1 = X.get_data()+i; fp2 = X.get_data()+X.get_stride()+i; fp3 = X.get_data()+(X.get_stride()*2)+i; fp4 = X.get_data()+(X.get_stride()*3)+i; fp5 = X.get_data()+(X.get_stride()*4)+i; fp = TEMP.get_data()+(X.get_stride()*2)+i; } return TEMP; }
int main() { env::variable<int> TEMP( "abc", env::default_value = 5 ); std::cout << TEMP << std::endl; return 0; }
cg_buffer2D<float> GaussianY(cg_buffer2D<float> &X) { cg_buffer2D<float> TEMP(X.get_width(), X.get_height(), X.get_stride()); float *fp1 = X.get_data(); float *fp2 = X.get_data()+X.get_stride(); float *fp3 = X.get_data()+(X.get_stride()*2); float *fp = TEMP.get_data()+(X.get_stride()); for(unsigned int i=0;i<X.get_stride();i++) { for (unsigned int j=0;j<X.get_height()-2;j++) { *fp = G3[0]*(float)*fp1 + G3[1]*(float)*fp2 + G3[2]*(float)*fp3; fp += X.get_stride(); fp1 += X.get_stride(); fp2 += X.get_stride(); fp3 += X.get_stride(); } fp1 = X.get_data()+i; fp2 = X.get_data()+X.get_stride()+i; fp3 = X.get_data()+(X.get_stride()*2)+i; fp = TEMP.get_data()+(X.get_stride())+i; } return TEMP; }
cg_buffer2D<float> DiffGausX(cg_buffer2D<float> &X) { cg_buffer2D<float> TEMP(X.get_width(), X.get_height(), X.get_stride()); float *Tp1 = X.get_data(); float *Tp2 = X.get_data()+1; float *Tp3 = X.get_data()+2; float *Tp4 = X.get_data()+3; float *Tp5 = X.get_data()+4; float *fp = TEMP.get_data()+2; for(int i=0;i<X.get_height();i++) { for (int j=0;j<X.get_stride()-4;j++) { *fp = (DG3[0]*(float)*Tp1++) + (DG3[1]*(float)*Tp2++) + (DG3[2]*(float)*Tp3++) + (DG3[3]*(float)*Tp4++) + (DG3[4]*(float)*Tp5++); fp++; } fp += 4; Tp1 += 4; Tp2 += 4; Tp3 += 4; Tp4 += 4; Tp5 += 4; } return TEMP; }
int main() { env::variable<int> TEMP( "abc", (env::global_id = "temp_dir_location", env::default_value = 5) ); std::cout << TEMP << std::endl; return 0; }
void radiator_loop() { temp_t tab [] = { DS18B20_COLLECTOR, DS18B20_OUTSIDE, }; ds18b20_get_temp_tab(sizeof(tab)/sizeof(temp_t), RESOLUTION_9, 7, tab); temp_t outside = MIN(tab[0], tab[1]); temp_t read_0 = ds18b20_get_temp(DS18B20_RADIATOR_U, RESOLUTION_11, 7); _delay_ms(1000); temp_t read_1 = ds18b20_get_temp(DS18B20_RADIATOR_U, RESOLUTION_11, 7); temp_t curr = read_1 + (read_1 - read_0) * 16; temp_t goal = CONFIG_GET(radiator_goal); CONFIG static uint8_t radiator_factor = 24; if (outside < goal) goal += (CONFIG_GET(radiator_factor) * ((uint32_t)goal - outside)) >> 4; bool dir = curr > goal; temp_t diff = dir ? curr - goal : goal - curr; valve_state_t amount = (VALVE_STATE_MAX * (uint32_t)diff) >> (8 + 6); if (dir) valve_close_for(VALVE_RADIATOR, amount); else valve_open_for (VALVE_RADIATOR, amount); if (valve_closed(VALVE_RADIATOR) || outside > TEMP(15)) // quick dirty hack - father wants radiator in bathroom warm, maybe we can achieve that by heating without pump relay_off(RELAY_PUMP_RADIATOR); else relay_on (RELAY_PUMP_RADIATOR); }
void T7(void) { assert(TEMP(3) == 123); assert(TEMP2(1) == 123); assert(xcat(xcat(1,2),3) == 123); assert(strcmp("abc123abc123abc123abc", S1(M1(123))) == 0); }
cg_buffer2D<float> Amplitude(cg_buffer2D<float> &X, cg_buffer2D<float> &Y) { cg_buffer2D<float> TEMP(X.get_width(), X.get_height(), X.get_stride()); float *dp = TEMP.get_data(); float *sp1 = X.get_data(); float *sp2 = Y.get_data(); for (unsigned int i=0;i<(X.get_stride()*X.get_height());i++) { *dp = sqrt((*sp1**sp1)+(*sp2**sp2)); dp++; sp1++; sp2++; } return TEMP; }
cg_buffer2D<float> Angle(cg_buffer2D<float> &X, cg_buffer2D<float> &Y) { cg_buffer2D<float> TEMP(X.get_width(), X.get_height(), X.get_stride()); float *dp = TEMP.get_data(); float *sp1 = X.get_data(); float *sp2 = Y.get_data(); for (unsigned int i=0;i<(X.get_stride()*X.get_height());i++) { *dp = atan(*sp2 / *sp1); dp++; sp1++; sp2++; } return TEMP; }
int main(void) { RCC_Configuration(); GPIO_Configuration(); RCC_ClocksTypeDef RCC_Clocks; RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000 - 1); setup_adc(); tim1_init(); usart_init(); PWM_U = 0; PWM_V = 0; PWM_W = 0; while(1){ if(uartsend == 1){ amp = AMP(amp_raw); volt = VOLT(volt_raw); if(temp_raw < ARES && temp_raw > 0){ temp = TEMP(temp_raw); } from_hv.dc_volt = TOFIXED(volt); from_hv.dc_cur = TOFIXED(amp); from_hv.hv_temp = TOFIXED(temp); #ifdef TROLLER from_hv.dc_cur = TOFIXED(0); from_hv.hv_temp = TOFIXED(0); from_hv.a = TOFIXED(AMP(ADCConvertedValue[1])); from_hv.b = TOFIXED(AMP(ADCConvertedValue[2])); from_hv.c = TOFIXED(AMP(ADCConvertedValue[3])); #endif uartsend = 0; while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); USART_SendData(USART2, 0x154); for(int j = 0;j<sizeof(from_hv_t);j++){ while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); USART_SendData(USART2, ((uint8_t*)&from_hv)[j]); } } //GPIOA->BSRR = (GPIOA->ODR ^ GPIO_Pin_2) | (GPIO_Pin_2 << 16);//toggle red led } }
cg_buffer2D<float> GaussianX(cg_buffer2D<T> &X) { cg_buffer2D<float> TEMP(X.get_width(), X.get_height(), X.get_stride()); T *Tp1 = X.get_data(); T *Tp2 = X.get_data()+1; T *Tp3 = X.get_data()+2; float *fp = TEMP.get_data()+1; for(unsigned int i=0;i<X.get_height();i++) { for (unsigned int j=0;j<X.get_stride()-2;j++) { *fp = (G3[0]*(float)*Tp1++) + (G3[1]*(float)*Tp2++) + (G3[2]*(float)*Tp3++); fp++; } fp += 2; Tp1 += 2; Tp2 += 2; Tp3 += 2; } return TEMP; }
int main() { env::variable<> TEMP( "TEMP", env::global_id = "temp_dir_location" ); return 0; }
/* Generate code for a section of the mask. first is the index we start * at, we set last to the index of the last one we use before we run * out of intermediates / constants / parameters / sources or mask * coefficients. * * 0 for success, -1 on error. */ static int vips_reducev_compile_section( VipsReducev *reducev, Pass *pass, gboolean first ) { VipsVector *v; int i; #ifdef DEBUG_COMPILE printf( "starting pass %d\n", pass->first ); #endif /*DEBUG_COMPILE*/ pass->vector = v = vips_vector_new( "reducev", 1 ); /* We have two destinations: the final output image (8-bit) and the * intermediate buffer if this is not the final pass (16-bit). */ pass->d2 = vips_vector_destination( v, "d2", 2 ); /* "r" is the array of sums from the previous pass (if any). */ pass->r = vips_vector_source_name( v, "r", 2 ); /* The value we fetch from the image, the accumulated sum. */ TEMP( "value", 2 ); TEMP( "sum", 2 ); /* Init the sum. If this is the first pass, it's a constant. If this * is a later pass, we have to init the sum from the result * of the previous pass. */ if( first ) { char c0[256]; CONST( c0, 0, 2 ); ASM2( "loadpw", "sum", c0 ); } else ASM2( "loadw", "sum", "r" ); for( i = pass->first; i < reducev->n_point; i++ ) { char source[256]; char coeff[256]; SCANLINE( source, i, 1 ); /* This mask coefficient. */ vips_snprintf( coeff, 256, "p%d", i ); pass->p[pass->n_param] = PARAM( coeff, 2 ); pass->n_param += 1; if( pass->n_param >= MAX_PARAM ) return( -1 ); /* Mask coefficients are 2.6 bits fixed point. We need to hold * about -0.5 to 1.0, so -2 to +1.999 is as close as we can * get. * * We need a signed multiply, so the image pixel needs to * become a signed 16-bit value. We know only the bottom 8 bits * of the image and coefficient are interesting, so we can take * the bottom bits of a 16x16->32 multiply. * * We accumulate the signed 16-bit result in sum. */ ASM2( "convubw", "value", source ); ASM3( "mullw", "value", "value", coeff ); ASM3( "addssw", "sum", "sum", "value" ); /* We've used this coeff. */ pass->last = i; if( vips_vector_full( v ) ) break; /* orc 0.4.24 and earlier hate more than about five lines at * once :( */ if( i - pass->first > 3 ) break; } /* If this is the end of the mask, we write the 8-bit result to the * image, otherwise write the 16-bit intermediate to our temp buffer. */ if( pass->last >= reducev->n_point - 1 ) { char c32[256]; char c6[256]; char c0[256]; char c255[256]; CONST( c32, 32, 2 ); ASM3( "addw", "sum", "sum", c32 ); CONST( c6, 6, 2 ); ASM3( "shrsw", "sum", "sum", c6 ); /* You'd think "convsuswb", convert signed 16-bit to unsigned * 8-bit with saturation, would be quicker, but it's a lot * slower. */ CONST( c0, 0, 2 ); ASM3( "maxsw", "sum", c0, "sum" ); CONST( c255, 255, 2 ); ASM3( "minsw", "sum", c255, "sum" ); ASM2( "convwb", "d1", "sum" ); } else ASM2( "copyw", "d2", "sum" ); if( !vips_vector_compile( v ) ) return( -1 ); #ifdef DEBUG_COMPILE printf( "done coeffs %d to %d\n", pass->first, pass->last ); vips_vector_print( v ); #endif /*DEBUG_COMPILE*/ return( 0 ); }
void handle_timechanges(struct tm *tick_time, TimeUnits units_changed) { static char time_buffer[256]; static char clock_buffer[64]; // static char day_buffer[10]; // static char date_buffer[10]; static char ampm[3]; static char buf[64]; char *p = 0; strftime(ampm, sizeof(ampm), "%p", tick_time); time_t current_time = time(0); time_t since = current_time + timezone_offset - last_update; if(tick_time->tm_sec == 0 && tick_time->tm_min % 15 == 0) send_int(KEY_TEMPERATURE, CMD_UPDATE); else if(bluetooth && last_update == -1) send_int(KEY_TEMPERATURE, CMD_UPDATE); static char time_format[16]; snprintf(time_format, sizeof(time_format), "%%l:%%M"); if(clock_is_24h_style()) snprintf(time_format, sizeof(time_format), "%%H:%%M"); if(show_seconds) strncat(time_format, ":%S", sizeof(time_format)); if(clock_is_24h_style()) strftime(clock_buffer, sizeof(clock_buffer), time_format, tick_time); else { strftime(clock_buffer, sizeof(clock_buffer), time_format, tick_time); snprintf(buf, sizeof(buf), "%c", ampm[0] == 'A' ? 'a' : 'p'); strncat(clock_buffer, buf, sizeof(time_buffer)); } p = clock_buffer; if(p[0] == ' ') p++; text_layer_set_text(time_layer, p); //strncat(time_buffer, "\n", sizeof(time_buffer)); strftime(time_buffer, sizeof(time_buffer), "%A\n%B ", tick_time); //strncat(time_buffer, buf, sizeof(time_buffer)); strftime(buf, sizeof(buf), "%e, %Y", tick_time); p = buf; if(p[0] == ' ') p++; strncat(time_buffer, p, sizeof(time_buffer)); snprintf(buf, sizeof(buf), "\nepoch: %ld", current_time + timezone_offset); strncat(time_buffer, buf, sizeof(time_buffer)); snprintf(buf, sizeof(buf), "\nbattery: %s", battery); strncat(time_buffer, buf, sizeof(time_buffer)); snprintf(buf, sizeof(buf), "\nconnected: %s", bluetooth ? "yes" : "no"); strncat(time_buffer, buf, sizeof(time_buffer)); // only show weather and location if we're connected and it has been updated if(bluetooth && last_update != -1) { if(latitude[0] != 0) { snprintf(buf, sizeof(buf), "\nlatitude: %s", latitude); strncat(time_buffer, buf, sizeof(time_buffer)); } if(longitude[0] != 0) { snprintf(buf, sizeof(buf), "\nlongitude: %s", longitude); strncat(time_buffer, buf, sizeof(time_buffer)); } if(location[0] != 0) { snprintf(buf, sizeof(buf), "\nlocation: %s", location); strncat(time_buffer, buf, sizeof(time_buffer)); } if(weather[0] != 0) { snprintf(buf, sizeof(buf), "\nweather: %s", weather); strncat(time_buffer, buf, sizeof(time_buffer)); } if(temperature != -999999) { snprintf(buf, sizeof(buf), "\ntemp: %d\u00B0%c (%d/%d)", TEMP(temperature), metric_units ? 'C' : 'F', TEMP(temperature_min), TEMP(temperature_max)); strncat(time_buffer, buf, sizeof(time_buffer)); } char unit = 's'; if(since > 3600) { since /= 3600; unit = 'h'; } else if(since > 60) { since /= 60; unit = 'm'; } snprintf(buf, sizeof(buf), "\nupdated: %ld%c ago", since, unit); if(unit == 's') snprintf(buf, sizeof(buf), "\nupdated: <1m ago"); strncat(time_buffer, buf, sizeof(time_buffer)); } p = time_buffer; if(p[0] == ' ') p++; text_layer_set_text(text_layer, p); //strftime(date_buffer, sizeof(date_buffer), "%b %e", tick_time); //text_layer_set_text(date_layer, date_buffer); }
/* Generate code for a section of the mask. first is the index we start * at, we set last to the index of the last one we use before we run * out of intermediates / constants / parameters / sources or mask * coefficients. * * 0 for success, -1 on error. */ static int pass_compile_section( Pass *pass, Morph *morph, gboolean first_pass ) { INTMASK *mask = morph->mask; const int n_mask = mask->xsize * mask->ysize; VipsVector *v; char offset[256]; char source[256]; char zero[256]; char one[256]; int i; pass->vector = v = vips_vector_new( "morph", 1 ); /* The value we fetch from the image, the accumulated sum. */ TEMP( "value", 1 ); TEMP( "sum", 1 ); CONST( zero, 0, 1 ); CONST( one, 255, 1 ); /* Init the sum. If this is the first pass, it's a constant. If this * is a later pass, we have to init the sum from the result * of the previous pass. */ if( first_pass ) { if( morph->op == DILATE ) ASM2( "copyb", "sum", zero ); else ASM2( "copyb", "sum", one ); } else { /* "r" is the result of the previous pass. */ pass->r = vips_vector_source_name( v, "r", 1 ); ASM2( "loadb", "sum", "r" ); } for( i = pass->first; i < n_mask; i++ ) { int x = i % mask->xsize; int y = i / mask->xsize; /* Exclude don't-care elements. */ if( mask->coeff[i] == 128 ) continue; /* The source. sl0 is the first scanline in the mask. */ SCANLINE( source, y, 1 ); /* The offset, only for non-first-columns though. */ if( x > 0 ) { CONST( offset, morph->in->Bands * x, 1 ); ASM3( "loadoffb", "value", source, offset ); } else ASM2( "loadb", "value", source ); /* Join to our sum. If the mask element is zero, we have to * add an extra negate. */ if( morph->op == DILATE ) { if( !mask->coeff[i] ) ASM3( "xorb", "value", "value", one ); ASM3( "orb", "sum", "sum", "value" ); } else { if( !mask->coeff[i] ) ASM3( "andnb", "sum", "sum", "value" ); else ASM3( "andb", "sum", "sum", "value" ); } if( vips_vector_full( v ) ) break; } pass->last = i; ASM2( "copyb", "d1", "sum" ); if( !vips_vector_compile( v ) ) return( -1 ); #ifdef DEBUG printf( "done matrix coeffs %d to %d\n", pass->first, pass->last ); vips_vector_print( v ); #endif /*DEBUG*/ return( 0 ); }