<commit_before>#include <SoftwareSerial.h>
#include <Thread.h>
#define PPR_ON "a"
#define PPR_OFF "b"
#define FSR_ON "c"
#define FSR_OFF "d"
#define TMP_ON "e"
#define TMP_OFF "f"

Thread fsrThread = Thread(); // For measuring Pressure data in other thread

//  Mosfet
int MOSFET_C1 = 6;
int MOSFET_C2 = 7;

//  UNO board
int INB = 8;
int INA = 9;
//  Analog read  
int PRESSURE = A0; 
int TEMPERATURE = A1;

bool isTMPOn = false;

int MAX_TMP;

SoftwareSerial BTSerial(2, 3); // (RX, TX)

void setup() {
  BTSerial.begin(9600); 
  Serial.begin(9600);   
  pinMode(INA,OUTPUT); 
  pinMode(INB,OUTPUT); 
  pinMode(MOSFET_C1, OUTPUT);
  pinMode(MOSFET_C2, OUTPUT);
  fsrThread.onRun(readPressure);
  fsrThread.enabled = false;
  fsrThread.setInterval(1000);
}

void loop() {

  // char to String data received from Android
  String response = "";
  while(BTSerial.available()){
    char tempChar = BTSerial.read();
    if(tempChar != '\n')
    response.concat(tempChar);
  }
  if(response.length()>1){
    String resInt = response.substring(1);
    response = response.substring(0,1);
    MAX_TMP = resInt.toInt();
  }
  
  if(response.equals(PPR_ON)){
    Serial.println(response);
    digitalWrite(INA,HIGH);
    digitalWrite(INB,LOW);
  }else if(response.equals(PPR_OFF)){
    Serial.println(response);
    digitalWrite(INA,LOW);
    digitalWrite(INB,LOW);
  }else if(response.equals(FSR_ON)){
    Serial.println(response);
    fsrThread.enabled = true;
  }else if(response.equals(FSR_OFF)){
    Serial.println(response);
    fsrThread.enabled = false;
  }else if(response.equals(TMP_ON)){
    Serial.println(response);
    isTMPOn = true;
  }else if(response.equals(TMP_OFF)){
    Serial.println(response);
    MAX_TMP = 0;
    isTMPOn = false;
  }
  
  if(isTMPOn){
    readTmp();
  }
  
  if(fsrThread.shouldRun())
    fsrThread.run();
}

// Runnable for fsrThread
void readPressure(){
  int fsrData = analogRead(PRESSURE);
  Serial.println("Pressure : "+ String(fsrData));
  BTSerial.println(fsrData);
}

void readTmp(){
  float analogTmp = (float)analogRead(TEMPERATURE)*5/1024;
  float currTmp = 100*(analogTmp-0.5);
  if(currTmp < MAX_TMP){
    digitalWrite(MOSFET_C1,HIGH);
    digitalWrite(MOSFET_C2,HIGH);
  }else{
    digitalWrite(MOSFET_C1,LOW);
    digitalWrite(MOSFET_C2,LOW);
  }
}<commit_msg>refactor temperature part (arduino)<commit_after>#include <SoftwareSerial.h>
#include <Thread.h>
#define PPR_ON "a"
#define PPR_OFF "b"
#define FSR_ON "c"
#define FSR_OFF "d"
#define TMP_ON "e"
#define TMP_OFF "f"

Thread fsrThread = Thread(); // For measuring Pressure data in other thread

//  Mosfet channel
int MOSFET_C1 = 10;
int MOSFET_C2 = 7;
//  UNO board
int INB = 8;
int INA = 9;
//  Analog read  
int PRESSURE_0 = A0; 
int PRESSURE_1 = A1; 
int PRESSURE_2 = A2; 
int PRESSURE_3 = A3; 

bool isTMPOn = false;

int MAX_TMP;

SoftwareSerial BTSerial(2, 3); // (RX, TX)

void setup() {
  BTSerial.begin(9600); 
  Serial.begin(9600);   
  pinMode(INA,OUTPUT); 
  pinMode(INB,OUTPUT); 
  pinMode(MOSFET_C1, OUTPUT);
  pinMode(MOSFET_C2, OUTPUT);
  digitalWrite(MOSFET_C1,LOW);
  fsrThread.onRun(readPressure);
  fsrThread.enabled = false;
  fsrThread.setInterval(1000);
}

void loop() {

  // char to String data received from Android
  String response = "";
  while(BTSerial.available()){
    char tempChar = BTSerial.read();
    if(tempChar == '\n'){
      break;
    }
    response.concat(tempChar);
  }
  if(response.length()>1){
    String resInt = response.substring(1);
    response = response.substring(0,1);
    MAX_TMP = resInt.toInt();
  }
  if(response.equals(PPR_ON)){
    Serial.println(response);
    digitalWrite(INA,HIGH);
    digitalWrite(INB,LOW);
  }else if(response.equals(PPR_OFF)){
    Serial.println(response);
    digitalWrite(INA,LOW);
    digitalWrite(INB,LOW);
  }else if(response.equals(FSR_ON)){
    Serial.println(response);
    fsrThread.enabled = true;
  }else if(response.equals(FSR_OFF)){
    Serial.println(response);
    fsrThread.enabled = false;
  }else if(response.equals(TMP_ON)){
    Serial.println(response);
    isTMPOn = true;
  }else if(response.equals(TMP_OFF)){
    Serial.println(response);
    MAX_TMP = 0;
    digitalWrite(MOSFET_C1,LOW);
    isTMPOn = false;
  }
  
  if(isTMPOn && MAX_TMP >0){
    readTmp();
  }
  
  if(fsrThread.shouldRun())
    fsrThread.run();
}

// Runnable for fsrThread
void readPressure(){
  int frontRight = analogRead(PRESSURE_0)*5;
  int frontLeft = analogRead(PRESSURE_1)*5;
  int backRight = analogRead(PRESSURE_2)*5;
  int backLeft = analogRead(PRESSURE_3)*5;
  Serial.println("0 : "+ String(frontRight));
  Serial.println("1 : "+ String(frontLeft));
  Serial.println("2 : "+ String(backRight));
  Serial.println("3 : "+ String(backLeft));

  if(frontRight>2000){
    BTSerial.println("right leg side");
  }
}

void readTmp(){
    digitalWrite(MOSFET_C1,HIGH);
    Serial.println(String(MAX_TMP));  
}
{'fraction_non_alphanumeric': 0.14676464584609103, 'fraction_numerical': 0.02020820575627679, 'mean_word_length': 3.9796747967479673, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3130118', 'n_tokens_mistral': 1929, 'n_tokens_neox': 1873, 'n_words': 354}