import processing.core.*; 
import processing.data.*; 
import processing.event.*; 
import processing.opengl.*; 

import oscP5.*; 
import netP5.*; 

import java.util.HashMap; 
import java.util.ArrayList; 
import java.io.File; 
import java.io.BufferedReader; 
import java.io.PrintWriter; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.io.IOException; 

public class LDQR_testFab extends PApplet {

/**
 * oscP5oscArgument by andreas schlegel
 * example shows how to parse incoming osc messages "by hand".
 * it is recommended to take a look at oscP5plug for an alternative way to parse messages.
 * oscP5 website at http://www.sojamo.de/oscP5
 */




OscP5 oscP5;
NetAddress myRemoteLocation;

int hallPage1, hallPage2, hallPage3, hallPage4, hallPage5, hallPage6;

PFont f;

public void setup() {
  
  frameRate(25);
  /* start oscP5, listening for incoming messages at port 12000 */
  oscP5 = new OscP5(this, 12000);
  /* send an OSC message to this sketch */
  hallPage1 = 3;
  hallPage2 = 3;
  hallPage3 = 3;
  hallPage4 = 3;
  hallPage5 = 3;
  hallPage6 = 3;
  
  f = createFont("SourceCodePro-Regular.ttf", 12);
  textFont(f);
}

public void draw() {
  //println(hallPage2);
  background(0);
  stroke(255);
  fill(fillHall(hallPage1));
  rect(20, 20, 10, 10);
  fill(fillHall(hallPage2));
  rect(40, 20, 10, 10);
  fill(fillHall(hallPage3));
  rect(60, 20, 10, 10);
  fill(fillHall(hallPage4));
  rect(80, 20, 10, 10);
  fill(fillHall(hallPage5));
  rect(100, 20, 10, 10);
  fill(fillHall(hallPage6));
  rect(120, 20, 10, 10);
  fill(255);
  text("Capteurs effet hall", 140, 30);
}

public int fillHall(int hallState){
  int theColor = 0;
  switch (hallState)
  {
    case 0:
      theColor = 255;
      break;
    
    case 1:
      theColor = 125;
      break;
    
    default:
      theColor = 0;
      break;
  }
  return theColor;
}


public void oscEvent(OscMessage theOscMessage) {
  println(theOscMessage);
  if (theOscMessage.checkAddrPattern("/page1")==true) {
    hallPage1 = theOscMessage.get(0).intValue();  // get the first osc argument
    return;
  } else if (theOscMessage.checkAddrPattern("/page2")==true) {
    hallPage2 = theOscMessage.get(0).intValue();  // get the first osc argument
    return;
  } else if (theOscMessage.checkAddrPattern("/page3")==true) {
    hallPage3 = theOscMessage.get(0).intValue();  // get the first osc argument
    return;
  } else if (theOscMessage.checkAddrPattern("/page4")==true) {
    hallPage4 = theOscMessage.get(0).intValue();  // get the first osc argument
    return;
  } else if (theOscMessage.checkAddrPattern("/page5")==true) {
    hallPage5 = theOscMessage.get(0).intValue();  // get the first osc argument
    return;
  } else if (theOscMessage.checkAddrPattern("/page6")==true) {
    hallPage6 = theOscMessage.get(0).intValue();  // get the first osc argument
    return;
  }
}
  public void settings() {  size(400, 400); }
  static public void main(String[] passedArgs) {
    String[] appletArgs = new String[] { "LDQR_testFab" };
    if (passedArgs != null) {
      PApplet.main(concat(appletArgs, passedArgs));
    } else {
      PApplet.main(appletArgs);
    }
  }
}
