Ejemplo n.º 1
0
  /**
   * This method can be run from a global menu context, using the global Keyboard and Display
   * objects.
   */
  public void run() {
    running = true;
    int hours, minutes, seconds;
    {
      Time time = new Time();
      hours = time.hour;
      minutes = time.minute;
      seconds = time.second;
    }

    Deadline dl = new Deadline(1000);
    synchronized (dl) {
      int count = 0;
      Buzzer b = null;
      do {
        clock.setValue(hours, minutes, seconds);
        try {
          if (alarm && count < 20) {
            if (b == null) b = new Buzzer();
            for (int i = 0; i < 4; i++) {
              b.on((short) 880);
              ThreadExt.sleep(120);
              b.off();
              ThreadExt.sleep(30);
            }
            count++;
          }
        } catch (InterruptedException e) {
          count = 20;
        }
        seconds++;
        if (seconds >= 60) {
          seconds -= 60;
          minutes++;
          if (minutes >= 60) {
            minutes -= 60;
            hours++;
            if (hours >= 24) hours -= 24;
          }
          if (RTC.isAlarm()) abort = true;
        }
        if (!abort)
          try {
            dl.append(1000);
          } catch (DeadlineMissException e) {
          }
      } while (!abort);
    }
    running = false;
  }
Ejemplo n.º 2
0
    public void run() {
      timeRequesterReady = false; // flag to indicate if the thread is running
      for (; !modify; ) {
        Time t = new Time(); // the current time

        // update labels if necessary
        if (years != t.year) {
          years = t.year;
          year.setLabel(String.valueOf(years), false);
        }
        if (months != t.month) {
          months = t.month;
          month.setLabel(
              (months < 10 ? "0" : "").concat(String.valueOf(months)).concat("."), false);
        }
        if (days != t.day) {
          days = t.day;
          day.setLabel((days < 10 ? "0" : "").concat(String.valueOf(days)).concat("."), false);
        }

        // update clock
        clock.setValue(t.hour, t.minute, t.second);
        if (!modify) {
          try {
            ThreadExt.sleep(200);
          } catch (InterruptedException e) {
          }
        }
      }
      timeRequesterReady = true; // thread runs out
    }
Ejemplo n.º 3
0
  public I2CDemo() {
    // create the left Diagram
    add(new Border("Temp.", 0, 0, 40, 64));
    add(new Border("Light", 42, 0, 86, 64));
    Thermometer thermometer = new Thermometer(3, 10, 35, 50, -100, 500);
    thermometer.setCaption("-10", "+50");
    thermometer.setNumericDisplay(3, 1, "°C");
    thermometer.setValue(0);
    add(thermometer);

    AnalogMeter luxmeter =
        new AnalogMeter(57, 5, 50, 50, 0, 1000, 130, AnalogMeter.ORIENTATION_CENTER, 20);
    luxmeter.setCaption("Dark", "Bright");
    luxmeter.setNumericDisplay(5, 0, "");
    luxmeter.setValue(0);
    add(luxmeter);

    add(new Label("lux", 77, 56, Label.ALIGN_CENTER));
    // show the frame
    show();

    // create sensor instances
    LM75 lm75 = new LM75(0x9e);
    TSL2550 tsl2550 = null;
    try {
      tsl2550 = new TSL2550(0x72);
      // tsl2550.setExtendedRange(true);
    } catch (IOException e2) {
      add(new Label("No TSL2550 found!", 45, 25, 80, 10, Label.ALIGN_CENTER));
    }
    for (; ; ) {
      if (lm75 != null) {
        try {
          thermometer.setValue(lm75.getTemp());
        } catch (IOException e1) {
          add(new Label("No LM75 found!", 0, 25, 60, 10, Label.ALIGN_CENTER));
          lm75 = null;
        }
      }
      if (tsl2550 != null) {
        try {
          int lux = tsl2550.getIllumination();
          if (lux > 0) {
            luxmeter.setValue(lux);
          }
        } catch (IOException e) {
        }
      }
      // sleep
      try {
        ThreadExt.sleep(500);
      } catch (InterruptedException e) {
      }
    }
  }
  public LightTemperatureIntro() {
    try {
      RS232 rs232 = new RS232();
      rs232.println("Welcome!");
      rs232.println("Please connect one or both of the");
      rs232.println("sensors that came with your evaluation kit");
      rs232.println("to the evaluation board's I2C connectors");

      TMP75 tmp = null;
      TSL2561 tsl = null;

      intro:
      for (; ; ) {
        if (tmp == null) {
          tmp = new TMP75(0x9e);
        }
        if (tmp != null) {
          try {
            tmp.getTemp();
          } catch (IOException e1) {
            tmp = null;
          }
        }
        if (tsl == null) {
          try {
            tsl = new TSL2561(0x72);
          } catch (IOException e2) {
          }
        }
        if (tsl != null) {
          try {
            tsl.getChannel0();
          } catch (IOException e) {
            tsl = null;
          }
        }

        if (tmp != null || tsl != null) {
          break intro;
        }

        try {
          ThreadExt.sleep(1);
        } catch (InterruptedException e) {
        }
      }
      if (tmp != null) {
        rs232.println("TMP75 detected.");
      }
      if (tsl != null) {
        rs232.println("TSL2651 detected.");
      }
    } catch (IOException e) {
    }
  }
 /** Run method is used for acoustic signals and reboot after 10s */
 public void run() {
   // generate acoustic error signal if property is enabled
   if ("true".equals(Management.getProperty("buzzer.systembeep"))) {
     // we use PWM to bypass the property "buzzer.enable"
     PWM.setFrequency(400);
     PWM.setDuty(Buzzer.BUZZERCHANNEL, 128);
     PWM.setActive(Buzzer.BUZZERCHANNEL, true);
     try {
       ThreadExt.sleep(500);
       PWM.setFrequency(200);
       ThreadExt.sleep(250);
     } catch (InterruptedException e) {
     }
     PWM.setActive(Buzzer.BUZZERCHANNEL, false);
   }
   try {
     // wait for 10 sek.
     ThreadExt.sleep(10000);
     // reboot device
     Management.reboot(true);
   } catch (InterruptedException e) {
   }
 }
