Ejemplo n.º 1
0
//! generate data
var* sci_circbuff::gen(var* p_v_ce)
{
 var* p_y = new var_vec;	// create var_vec;	
 vec &y = (dynamic_cast<var_vec *>(p_y))->v; // alias to vector	
 bvec ce;

	try	{
		ce = (dynamic_cast<var_bvec *>(p_v_ce))->v;
	}
	catch (bad_cast) {
		throw sci_exception ("sci_circbuff::gen - ce - bad cast");
	}

	#if (DEBUG_LEVEL==3)
		cout << "***** sci_circbuff::gen *****" << endl;	
		cout << "ce=" << ce << endl;
		go_sleep();
	#endif
	y = generate(ce);	
	#if (DEBUG_LEVEL==3)
		cout << "y=" << y << endl;
		cout << "+++++ sci_circbuff::gen +++++" << endl;	
		go_sleep();
	#endif	
	return (p_y);
};
Ejemplo n.º 2
0
var* sci_bin2int::proc( var* p_v_ce, var* p_v_x )
{
 var* p_y = new var_ivec;	// create var_ivec;	
 ivec &y = (dynamic_cast<var_ivec *>(p_y))->v; // alias to ivec	
 
 var_bvec  *p_bvec;
 bvec ce;
 var_bmat *p_bmat;
 bmat x;

	#if (DEBUG_LEVEL==3)
		cout << "***** sci_bin2int::proc *****" << endl;	
	#endif	

	p_bvec = dynamic_cast<var_bvec *>(p_v_ce); // The value of a failed cast to pointer type is the null pointer
    if (p_bvec == NULL ) {
		throw sci_exception ("sci_bin2int::proc - ce - bad cast");
	}
	ce = p_bvec->v;
	#if (DEBUG_LEVEL==3)
		cout << "ce=" << ce << endl;
	#endif	

	p_bmat = dynamic_cast<var_bmat *>(p_v_x); // The value of a failed cast to pointer type is the null pointer	
	if (p_bmat == NULL ) {		
		p_bvec = dynamic_cast<var_bvec *>(p_v_x);
		if (p_bvec == NULL ) {
			throw sci_exception ("sci_bin2int::proc - x - bad cast");
		}
	}
	if (p_bmat) {
		x = p_bmat->v;
	} else { // convert bvec to bmat - two scenarios
		if ( ce.length() > 1 ) { // x is bvec is a column 
			x.append_col(p_bvec->v);
		} else {
			x.append_row(p_bvec->v);
		}
	}
	#if (DEBUG_LEVEL==3)
		cout << "x=" << x << endl;
		go_sleep();
	#endif	

	if ( ce.length() != x.rows() ) {
			throw sci_exception ("sci_bin2int::proc - x and ce - don't match");
	}	

	y = process(ce,x);	// y is aliased to p_y->v	

	#if (DEBUG_LEVEL==3)
		cout << "y=" << y << endl;
		cout << "+++++ sci_bin2int::proc +++++" << endl;	
		go_sleep();
	#endif
	return (p_y);
};
Ejemplo n.º 3
0
//! get parameter 
var* sci_fir_up_x::get(int param)
{
var* p_var_ivec = new var_ivec;	// create var_vec;	
 ivec &iv = (dynamic_cast<var_ivec *>(p_var_ivec))->v; // alias to vector	

 var* p_var_cvec = new var_cvec;	// create var_vec;	
 cvec &cv = (dynamic_cast<var_cvec *>(p_var_cvec))->v; // alias to vector	
 	
	switch (param)
	{
	case SCI_SIZE:
		iv.set_length(1);
		iv[0] = get_size();
		#if (DEBUG_LEVEL==3)
			cout << "***** sci_fir_up_x::get SCI_SIZE  *****" << endl;	
			cout << "iv=" << iv << endl;
			cout << "+++++ sci_fir_up_x::get SCI_SIZE  ++++++" << endl;
			go_sleep();
		#endif						
		return(p_var_ivec);

	case SCI_TAPS:
		cv = get_taps();
		#if (DEBUG_LEVEL==3)
			cout << "***** sci_fir_up_x::get SCI_TAPS  *****" << endl;	
			cout << "cv=" << cv << endl;
			cout << "+++++ sci_fir_up_x::get SCI_TAPS  ++++++" << endl;
			go_sleep();
		#endif						
		return(p_var_cvec);

	case SCI_STATE:
		cv = get_input();
		#if (DEBUG_LEVEL==3)
			cout << "***** sci_fir_up_x::get SCI_STATE  *****" << endl;	
			cout << "cv=" << cv << endl;
			cout << "+++++ sci_fir_up_x::get SCI_STATE  ++++++" << endl;
			go_sleep();
		#endif						
		return(p_var_cvec);

	case SCI_OUTPUT:
		cv.set_length(1);
		cv[0] = y0;
		#if (DEBUG_LEVEL==3)
			cout << "***** sci_fir_up_x::get SCI_OUTPUT  *****" << endl;	
			cout << "cv[0]=" << cv[0] << endl;
			cout << "+++++ sci_fir_up_x::get SCI_OUTPUT  ++++++" << endl;
			go_sleep();
		#endif						
		return(p_var_cvec);

	default:
		throw sci_exception ("sci_fir_up_x::get - unknown param");	
	}	     
};
Ejemplo n.º 4
0
//! process data
var* sci_circbuff::proc(var* p_v_ce, var* p_v_x)
{
 var* p_y = new var_vec;	// create var_vec;	
 vec &y = (dynamic_cast<var_vec *>(p_y))->v; // alias to vector	
 var_bmat *p_var_bmat;
 var_bvec *p_var_bvec;
 vec x; 
 bmat ceio;

	try	{
		x = (dynamic_cast<var_vec *>(p_v_x))->v;
	}
	catch (bad_cast) {
		throw sci_exception ("sci_circbuff::proc - x - bad cast");
	}

	
	p_var_bmat = dynamic_cast<var_bmat *> (p_v_ce);
	if (p_var_bmat !=  NULL) {
		ceio = (dynamic_cast<var_bmat *>(p_v_ce))->v;
	}
	else
	{	// ceio might be [%T,%T] -> this will be converted into bvec by with 2 rows by sci_coslab layer
		p_var_bvec = dynamic_cast<var_bvec *> (p_v_ce);
		if (p_var_bvec !=  NULL) {
			if (p_var_bvec->get_rows()== 2)
			{	ceio.set_size(1,2);
				ceio.set_row(0,(dynamic_cast<var_bvec *>(p_v_ce))->v);
			}
			else
			{
				throw sci_exception ("sci_circbuff::proc - ceio - vector <> [2,1] ");
			}
		}
		else {
			throw sci_exception ("sci_circbuff::proc - ceio - bad cast");
		}
	}
		

	#if (DEBUG_LEVEL==3)
		cout << "***** sci_circbuff::proc *****" << endl;	
		cout << "ceio=" << ceio << endl;
		cout << "x=" << x << endl;
		go_sleep();
	#endif
	y = process(ceio,x);	
	#if (DEBUG_LEVEL==3)
		cout << "y=" << y << endl;
		cout << "+++++ sci_circbuff::proc +++++" << endl;	
		go_sleep();
	#endif	
	return (p_y);
};
Ejemplo n.º 5
0
//! set parameter
void sci_fir_up_x::set(int param, var* p_v)
{
 cvec cv;
 var_cvec *p_var_cvec;

	// p_v might be var_vec only
	p_var_cvec = dynamic_cast<var_cvec *> (p_v);
	if (p_var_cvec ==  NULL) {
		throw sci_exception ("sci_fir_up_x::set - p_v -  bad cast");
	}


	switch (param)
	{
	case SCI_TAPS:							
		cv = p_var_cvec->v;	
		#if (DEBUG_LEVEL==3)
		cout << "***** sci_fir_up_x::set SCI_TAPS  *****" << endl;	
		cout << "cv=" << cv << endl;
		cout << "+++++ sci_fir_up_x::set SCI_TAPS  ++++++" << endl;
		go_sleep();
		#endif	
		set_taps( cv );
		break;

	case SCI_STATE:							
		cv = p_var_cvec->v;	
		#if (DEBUG_LEVEL==3)
		cout << "***** sci_fir_up_x::set SCI_STATE  *****" << endl;	
		cout << "cv=" << cv << endl;
		cout << "+++++ sci_fir_up_x::set SCI_STATE  ++++++" << endl;
		go_sleep();
		#endif	
		set_state( cv );
		break;

	case SCI_OUTPUT:
		cv = p_var_cvec->v;
		#if (DEBUG_LEVEL==3)
		cout << "***** sci_fir_up_x::set SCI_OUTPUT  *****" << endl;	
		cout << "cv=" << cv << endl;
		cout << "+++++ sci_fir_up_x::set SCI_OUTPUT  ++++++" << endl;
		go_sleep();
		#endif	
		y0= cv[0];
		break;

	default:
		throw sci_exception ("sci_fir_up_x::set - unknown param");
	}
	return;
}
Ejemplo n.º 6
0
//! process data
var* sci_psk_dem::proc( var* p_v_ce, var* p_v_x )
{
 var* p_y = new var_ivec;	// create var_cvec;	
 ivec &y = (dynamic_cast<var_ivec *>(p_y))->v; // alias to cvec	
 
 var_bvec  *p_var_bvec;
 bvec ce;
 var_cvec *p_var_cvec;
 cvec x;

	#if (DEBUG_LEVEL==3)
		cout << "***** sci_psk_dem::proc *****" << endl;	
	#endif	

	p_var_bvec = dynamic_cast<var_bvec *>(p_v_ce); // The value of a failed cast to pointer type is the null pointer
    if (p_var_bvec == NULL ) {
		throw sci_exception ("sci_psk_mod::proc - ce - bad cast");
	}
	ce = p_var_bvec->v;
	#if (DEBUG_LEVEL==3)
		cout << "ce=" << ce << endl;
	#endif	

	p_var_cvec = dynamic_cast<var_cvec *>(p_v_x); // The value of a failed cast to pointer type is the null pointer	
	if (p_var_cvec == NULL ) {		
		throw sci_exception ("sci_psk_dem::proc - x - bad cast");
	}
	x = p_var_cvec->v;
	#if (DEBUG_LEVEL==3)
		cout << "x=" << x << endl;
		go_sleep();
	#endif	

	if ( ce.length() != x.length() ) {
			throw sci_exception ("sci_psk_dem::proc - x and ce - don't match");
	}	

	y = process(ce,x);	// y is aliased to p_v_y->v and p_y->v	

	#if (DEBUG_LEVEL==3)
		cout << "y=" << y << endl;
		cout << "+++++ sci_psk_dem::proc +++++" << endl;	
		go_sleep();
	#endif
	return (p_y);
};
Ejemplo n.º 7
0
//! process data
var* sci_fir_up_x::proc( var* p_v_ce, var* p_v_x)
{
 var* p_y = new var_cvec;	// create var_vec;	
 cvec &y = (dynamic_cast<var_cvec *>(p_y))->v; // alias to vector	
 cvec x; 
 bmat ce;

	try {
		x = (dynamic_cast<var_cvec *>(p_v_x))->v;
	}
	catch (bad_cast) {
		throw sci_exception ("sci_fir_up_x::proc - x - bad cast");
	}

	try {
		ce = (dynamic_cast<var_bmat *>(p_v_ce))->v;
	}
	catch (bad_cast) {
		throw sci_exception ("sci_fir_up_x::proc - ce - bad cast");
	}

	#if (DEBUG_LEVEL==3)
		cout << "***** sci_fir_up_x::proc *****" << endl;	
		cout << "ce=" << ce << endl;
		cout << "x=" << x << endl;
		go_sleep();
	#endif
	y=process(ce,x);	
	#if (DEBUG_LEVEL==3)
		cout << "y=" << y << endl;
		cout << "+++++ sci_fir_up_x::proc +++++" << endl;	
		go_sleep();
	#endif	
	return (p_y);

};
Ejemplo n.º 8
0
void secret_button()
{
    static unsigned long but1;
    but1 = millis();
    Serial.println(F("1"));
    while(!digitalRead(ON_PIN)){
        delay(20);
        if (millis() > but1 + 5000){
            go_sleep();
        }
    }
    but1 = millis();
    while(millis() < but1 + BUTTON1_DELAY){delay(20);
        if(!digitalRead(ON_PIN)){
            Serial.println(F("2"));
            while(!digitalRead(ON_PIN)){delay(20);}
            but1 = millis();
            while(millis() < but1 + BUTTON1_DELAY){delay(20);
                if(!digitalRead(ON_PIN)){
                    Serial.println(F("3"));
                    while(!digitalRead(ON_PIN)){delay(20);}
                    but1 = millis();
                    while(millis() < but1 + BUTTON1_DELAY){delay(20);
                        if(!digitalRead(ON_PIN)){
                            Serial.println(F("4"));
                            while(!digitalRead(ON_PIN)){delay(20);}
                            but1 = millis();
                            while(millis() < but1 + BUTTON1_DELAY){delay(20);
                                if(!digitalRead(ON_PIN)){
                                    Serial.println(F("5"));
                                    but1 = millis();
                                    while(!digitalRead(ON_PIN)){delay(20);
                                        Serial.println(F("6"));
                                        if(millis() > but1 + 800){
                                            Serial.println(F("Release now!"));

                                            lcd.clear();
                                            lcd.setCursor(0, 0);
                                            lcd.print(F("Release now!"));
                                            delay(500);

                                            lcd.clear();
                                            lcd.setCursor(0, 0);
                                            lcd.print(F("Press: open box"));
                                            lcd.setCursor(0,1);
                                            lcd.print(F("Hold: reset game"));

                                            delay(1000);

                                            while(digitalRead(ON_PIN)){}
                                            but1 = millis();
                                            while(!digitalRead(ON_PIN)){delay(20);}

                                            if(millis() - but1 > 1000){
                                                lcd.clear();
                                                lcd.print(F("RESET GAME!"));
                                                delay(3000);
                                                target = 1;
                                                EEPROM.write(EEPROM_TARGET_INDEX, 1);

                                                break;
                                            }
                                            else {
                                                open_box();
                                                delay(15000);
                                                close_box();
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Ejemplo n.º 9
0
void loop()
{
    //Serial.print(F("Free RAM1:"));    Serial.println(freeRam());

    // Check secret button
    but = !digitalRead(ON_PIN);
    if(but){
        Serial.println(F("Button pressed"));
        secret_button();
    }

    bool GPS_debug = 0;
    unsigned long t = millis();
    while (ss.available() > 0 || t + 1100 < millis()){
        gps.encode(ss.read());
        GPS_debug = 1;
    }
    if (GPS_debug) {
        Serial.println(F("GPS received"));
        GPS_debug = 0;
    }


    sats_fix = gps.satellites.value();
    hdop = gps.hdop.value();
    position_lat = gps.location.lat();
    position_lon = gps.location.lng();

    //target = 3; // debug
    distance = gps.distanceBetween(position_lat, position_lon, target_lat[target], target_lon[target]);

    //distance = 4; // debug

    static int sim, ok;
#ifdef SIMULATION
    if (but == 1){
        sim = 1;
        delay (1000);
    }
    else {
        sim = 0;
        lcd.setCursor(14, 1);
        lcd.print(target);
    }

    if (distance > 30 && sim == 0){
#else
    if (distance > 30) {
#endif
        lcd_target(lcd, target, distance, sats_fix);
    }
    else {

#ifdef BUTTON_FOR_NEXT_STEP
        wait finish;
        finish.set_time(2500);
        finish.set_steps(2);
        lcd.setCursor(0, 0);

        if(finish.step() == 1){
            lcd.print(F("You are at your "));
            lcd.setCursor(0, 1);
            lcd.print(F("current target."));
        }
        if (finish.step() == 2){
            lcd.setCursor(0, 0);
            lcd.print(F("Press the button"));
            lcd.setCursor(0, 1);
            lcd.print(F("to continue...  "));
        }

        if (but == 1){
            // Go to next target
            target++;
            ok = 1;



        }
#else
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print(F("You are at your "));
        lcd.setCursor(0, 1);
        lcd.print(F("current target."));
        target++;
        delay(5000);
        but = 0;
#endif
        // Open the box at the end of game
        if(target > NUMBER_OF_TARGETS){
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print(F("CONRATULATIONS! "));
            delay(5000);
            open_box();
        }
        else {
            EEPROM.write(EEPROM_TARGET_INDEX, target);
        }

    }

    if(millis() > update_time + 1000){
        update_time = millis();

        Serial.println(gps.location.lat(), 6);
        Serial.print(F("LAT="));  Serial.println(gps.location.lat(), 6);
        Serial.print(F("LONG=")); Serial.println(gps.location.lng(), 6);
        Serial.print(F("ALT="));  Serial.println(gps.altitude.meters());
        Serial.print(F("hdop="));  Serial.println(hdop);
        Serial.print(F("sats="));  Serial.println(sats_fix);

        if(hdop < 500 && sats_fix > 4){
            fix = 1;
            distance = gps.distanceBetween(position_lat, position_lon, TARGET_1_LAT, TARGET_1_LON);
        }
        else{
            fix = 0;
            strength = sats_fix;
            //lcd_gps_signal(lcd, strength);
        }
    }

    if(millis() > sleep_time + SLEEP_TIME_MS){
        go_sleep();
    }
}

void go_sleep(void)
{
    lcd.clear();
    lcd.print(F("Going to sleep.."));
    delay(2000);
    pinMode(ON_PIN, OUTPUT);
    digitalWrite(ON_PIN, 0);
}
Ejemplo n.º 10
0
// the loop routine runs over and over again forever:
void loop() {
  byte lclocktick=0;
 //       int j;
	//    analogWrite(9, 60);
	//  TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
	//  TCCR2B = _BV(CS22);
	//  OCR2A = 180;
	//  OCR2B = 50;

	//  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
	if(!(laserstate||lightstate||command_pending))
	{
              
            if(sleepcounter==0)
            {
                attachInterrupt(0, int0, LOW);

		WDT_Stop();
                set_led(led,&ledstate,0);
               set_led(led2,&ledstate2,0);
//                delay(100);
		go_sleep();
                int0f();
		WDT_Init();
            }
	}
        else
            sleepcounter=SLEEPIDLESECS;
        if(clocktick)
        {
          cli();
            lclocktick=clocktick;
            clocktick=0;
          sei();
       	set_led(led,&ledstate,0);

            wdtcounter+=lclocktick;
            sleepcounter--;
           if(!(wdtcounter%BATCHECKSECS))
               checkbat=1;
            if(laserstate)
            		lasercounter++;
            
             if(lightstate)
			lightcounter++;


        }

	if(command_pending==2)
	{
		btnpress();

		command_pending=0;
            

	}
	if(command_pending==1&&millis()-timepressed>LONGBUTTONPRESS)
		int0r();
//	toggle_led(led2,&ledstate2);

	if(laserstate&&(lasercounter>LASER_MAX_ON))
	{
		set_laser(0);
                laserstate=0;

	}
	if(lightstate&&(lightcounter>LIGHT_MAX_ON))
	{
              set_lights(0);
              lightstate=0;
	}

        if(checkbat)
        {
          check_bat();
          checkbat=0;
        }
        if(volts<VBATTHRESH)
        {
             if(lclocktick)
         	    toggle_led(led2,&ledstate2);   
        }
        else   
            set_led(led2,&ledstate2,0);      
        if(volts<VBATTHRESH_CRIT)
        {
          if(!(wdtcounter%BATCHECKCRITSECS))
          {
   //         for(j=0;j<3;j++)
   //         {
              set_lights(0);
              delay(100);
              set_lights(lightstate);
               delay(100);
   //         }
            
          }
          
        }            


	//delay(100);
	//  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
	//  delay(500);               // wait for a second
}