Example #1
0
//Runs pacman or other animation, refreshes weather data
void pacClear() {
	DEBUGpln("in pacClear");
	//refresh weather if we havent had it for 30 mins
	//or the last time we had it, it was bad,
	//or weve never had it before.

#ifdef FACE_WEATHER
	if((millis()>lastWeatherTime+1800000) || lastWeatherTime==0 || !weatherGood) getWeather();

	if(!wasWeatherShownLast && weatherGood){
		showWeather();
		wasWeatherShownLast = true;
	}
	else{
		wasWeatherShownLast = false;

		pacMan();
	}
#else
	pacMan();
#endif
}
Example #2
0
static void initialise()
{
	if (self->active == TRUE)
	{
		if (self->mental == 0)
		{
			if (strcmpignorecase(getWeather(), "HEAVY_RAIN") != 0)
			{
				self->flags &= ~NO_DRAW;

				setWeather(HEAVY_RAIN);

				playDefaultBossMusic();
			}

			centerMapOnEntity(NULL);

			self->action = &doIntro;

			self->thinkTime = 60;

			self->endX = 0;

			self->touch = &entityTouch;

			setContinuePoint(FALSE, self->name, NULL);
		}

		else
		{
			self->action = &appear;
		}
	}

	checkToMap(self);
}
Example #3
0
static void canvas_update_proc(Layer *this_layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(this_layer);
  
  uint16_t ms_start = time_ms(NULL, NULL);
  
  graphics_context_set_antialiased(ctx, true);
  
  if (!isBtConnected) {
	graphics_context_set_fill_color(ctx, GColorDukeBlue);
	graphics_fill_rect(ctx, bounds, 0, GCornerNone);
  } else {
	graphics_context_set_fill_color(ctx, GColorBlack);
	graphics_fill_rect(ctx, bounds, 0, GCornerNone);
  }
    
  graphics_context_set_fill_color(ctx, GColorBlack);    
    
  uint16_t ms_fill = time_ms(NULL, NULL);
  
  graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorRed, GColorWhite));
#if defined(PBL_PLATFORM_APLITE) || defined(PBL_PLATFORM_DIORITE)
  graphics_context_set_stroke_width(ctx, 1);
#else
    graphics_context_set_stroke_width(ctx, 3);
#endif 
  graphics_draw_line(ctx, GPoint(bounds.size.w/2, 0), GPoint(bounds.size.w/2, bounds.size.h));
  
  graphics_context_set_stroke_color(ctx, GColorWhite);
  
  int hour_loc = bounds.size.h/2;
  
  if(ctick_time->tm_min < 20)
  	draw_hour(this_layer, ctx, -1, tz2, hour_loc, FONT_KEY_ROBOTO_BOLD_SUBSET_49, 49);
  draw_hour(this_layer, ctx,    0, tz2, hour_loc, FONT_KEY_ROBOTO_BOLD_SUBSET_49, 49);
  draw_hour(this_layer, ctx,    1, tz2, hour_loc, FONT_KEY_ROBOTO_BOLD_SUBSET_49, 49);
  if(ctick_time->tm_min > 50)
  	draw_hour(this_layer, ctx,  2, tz2, hour_loc, FONT_KEY_ROBOTO_BOLD_SUBSET_49, 49);
  
  graphics_context_set_stroke_width(ctx, 1);
  uint16_t ms_hour = time_ms(NULL, NULL);
  
  draw_minutes(this_layer, ctx, bounds.size.h/2+49/2+5);
  
  uint16_t ms_day = time_ms(NULL, NULL);
  
  int day_loc = bounds.size.h/2-49/2-12;

  draw_day(this_layer, ctx, -1, day_loc);
  draw_day(this_layer, ctx, 0, day_loc);
  draw_day(this_layer, ctx, 1, day_loc);
  draw_day(this_layer, ctx, 2, day_loc);

  draw_day_ticks(this_layer, ctx, bounds.size.h/2-49/2-12);
  
  if (temp != INVALID_TEMP) {
    draw_temp(this_layer, ctx, bounds.size.h/2+75);
  } 
  
  getWeather();
  getForecast();
  
  uint16_t ms_end = time_ms(NULL, NULL);
  
  draw_bat(this_layer, ctx, 0);
  