Ejemplo n.º 6
0
  /** The time modify page. */
  void modifyMenu() {
    modify = true; // stop the time request thread
    if (timeRequester != null) {
      while (!timeRequesterReady) {
        try {
          ThreadExt.sleep(100);
        } catch (InterruptedException ex) {
        }
      }
      timeRequester = null;
    }
    mainContainer.removeAll(); // remove all components
    graphics.clearRect(0, 0, 128, 64); // clear screen
    day = null; // delete all components for the garbage collector
    month = null;
    year = null;
    clock = null;
    changeButton = null;
    mainContainer.add(new Border("Datum/Uhrzeit stellen", 0, 0, 128, 64)); // border
    okButton = new Button("Ok", 2, 51, 40, 11); // ok button
    okButton.setActionListener(this);
    mainContainer.add(okButton);

    cancelButton = new Button("Abbrechen", 44, 51, 40, 11); // cancel button
    cancelButton.setActionListener(this);
    mainContainer.add(cancelButton);

    // initialize all number choosers with the current time
    Time t = new Time();
    dayChange = new NumberChooser(10, 10, 1, 31); // day
    dayChange.setValue(t.day);
    mainContainer.add(dayChange);
    dayChange.setActionListener(this);

    monthChange = new NumberChooser(40, 10, 1, 12); // month
    monthChange.setValue(t.month);
    mainContainer.add(monthChange);
    monthChange.setActionListener(this);

    yearChange = new NumberChooser(70, 10, 2003, 2099); // year
    yearChange.setValue(t.year);
    mainContainer.add(yearChange);
    yearChange.setActionListener(this);

    hourChange = new NumberChooser(10, 25, 0, 23); // hours
    hourChange.setValue(t.hour);
    mainContainer.add(hourChange);
    hourChange.setActionListener(this);

    minuteChange = new NumberChooser(40, 25, 0, 59); // minutes
    minuteChange.setValue(t.minute);
    mainContainer.add(minuteChange);
    minuteChange.setActionListener(this);

    secondChange = new NumberChooser(70, 25, 0, 59); // seconds
    secondChange.setValue(t.second);
    mainContainer.add(secondChange);
    secondChange.setActionListener(this);

    okButton.requestFocus();
  }
Ejemplo n.º 7
0
  /**
   * Program entry point. Displays the clock an main menu.
   *
   * @param args (not used)
   */
  public static void main(String[] args) {
    // lights on!
    jcontrol.io.Backlight.setBrightness(jcontrol.io.Backlight.MAX_BRIGHTNESS);

    lcd = new Display();
    key = new Keyboard();
    lcd.setFont(null);
    {
      String d = Management.getProperty("system.standbytimer");
      if (d != null) Management.powerOff(Integer.parseInt(d)); // get power off delay
    }
    int select = 0;
    Clock clk;
    for (; ; ) { // main loop
      lcd.clearDisplay();
      if (RTC.isAlarm()) {
        Time wakeup = new Time();
        RTC.getAlarm(wakeup);
        RTC.resetAlarm();
        Date alarmDate = Date.getNextDate(wakeup);
        if (alarmDate != null) {
          lcd.drawString(time2string(alarmDate.time), 0, 45);
          lcd.drawString("$".equals(alarmDate.text) ? "no subject" : alarmDate.text, 0, 56);
          updateAlarm(alarmDate.time);
        }
        clk = new Clock(45, 0, 40, 40, lcd, true); // show the alarm clock
      } else {
        clk = new Clock(35, 2, 60, 80, lcd, false); // show the normal clock
      }
      while (clk.isRunning()) {
        try {
          ThreadExt.sleep(500);
        } catch (InterruptedException e) {
          clk.stop();
        }
        if (key.getKey() != 0) clk.stop();
      }
      if (RTC.isAlarm()) continue; // begin from above...
      key:
      for (; ; ) { // the menu loop
        try {
          lcd.drawImage(new Resource("organizer.jcif"), 0, 0); // draw the background image
        } catch (java.io.IOException e) {
        }
        lcd.setFont(null);
        select =
            MenuSelector.listSelect(
                new String[] { // let the user select one of the specified menu items
                  "display time", "new appointment", "view appointments", "turn off"
                },
                select,
                lcd,
                key);
        Date date = null;
        switch (select) {
          case -1:
          case 0: // show the current time
            select = 0;
            break key;
          case 2: // adjust appointment
            date = listDates(); // show all stored dates and return date to change
            if (date == null) break;
          case 1: // new appointment
            date =
                DateInput.getDate(
                    lcd, key,
                    date); // get a new date (date==null) or modify an existing (date!=null)
            if (date != null) { // if the new date is valid
              try {
                date.store();
              } catch (IOException e) {
              }
              date = null; // this object may be garbage collected now
              updateAlarm(null);
            }
            break;
          case 3: // standby
            lcd.clearDisplay();
            while (key.getKey() != 0) {}
            jcontrol.system.Management.powerOff(-1);
            break;
        }
      }
    }
  }