예제 #1
0
파일: atlas.c 프로젝트: gabeg805/Atlas
// Display the atlas statusbar
int main(int argc, char **argv) {
    
    // Enable multi threading
    XInitThreads();
    
    // Initialize gtk toolkit
    gtk_init(&argc, &argv);
    
    // Setup widgets
    set_style();
    
    // Display widgets
    display_frame();
    display_tags(1);
    display_date(attrList);
    display_battery();
    display_wifi();
    display_volume();
    display_brightness();
    
    signal(SIGUSR1, widget_updater);
    
    // Run the gtk loop
    gtk_main();
    
    return 0;    
}
예제 #2
0
int display_qvariant(char *buf) {
	char *orig_buf=buf;
	uint32_t type = *((uint32_t*)buf);
	type=ntohl(type);
	buf+=4;
	char null=*buf;
	buf++;
	if(null) {
		//Nothing to do
	}
	switch(type) {
		case 1:
			buf+=display_bool(buf);
			break;
		case 2:
		case 3:
			buf+=display_int(buf, type);
			break;
		case 7:
			//UTF16 byte
			buf+=display_short(buf);
			break;
		case 8:
			buf+=display_map(buf);
			break;
		case 9:
			buf+=display_list(buf);
			break;
		case 10:
			buf+=display_string(buf);
			break;
		case 11:
			buf+=display_stringlist(buf);
			break;
		case 12:
			buf+=display_bytearray(buf);
			break;
		case 15:
			buf+=display_time(buf);
			break;
		case 16:
			buf+=display_date(buf);
			break;
		case 127:
			//User type !
			buf+=display_usertype(buf);
			break;
		case 133:
			buf+=display_short(buf);
			break;
		default:
			printf("Unknown QVariant type: %d\n", type);
			exit(-1);
			break;
	};
	return buf-orig_buf;
}
예제 #3
0
void set_date(void) {
  uint8_t mode = SHOW_MENU;

  timeoutcounter = INACTIVITYTIMEOUT;;  

  while (1) {
    if (just_pressed || pressed) {
      timeoutcounter = INACTIVITYTIMEOUT;;  
      // timeout w/no buttons pressed after 3 seconds?
    } else if (!timeoutcounter) {
      //timed out!
      displaymode = SHOW_TIME;     
      return;
    }
    if (just_pressed & 0x1) { // mode change
      return;
    }
    if (just_pressed & 0x2) {

      just_pressed = 0;
      if (mode == SHOW_MENU) {
	// start!
	if (region == REGION_US) {
	  mode = SET_MONTH;
	}
	else {
	  DEBUGP("Set day");
	  mode = SET_DAY;
	}
	display_date(DATE);
	display[1] |= 0x1;
	display[2] |= 0x1;
      } else if (((mode == SET_MONTH) && (region == REGION_US)) ||
		 ((mode == SET_DAY) && (region == REGION_EU))) {
	if (region == REGION_US)
	  mode = SET_DAY;
	else
	  mode = SET_MONTH;
	display_date(DATE);
	display[4] |= 0x1;
	display[5] |= 0x1;
      } else if (((mode == SET_DAY) && (region == REGION_US)) ||
	((mode == SET_MONTH) && (region == REGION_EU))) {
	mode = SET_YEAR;
	display_date(DATE);
	display[7] |= 0x1;
	display[8] |= 0x1;
      } else {
	displaymode = NONE;
	display_date(DATE);
	delayms(1500);
	displaymode = SHOW_TIME;
	return;
      }
    }
    if ((just_pressed & 0x4) || (pressed & 0x4)) {
      just_pressed = 0;
      if (mode == SET_MONTH) {
	date_m++;
	if (date_m >= 13)
	  date_m = 1;
	display_date(DATE);
	if (region == REGION_US) {
	  display[1] |= 0x1;
	  display[2] |= 0x1;
	} else {
	  display[4] |= 0x1;
	  display[5] |= 0x1;
	}
	eeprom_write_byte((uint8_t *)EE_MONTH, date_m);    
      }
      if (mode == SET_DAY) {
	date_d++;
	if (date_d > 31)
	  date_d = 1;
	display_date(DATE);

	if (region == REGION_EU) {
	  display[1] |= 0x1;
	  display[2] |= 0x1;
	} else {
	  display[4] |= 0x1;
	  display[5] |= 0x1;
	}
	eeprom_write_byte((uint8_t *)EE_DAY, date_d);    
      }
      if (mode == SET_YEAR) {
	date_y++;
	date_y %= 100;
	display_date(DATE);
	display[7] |= 0x1;
	display[8] |= 0x1;
	eeprom_write_byte((uint8_t *)EE_YEAR, date_y);    
      }

      if (pressed & 0x4)
	delayms(60);
    }
  }
}
예제 #4
0
int main(void) {
  //  uint8_t i;
  uint8_t mcustate;

  // turn boost off
  TCCR0B = 0;
  BOOST_DDR |= _BV(BOOST);
  BOOST_PORT &= ~_BV(BOOST); // pull boost fet low

  // check if we were reset
  mcustate = MCUSR;
  MCUSR = 0;

  wdt_disable();
  // now turn it back on... 2 second time out
  //WDTCSR |= _BV(WDP0) | _BV(WDP1) | _BV(WDP2);
  //WDTCSR = _BV(WDE);
  wdt_enable(WDTO_2S);
  kickthedog();

  // we lost power at some point so lets alert the user
  // that the time may be wrong (the clock still works)
  timeunknown = 1;

  // have we read the time & date from eeprom?
  restored = 0;

  // setup uart
  uart_init(BRRL_192);
  //DEBUGP("VFD Clock");
  DEBUGP("!");

  //DEBUGP("turning on anacomp");
  // set up analog comparator
  ACSR = _BV(ACBG) | _BV(ACIE); // use bandgap, intr. on toggle!
  // settle!
  if (ACSR & _BV(ACO)) {
    // hmm we should not interrupt here
    ACSR |= _BV(ACI);

    // even in low power mode, we run the clock 
    DEBUGP("clock init");
    clock_init();  

  } else {
    // we aren't in low power mode so init stuff

    // init io's
    initbuttons();
    
    VFDSWITCH_PORT &= ~_BV(VFDSWITCH);
    
    DEBUGP("turning on buttons");
    // set up button interrupts
    DEBUGP("turning on alarmsw");
    // set off an interrupt if alarm is set or unset
    EICRA = _BV(ISC00);
    EIMSK = _BV(INT0);
  
    displaymode = SHOW_TIME;
    DEBUGP("vfd init");
    vfd_init();
   
    dimmer_init();
 
    DEBUGP("boost init");
    brightness_level = eeprom_read_byte((uint8_t *)EE_BRIGHT);
    boost_init(brightness_level);
    sei();

    region = eeprom_read_byte((uint8_t *)EE_REGION);
    
    DEBUGP("speaker init");
    speaker_init();

    beep(4000, 1);

    DEBUGP("clock init");
    clock_init();  

    DEBUGP("alarm init");
    setalarmstate();
  }
  DEBUGP("done");
  while (1) {
    //_delay_ms(100);
    kickthedog();
    //uart_putc_hex(ACSR);
    if (ACSR & _BV(ACO)) {
      // DEBUGP("SLEEPYTIME");
      gotosleep();
      continue;
    }
    //DEBUGP(".");
    if (just_pressed & 0x1) {
      just_pressed = 0;
      switch(displaymode) {
      case (SHOW_TIME):
	displaymode = SET_ALARM;
	display_str("set alarm");
	set_alarm();
	break;
      case (SET_ALARM):
	displaymode = SET_TIME;
	display_str("set time");
	set_time();
	timeunknown = 0;
	break;
      case (SET_TIME):
	displaymode = SET_DATE;
	display_str("set date");
	set_date();
	break;
      case (SET_DATE):
	displaymode = SET_BRIGHTNESS;
	display_str("set brit");
	set_brightness();
	break;
      case (SET_BRIGHTNESS):
	displaymode = SET_DIMMER;
	display_str("set dimr");
	set_dimmer();
	break;
      case (SET_DIMMER):
	displaymode = SET_VOLUME;
	display_str("set vol ");
	set_volume();
	break;
      case (SET_VOLUME):
	displaymode = SET_REGION;
	display_str("set regn");
	set_region();
	break;
	/*
      case (SET_REGION):
	displaymode = SET_SNOOZE;
	display_str("set snoz");
	set_snooze();
	break;
	*/
      default:
	displaymode = SHOW_TIME;
      }
    } else if ((just_pressed & 0x2) || (just_pressed & 0x4)) {
      just_pressed = 0;
      displaymode = NONE;
      display_date(DAY);

      kickthedog();
      delayms(1500);
      kickthedog();

      displaymode = SHOW_TIME;     
    } 
  }
}
예제 #5
0
//show time and date and use a random jumble of letters transition each time the time changes.
void jumble() {

	char days[7][4] = {
		"SUN","MON","TUE", "WED", "THU", "FRI", "SAT"                  }; //DS1307 outputs 1-7
	char allchars[37] = {
		"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"                  };
	char endchar[16];
	byte counter[16];
	byte mins = Time.minute();
	byte seq[16];

	DEBUGpln("in Jumble");
	cls();

	for (int show = 0; show < SHOWCLOCK ; show++) {
		if (mode_changed == 1)
			return;
			
		if(mode_quick){
			mode_quick = false;
			display_date();

#ifdef FACE_WEATHER
			quickWeather();
#endif
			jumble();
			return;
		}

		if ( show == 0 || mins != Time.minute()  ) {
			//fill an arry with 0-15 and randomize the order so we can plot letters in a jumbled pattern rather than sequentially
			for (int i=0; i<16; i++) {
				seq[i] = i;  // fill the array in order
			}
			//randomise array of numbers
			for (int i=0; i<(16-1); i++) {
				int r = i + (rand() % (16-i)); // Random remaining position.
				int temp = seq[i];
				seq[i] = seq[r];
				seq[r] = temp;
			}

			//reset these for comparison next time
			mins = Time.minute();
			byte hours = Time.hour();
			byte dow   = Time.weekday() - 1; // the DS1307 outputs 1 - 7.
			byte date  = Time.day();

			byte alldone = 0;

			//set counters to 50
			for(byte c=0; c<16 ; c++) {
				counter[c] = 3 + random (0,20);
			}

			//set final characters
			char buffer[3];
			itoa(hours,buffer,10);

			//fix - as otherwise if num has leading zero, e.g. "03" hours, itoa coverts this to chars with space "3 ".
			if (hours < 10) {
				buffer[1] = buffer[0];
				buffer[0] = '0';
			}

			endchar[0] = buffer[0];
			endchar[1] = buffer[1];
			endchar[2] = ':';

			itoa (mins, buffer, 10);
			if (mins < 10) {
				buffer[1] = buffer[0];
				buffer[0] = '0';
			}

			endchar[3] = buffer[0];
			endchar[4] = buffer[1];

			itoa (date, buffer, 10);
			if (date < 10) {
				buffer[1] = buffer[0];
				buffer[0] = '0';
			}

			//then work out date 2 letter suffix - eg st, nd, rd, th etc
			char suffix[4][3]={
				"st", "nd", "rd", "th"                                                      };
			byte s = 3;
			if(date == 1 || date == 21 || date == 31) {
				s = 0;
			}
			else if (date == 2 || date == 22) {
				s = 1;
			}
			else if (date == 3 || date == 23) {
				s = 2;
			}
			//set topline
			endchar[5] = ' ';
			endchar[6] = ' ';
			endchar[7] = ' ';

			//set bottom line
			endchar[8] = days[dow][0];
			endchar[9] = days[dow][1];
			endchar[10] = days[dow][2];
			endchar[11] = ' ';
			endchar[12] = buffer[0];
			endchar[13] = buffer[1];
			endchar[14] = suffix[s][0];
			endchar[15] = suffix[s][1];

			byte x = 0;
			byte y = 0;

			//until all counters are 0
			while (alldone < 16){

				//for each char
				for(byte c=0; c<16 ; c++) {

					if (seq[c] < 8) {
						x = 0;
						y = 0;
					}
					else {
						x = 8;
						y = 8;
					}

					//if counter > 1 then put random char
					if (counter[ seq[c] ] > 1) {
						matrix.fillRect((seq[c]-x)*4,y,3,5,matrix.Color333(0,0,0));
						drawChar((seq[c] - x) *4, y, allchars[random(0,36)],51,matrix.Color444(1,0,0));
						counter[ seq[c] ]--;
						matrix.swapBuffers(true);
					}

					//if counter == 1 then put final char
					if (counter[ seq[c] ] == 1) {
						matrix.fillRect((seq[c]-x)*4,y,3,5,matrix.Color444(0,0,0));
						drawChar((seq[c] - x) *4, y, endchar[seq[c]],51,matrix.Color444(0,0,1));
						counter[seq[c]] = 0;
						alldone++;
						matrix.swapBuffers(true);
					}

					//if counter == 0 then just pause to keep update rate the same
					if (counter[seq[c]] == 0) {
						delay(4);
					}

					if (mode_changed == 1)
					return;
				}
				bgProcess();//Give the background process some lovin'
			}
		}
		delay(50);
	} //showclock
}
static void
update_format_examples (GtkDialog *chooser)
{
        CcFormatChooserPrivate *priv = GET_PRIVATE (chooser);
        gchar *locale;
        GDateTime *dt;
        gchar *s;
        const gchar *fmt;
        GtkPaperSize *paper;

        locale = g_strdup (setlocale (LC_TIME, NULL));
        setlocale (LC_TIME, priv->region);

        dt = g_date_time_new_now_local ();
        display_date (priv->full_date, dt, "%A %e %B %Y");
        display_date (priv->medium_date, dt, "%e %b %Y");
        display_date (priv->short_date, dt, "%x");
        display_date (priv->time, dt, "%X");

        setlocale (LC_TIME, locale);
        g_free (locale);

        locale = g_strdup (setlocale (LC_NUMERIC, NULL));
        setlocale (LC_NUMERIC, priv->region);

        s = g_strdup_printf ("%'.2f", 123456789.00);
        gtk_label_set_text (GTK_LABEL (priv->number), s);
        g_free (s);

        setlocale (LC_NUMERIC, locale);
        g_free (locale);

#if 0
        locale = g_strdup (setlocale (LC_MONETARY, NULL));
        setlocale (LC_MONETARY, priv->region);

        num_info = localeconv ();
        if (num_info != NULL)
                gtk_label_set_text (GTK_LABEL (priv->currency), num_info->currency_symbol);

        setlocale (LC_MONETARY, locale);
        g_free (locale);
#endif

#ifdef LC_MEASUREMENT
        locale = g_strdup (setlocale (LC_MEASUREMENT, NULL));
        setlocale (LC_MEASUREMENT, priv->region);

        fmt = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
        if (fmt && *fmt == 2)
                gtk_label_set_text (GTK_LABEL (priv->measurement), C_("measurement format", "Imperial"));
        else
                gtk_label_set_text (GTK_LABEL (priv->measurement), C_("measurement format", "Metric"));

        setlocale (LC_MEASUREMENT, locale);
        g_free (locale);
#endif

#ifdef LC_PAPER
        locale = g_strdup (setlocale (LC_PAPER, NULL));
        setlocale (LC_PAPER, priv->region);

        paper = gtk_paper_size_new (gtk_paper_size_get_default ());
        gtk_label_set_text (GTK_LABEL (priv->paper), gtk_paper_size_get_display_name (paper));
        gtk_paper_size_free (paper);

        setlocale (LC_PAPER, locale);
        g_free (locale);
#endif
}
예제 #7
0
// *************************************************************************************************
// @fn          display_date
// @brief       Display date in DD.MM format (metric units) or MM.DD (English units).
// @param       line_t line			LINE1, LINE2
//				update_t update		DISPLAY_LINE_UPDATE_FULL, DISPLAY_LINE_UPDATE_PARTIAL
// @return      none
// *************************************************************************************************
void display_date(line_t line, update_t update)
{
#ifdef CONFIG_DAY_OF_WEEK
	const u8 weekDayStr[7][3] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
#endif
	u8 * str;
	
	if (update == DISPLAY_LINE_UPDATE_FULL)
	{
		switch (sDate.view)
		{
			case 0: //WWW.DD
				// Convert day to string
#ifdef CONFIG_DAY_OF_WEEK
				str = _itoa(sDate.day, 2, 1);
				display_chars(switch_seg(line, LCD_SEG_L1_1_0, LCD_SEG_L2_1_0), str, SEG_ON);

				//pfs BEGIN replace year display with day of week
				//pfs algorith from http://klausler.com/new-dayofweek.html
				#define BASE_YEAR 2001 // not a leap year, so no need to add 1
				u8 skew;
				skew = (sDate.year - BASE_YEAR)+(sDate.year - BASE_YEAR)/4; // compute number of leap years since BASE_YEAR
				if ((29 == get_numberOfDays(2, sDate.year)) && (sDate.month < 3))
				  skew--; // if this is a leap year but before February 29
				skew = (skew + sDate.day); // add day of current month
				//add this month's skew value
				switch(sDate.month) {
				  case 5:
					skew += 1;
					break;
				  case 8:
					skew += 2;
					break;
				  case 2:
				  case 3:
				  case 11:
					skew += 3;
					break;
				  case 6:
					skew += 4;
					break;
				  case 9:
				  case 12:
					skew += 5;
					break;
				  case 4:
				  case 7:
					skew += 6;
					break;
				  default:  //January and October
					break;
				}
				skew = skew%7;
				str = (u8 *)weekDayStr[skew];
				display_chars(switch_seg(line, LCD_SEG_L1_3_2, LCD_SEG_L2_4_2), str, SEG_ON);
				display_symbol(switch_seg(line, LCD_SEG_L1_DP1, LCD_SEG_L2_DP), SEG_ON);
				break;
#else
				// skip this view
				sDate.view++;
#endif
			case 1: //MM  DD
				// Convert day to string
				display_symbol(switch_seg(line, LCD_SEG_L1_DP1, LCD_SEG_L2_DP), SEG_ON);
				// display date
#ifndef CONFIG_METRIC_ONLY
				if (!sys.flag.use_metric_units) {
					str = _itoa(sDate.day, 2, 0);
					display_chars(switch_seg(line, LCD_SEG_L1_1_0, LCD_SEG_L2_1_0), str, SEG_ON);

					// Convert month to string
					str = _itoa(sDate.month, 2, 1);
					display_chars(switch_seg(line, LCD_SEG_L1_3_2, LCD_SEG_L2_3_2), str, SEG_ON);
				} else {
#else
				if (1) {
#endif
					str = _itoa(sDate.day, 2, 0);
					display_chars(switch_seg(line, LCD_SEG_L1_3_2, LCD_SEG_L2_3_2), str, SEG_ON);
					
					str = _itoa(sDate.month, 2, 0);
					display_chars(switch_seg(line, LCD_SEG_L1_1_0, LCD_SEG_L2_1_0), str, SEG_ON);
				}
				break;
			case 2: //YYYY
				// Convert year to string
				str = _itoa(sDate.year, 4, 0);
				display_chars(switch_seg(line, LCD_SEG_L1_3_0, LCD_SEG_L2_3_0), str, SEG_ON);
				break;
			default:
				display_time(line, update);
				break;
		}
	}
	else if	(update == DISPLAY_LINE_UPDATE_PARTIAL)
	{
		if ((sDate.view == 3) || (display.flag.update_date))
			display_date(line, DISPLAY_LINE_UPDATE_FULL);
	}
	else if (update == DISPLAY_LINE_CLEAR)
	{
		// Do some display cleanup (or just do nothing if everything is OK)
		// This is NOT ONLY called on switch to next menu item
	}	
}
static void
update_examples_cb (GtkTreeSelection *selection, gpointer user_data)
{
	GtkBuilder *builder = GTK_BUILDER (user_data);
        GtkTreeModel *model;
        GtkTreeIter iter;
        gchar *active_id;
	gchar *locale;
	GDateTime *dt;
	gchar *s;
	struct lconv *num_info;
	const char *fmt;

        if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
                return;
        }
        gtk_tree_model_get (model, &iter, 0, &active_id, -1);

	locale = g_strdup (setlocale (LC_TIME, NULL));
        setlocale (LC_TIME, active_id);

	dt = g_date_time_new_now_local ();

	/* Display dates */
	display_date (GTK_LABEL (gtk_builder_get_object (builder, "full_date_format")), dt, "%A %e %B %Y");
	display_date (GTK_LABEL (gtk_builder_get_object (builder, "full_day_format")), dt, "%e %B %Y");
	display_date (GTK_LABEL (gtk_builder_get_object (builder, "short_day_format")), dt, "%e %b %Y");
	display_date (GTK_LABEL (gtk_builder_get_object (builder, "shortest_day_format")), dt, "%x");

	/* Display times */
	display_date (GTK_LABEL (gtk_builder_get_object (builder, "full_time_format")), dt, "%r %Z");
	display_date (GTK_LABEL (gtk_builder_get_object (builder, "short_time_format")), dt, "%X");

	setlocale (LC_TIME, locale);
	g_free (locale);

	/* Display numbers */
	locale = g_strdup (setlocale (LC_NUMERIC, NULL));
	setlocale (LC_NUMERIC, active_id);

	s = g_strdup_printf ("%'.2f", 123456789.00);
	gtk_label_set_text (GTK_LABEL (gtk_builder_get_object (builder, "numbers_format")), s);
	g_free (s);

	setlocale (LC_NUMERIC, locale);
	g_free (locale);

	/* Display currency */
	locale = g_strdup (setlocale (LC_MONETARY, NULL));
	setlocale (LC_MONETARY, active_id);

	num_info = localeconv ();
	if (num_info != NULL) {
		gtk_label_set_text (GTK_LABEL (gtk_builder_get_object (builder, "currency_format")), num_info->currency_symbol);
	}

	setlocale (LC_MONETARY, locale);
	g_free (locale);

	/* Display measurement */
#ifdef LC_MEASUREMENT
	locale = g_strdup (setlocale (LC_MEASUREMENT, NULL));
	setlocale (LC_MEASUREMENT, active_id);

	fmt = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
	if (fmt && *fmt == 2)
		gtk_label_set_text (GTK_LABEL (gtk_builder_get_object (builder, "measurement_format")), _("Imperial"));
	else
		gtk_label_set_text (GTK_LABEL (gtk_builder_get_object (builder, "measurement_format")), _("Metric"));

	setlocale (LC_MEASUREMENT, locale);
	g_free (locale);
#endif
        g_free (active_id);
}