#if defined(PBL_HEALTH)
  // Check step data is available
  HealthServiceAccessibilityMask mask = health_service_metric_accessible(HealthMetricStepCount, 
                                                                    time_start_of_today(), cur_time);
  
  if(mask & HealthServiceAccessibilityMaskAvailable) {
    // Data is available!
    int total_steps = (int)health_service_sum_today(HealthMetricStepCount);
    draw_step(this_layer, ctx, 22, total_steps);
  }
  
  time_t end_time = time(NULL);
  time_t start_time = end_time - 600;
  
  HealthServiceAccessibilityMask hr = health_service_metric_accessible(HealthMetricHeartRateBPM, start_time, end_time);
  if (hr & HealthServiceAccessibilityMaskAvailable) {
    uint32_t bpm = health_service_peek_current_value(HealthMetricHeartRateBPM);
    APP_LOG(APP_LOG_LEVEL_INFO, "HR: %d", (int)bpm);
    draw_bpm(this_layer, ctx, 9, bpm);
  }
#endif
  
  static int repaints = 0; 
  ++repaints;
  
  ms_fill = ms_fill < ms_start ? ms_fill + 1000 : ms_fill;
  ms_hour = ms_hour < ms_start ? ms_hour + 1000 : ms_hour;
  ms_day = ms_day < ms_start ? ms_day + 1000 : ms_day;
  ms_end = ms_end < ms_start ? ms_end + 1000 : ms_end;
  
  static uint16_t tt_max = 0;
  if ((ms_end-ms_start) > tt_max)
  	tt_max = ms_end-ms_start;
  
}
Example #4
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  // Get the first pair
  Tuple *data = dict_read_first(iterator);
  while (data) {
    APP_LOG(APP_LOG_LEVEL_INFO, "Key received: %d", (int)data->key);
    if (data->key == MESSAGE_KEY_AppKeyReady) {
        isJSRunning = true;
        getWeather();
        getForecast();
    } else if (data->key == MESSAGE_KEY_TEMP) {
        temp = data->value->int32;
        temp_age = cur_time;
        persist_write_int(MESSAGE_KEY_TEMP, temp);
        persist_write_int(MESSAGE_KEY_CONFIG_TEMP_AGE, cur_time);
        APP_LOG(APP_LOG_LEVEL_INFO, "Temp received: %d", temp);
    } else if (data->key == MESSAGE_KEY_TEMP_FORE_MIN) {
        temp_fore_min = data->value->int32;
        persist_write_int(MESSAGE_KEY_TEMP_FORE_MIN, temp_fore_min);
        persist_write_int(MESSAGE_KEY_CONFIG_FORE_AGE, cur_time);
        temp_fore_age = cur_time;
        APP_LOG(APP_LOG_LEVEL_INFO, "Temp min received: %d", temp_fore_min);
    } else if (data->key == MESSAGE_KEY_TEMP_FORE_MAX) {
        temp_fore_max = data->value->int32;
        persist_write_int(MESSAGE_KEY_TEMP_FORE_MAX, temp_fore_max);
        persist_write_int(MESSAGE_KEY_CONFIG_FORE_AGE, cur_time);
        temp_fore_age = cur_time; 
        APP_LOG(APP_LOG_LEVEL_INFO, "Temp max received: %d", temp_fore_max);
    } else if (data->key == MESSAGE_KEY_CONFIG_TZ_OFFSET) {
        switch (data->type) {
          case TUPLE_BYTE_ARRAY:
            APP_LOG(APP_LOG_LEVEL_INFO, "tz2 can't handle a byte array");
            break;
          case TUPLE_CSTRING:
          {
            char *str = data->value->cstring;
            bool neg = false;
            if (str[0] == '-') {
              neg = true;
              str += 1;
            } else if(str[0] == '+') {
              str += 1;
            }
            tz2 = atoi(str);
            if (neg) {
              tz2 *= -1;
            }
            break;
          }
          case TUPLE_INT:
          case TUPLE_UINT:
            tz2 = data->value->int32;
            break;
        }
        persist_write_int(MESSAGE_KEY_CONFIG_TZ_OFFSET, tz2);
        APP_LOG(APP_LOG_LEVEL_INFO, "Tz2: %d type: %d", tz2, data->type);
    } else if(data->key == MESSAGE_KEY_CONFIG_METRIC) {
        metric = data->value->int8;
        persist_write_int(MESSAGE_KEY_CONFIG_METRIC, metric);
        APP_LOG(APP_LOG_LEVEL_INFO, "Metric: %d %ld %d %d", metric, data->value->int32, data->value->int16, data->type);
    } else if(data->key == MESSAGE_KEY_CONFIG_BUZZ) {
        buzz = data->value->int8;
        persist_write_int(MESSAGE_KEY_CONFIG_BUZZ, buzz);
        APP_LOG(APP_LOG_LEVEL_INFO, "Buzz: %d", buzz);
    } else if(data->key == MESSAGE_KEY_CONFIG_BUZZ_MUTE) {
        buzz_mute = data->value->int8;
        persist_write_int(MESSAGE_KEY_CONFIG_BUZZ_MUTE, buzz_mute);
        APP_LOG(APP_LOG_LEVEL_INFO, "Buzz Mute: %d", buzz_mute);
    }
    data = dict_read_next(iterator);
  } 
  layer_mark_dirty(s_layer);
}
void printForecast(size_t woeid, char* unit) {
    struct Weather weather = getWeather(woeid, unit);

    printf("location\n");
    printf("woeid: %zd\n", weather.woeid);
    printf("city: %s\n", weather.city);
    printf("country: %s\n", weather.country);
    printf("region: %s\n", weather.region);
    printf("\n");

    printf("wind\n");
    printf("chill: %zd\n", weather.wind.chill);
    printf("direction: %zd°\n", weather.wind.direction);
    printf("speed: %.2f %s\n", weather.wind.speed, weather.units.speed);
    printf("\n");

    printf("atmosphere\n");
    printf("humidity: %zd\n", weather.atmosphere.humidity);
    printf("pressure: %.2f %s\n", weather.atmosphere.pressure, weather.units.pressure);
    printf("rising: %zd\n", weather.atmosphere.rising);
    printf("visibility: %zd\n", weather.atmosphere.visibility);
    printf("\n");

    printf("astronomy\n");
    if (strcmp(unit, "c") == 0) {
        printf("sunrise: ");
        if (weather.astronomy.sunrise_hour < 10)
            printf("0");
        printf("%zd:", weather.astronomy.sunrise_hour);
        if (weather.astronomy.sunrise_minute < 10)
            printf("0");
        printf("%zd\n", weather.astronomy.sunrise_minute);

        printf("sunset: ");
        if (weather.astronomy.sunset_hour < 10)
            printf("0");
        printf("%zd:", weather.astronomy.sunset_hour);
        if (weather.astronomy.sunset_minute < 10)
            printf("0");
        printf("%zd\n", weather.astronomy.sunset_minute);
    }
    else if (strcmp(unit, "f") == 0) {
        printf("sunrise: ");
        if (weather.astronomy.sunrise_hour > 11) {
            printf("%zd:", weather.astronomy.sunrise_hour - 12);
            if (weather.astronomy.sunrise_minute < 10)
                printf("0");
            printf("%zd pm\n", weather.astronomy.sunrise_minute);
        }
        else {
            printf("%zd:", weather.astronomy.sunrise_hour);
            if (weather.astronomy.sunrise_minute < 10)
                printf("0");
            printf("%zd am\n", weather.astronomy.sunrise_minute);
        }

        printf("sunset: ");
        if (weather.astronomy.sunset_hour > 11) {
            printf("%zd:", weather.astronomy.sunset_hour - 12);
            if (weather.astronomy.sunset_minute < 10)
                printf("0");
            printf("%zd pm\n", weather.astronomy.sunset_minute);
        }
        else {
            printf("%zd:", weather.astronomy.sunset_hour);
            if (weather.astronomy.sunset_minute < 10)
                printf("0");
            printf("%zd am\n", weather.astronomy.sunset_minute);
        }
    }
    printf("\n");

    printf("condition\n");
    printf("code: %s\n", conditions[weather.code]);
    printf("temperature: %zd°%s\n", weather.temp, weather.units.temperature);
    printf("\n");

    size_t i;
    for (i = 0; i < 5; i++) {
        printf("forecast %zd\n", i);
        printf("code: %s\n", conditions[weather.temperature[i].code]);
        printf("date: %s\n", weather.temperature[i].date);
        printf("day: %s\n", weather.temperature[i].day);
        printf("high: %zd°%s\n", weather.temperature[i].high, weather.units.temperature);
        printf("low: %zd°%s\n", weather.temperature[i].low, weather.units.temperature);
        printf("\n");
    }
}
Example #6
0
int main (int argc, char *argv [])
{
    int loadSpi=FALSE;
    int analogChannel=0;
    int spiChannel=0;
    int channelConfig=CHAN_CONFIG_SINGLE;
    int print_once;
    int modus_operandi = 1;
    int mode_flag=1;
    int rows = 2;
    int cols = 16;
    int bits = 4; //4 bit mode
    char buf [32];
    char tempbuf [32];
    char weatherBuff;
    char *tempmsg;
    int lcd;
    struct tm *t ;
    time_t tim ;
    int i;
    int max_distance;
    int curr_distance;
  /*
    if (argc < 2)
    {
        fprintf (stderr, "%s\n", usage) ;
        return 1 ;
    }
    if((strcasecmp (argv [1], "all") == 0) )
        argv[1] = "0";
    if ( (sscanf (argv[1], "%i", &analogChannel)!=1) || analogChannel < 0 || analogChannel > 8 )
    {
        printf ("%s\n",  usage) ;
        return 1 ;
    }
    int i;
    for(i=2; i<argc; i++)
    {
        if (strcasecmp (argv [i], "-l") == 0 || strcasecmp (argv [i], "-load") == 0)
            loadSpi=TRUE;
        else if (strcasecmp (argv [i], "-ce1") == 0)
            spiChannel=1;
        else if (strcasecmp (argv [i], "-d") == 0 || strcasecmp (argv [i], "-diff") == 0)
            channelConfig=CHAN_CONFIG_DIFF;
    }
  */
    //
    if(loadSpi==TRUE)
        loadSpiDriver();
    wiringPiSetup () ;
    //set button input
   // pinMode(BUTTON, INPUT);	
    spiSetup(spiChannel);
    i = 0;
    print_once = 0;
    
    if (bits == 4)
	lcdHandle = lcdInit (rows, cols, 4, 11,15, 4,5,6,7,0,0,0,0) ;
    else
	lcdHandle = lcdInit (rows, cols, 8, 11,15, 0,1,2,3,4,5,6,7) ;

  if (lcdHandle < 0)
  {
    fprintf (stderr, "%s: lcdInit failed\n", argv [0]) ;
    return -1 ;
  }
//-------------Begin Infinite Loop
pinMode(27, OUTPUT);
//digitalWrite(27, HIGH);
pinMode(23, OUTPUT);
digitalWrite(27,LOW);
digitalWrite(23,LOW);
//sendEmail();
printf("grabbing weather data\n");
getWeather();
printf("weather is: %s\n", filestring);
delay(20);

/*set initial distance for ultrasonic sensor*/

	ZonicSetup();
	max_distance = getZonicCM();

while(1){

//ZonicSetup();
curr_distance = getZonicCM();
if (digitalRead(MODUS_OPERANDI_PIN) == LOW)
	{mode_flag = (mode_flag+1)%2;
	delay(500);}
/*else if (digitalRead(MODUS_OPERANDI_PIN) == HIGH)
	{mode_flag = 0;}
*/
/*MODE_FLAG = 0.....HOME MODE
MODE_FLAG = 1......AWAY MODE */
/*MAYBE ADD SET APPLIANCE MODE*/
printf("How fast is this while?\n");

/*HOME MODE
*
*Display Temperature and Date on LCD
*
*/
	if (mode_flag == 1){
		digitalWrite(27,LOW);
		digitalWrite(23,HIGH);


		tim = time (NULL) ;
		 t = localtime (&tim) ;

		 sprintf (buf, "%02d:%02d:%02d   %02d/%02d", t->tm_hour, t->tm_min, t->tm_sec, t->tm_mon, t->tm_mday) ;

		 //lcdPosition (lcdHandle, (cols - 8) / 2, 1) ;
		 lcdPosition (lcdHandle, 0, 1);
		 lcdPuts     (lcdHandle, buf) ;

//printf("got here1\n");
 //pingPong (lcd, cols) ;

		temp = steinhartAndHart(myAnalogRead(0,8,0));
		sprintf (tempbuf,"        TEMP:%.0fC   WEATHER: %s  MODE:HOME              ", temp,filestring); 
		tempmsg = tempbuf;
		lcdPosition (lcdHandle, 0, 1);
		scrollMessage(tempmsg,0, 16);
		//scrollMessage(weatherBuff, 0, 16);
		//lcdPuts (lcdHandle, tempbuf);
//		lcdPuts (lcdHandle, chr(223));
 
//	printf("mode_flag = %d\n", mode_flag);
/*		if (digitalRead(BUTTON) == LOW){
			printf("\n------HOME MODE--------\n");
			printf("Thermistor Output (Channel 1):\n");
			printf("-----------------\n");
			temp = steinhartAndHart(myAnalogRead(0,8,0));
			sprintf (tempbuf, "Temp: %.02d C", temp); 
			lcdPosition (lcdHandle, 0, 0);
			lcdPuts (lcdHandle, tempbuf);
			printf("Celsius: %.02f\n", temp);		//print out temperature in Celsius
			temp = (temp * 9.0)/5.0 + 32.0;
			printf("Fahrenheit: %.02f\n", temp);		//print out temperature in Fahrenheit
			//delay(170);
			}
*/
		}


/*AWAY MODE
*
*TAKE IN LDR AND SONIC SENSOR DATA
*
*/
	else {
		 digitalWrite(23,LOW);
		 digitalWrite(27,HIGH);
		
		//printf("mode_flag = %d\n", mode_flag);
		//delay(500);
		//mode_flag = 0; //do something
		/*
		if (curr_distance < max_distance){
			printf("Intruder at %d!\n",getZonicCM());
			}*/
		 printf("%d cm\n", getZonicCM());
		 tim = time (NULL) ;
		 t = localtime (&tim) ;

		 sprintf (buf, "%02d:%02d:%02d   %02d/%02d", t->tm_hour, t->tm_min, t->tm_sec, t->tm_mon, t->tm_mday) ;

		 //lcdPosition (lcdHandle, (cols - 8) / 2, 1) ;
		 lcdPosition (lcdHandle, 0, 1);
		 lcdPuts     (lcdHandle, buf) ;


		temp = steinhartAndHart(myAnalogRead(0,8,0));
		sprintf (tempbuf, "                Temp:%.0fC   MODE:AWAY                 ", temp); 
		lcdPosition (lcdHandle, 0, 0);
		//lcdPuts (lcdHandle, tempbuf);
		scrollMessage(tempbuf,0,16);
//		printf("got here1\n");
/*ULTRASONIC SENSOR*/			
	//	printf("Distance: %dcm\n",getZonicCM());
	//	delay(2000);
		/*
		if (digitalRead(BUTTON) == LOW){
			printf("\n------AWAY MODE------\n");
			printf("LDR Output (Channel 2):\n");
			printf("LDR Output: %d\n", myAnalogRead(0,8,1));
			printf("-----------------\n");
			//delay(200);
		}
		*/
	}
}
return 0;
}