Skip to content
Snippets Groups Projects
Commit a206a954 authored by Puissegur Alexis's avatar Puissegur Alexis
Browse files

sound

parent e3161e1d
No related branches found
No related tags found
No related merge requests found
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Util;
import java.util.Calendar;
/**
*
* @author timperez
* see https://gist.github.com/timperez/9555657
*/
public class CalendarUtil {
public static boolean isBusinessDay(Calendar cal){
// check if weekend
if(cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY){
return false;
}
// check if New Year's Day
if (cal.get(Calendar.MONTH) == Calendar.JANUARY
&& cal.get(Calendar.DAY_OF_MONTH) == 1) {
return false;
}
// check if Christmas
if (cal.get(Calendar.MONTH) == Calendar.DECEMBER
&& cal.get(Calendar.DAY_OF_MONTH) == 25) {
return false;
}
// check if 4th of July
if (cal.get(Calendar.MONTH) == Calendar.JULY
&& cal.get(Calendar.DAY_OF_MONTH) == 4) {
return false;
}
// check Thanksgiving (4th Thursday of November)
if (cal.get(Calendar.MONTH) == Calendar.NOVEMBER
&& cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) == 4
&& cal.get(Calendar.DAY_OF_WEEK) == Calendar.THURSDAY) {
return false;
}
// check Memorial Day (last Monday of May)
if (cal.get(Calendar.MONTH) == Calendar.MAY
&& cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY
&& cal.get(Calendar.DAY_OF_MONTH) > (31 - 7) ) {
return false;
}
// check Labor Day (1st Monday of September)
if (cal.get(Calendar.MONTH) == Calendar.SEPTEMBER
&& cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) == 1
&& cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
return false;
}
// check President's Day (3rd Monday of February)
if (cal.get(Calendar.MONTH) == Calendar.FEBRUARY
&& cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) == 3
&& cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
return true;
}
// check Veterans Day (November 11)
if (cal.get(Calendar.MONTH) == Calendar.NOVEMBER
&& cal.get(Calendar.DAY_OF_MONTH) == 11) {
return true;
}
// check MLK Day (3rd Monday of January)
if (cal.get(Calendar.MONTH) == Calendar.JANUARY
&& cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) == 3
&& cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
return true;
}
// IF NOTHING ELSE, IT'S A BUSINESS DAY
return true;
}
}
......@@ -9,8 +9,10 @@ import Bluetooth.BluetoothManager;
import Bluetooth.BluetoothThread;
import Interfaces.Observable;
import Interfaces.Observer;
import Util.CalendarUtil;
import java.net.URL;
import java.text.NumberFormat;
import java.util.Calendar;
import java.util.Formatter;
import java.util.Locale;
import java.util.ResourceBundle;
......@@ -140,9 +142,10 @@ public class FXMLVueController implements Initializable, Observer {
humidityPlante.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
if (Integer.parseInt(newValue) < Integer.parseInt(humiditySeuil.getText())) {
if (newValue != null && Integer.parseInt(newValue) < Integer.parseInt(humiditySeuil.getText())) {
changeImagePlante(true);
alert = true;
work();
}
else if(alert){
changeImagePlante(false);
......@@ -203,20 +206,21 @@ public class FXMLVueController implements Initializable, Observer {
public void update(Observable obs) {
if(obs instanceof BluetoothThread){
BluetoothThread t = (BluetoothThread) obs;
String[] values = t.getBuffer().split(";");
String[] values = t.getBuffer().split(";");
Platform.runLater(
() -> {
this.humidityAir.setText(values[0] + " %");
this.intensity.setText(values[1] + " LUX");
this.temperature.setText(values[2] + " °C");
this.humidityPlante.setText(values[3] + " %");
this.humidityAir.setText(values[0].replaceFirst("^0+(?!$)", ""));
this.intensity.setText(values[1].replaceFirst("^0+(?!$)", ""));
this.temperature.setText(values[2].replaceFirst("^0+(?!$)", ""));
this.humidityPlante.setText(values[3].replaceFirst("^0+(?!$)", ""));
}
);
}
}
/**
* Update the vue with the right image of the plant
* Update the view with the right image of the plant
* @param alertM
*/
public void changeImagePlante(boolean alertM){
......@@ -266,5 +270,21 @@ public class FXMLVueController implements Initializable, Observer {
currentButton.setStyle("-fx-background-color: #7fca5eff");
}
private void work(){
if(CalendarUtil.isBusinessDay(Calendar.getInstance())){
System.out.println("is business");
// compute & send
computeGravity();
} else {
System.out.println("is not");
// send mail
}
}
public void computeGravity(){
int humidity = Integer.parseInt(humidityPlante.getText().replaceFirst("^0+(?!$)", ""));
int seuil = Integer.parseInt(seuil.getText().replaceFirst("^0+(?!$)", ""));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment