Difference between revisions of "Pseudo-Medical Monitor Code HNDHLD STUFF"

From LVL1
Jump to navigation Jump to search
(Created page with " <nowiki> class HandHeld_Class { private: int Unit_ID; int Port_ID; int Port_Type; int mpu_address; int mpu_int_pin; int vibration_pin; int button_pin; int g...")
 
Line 155: Line 155:
 
}
 
}
  
 +
void HH_Display_Data(int unit_index, int panel_number)
 +
{
 +
 +
  Serial.println("X");
 +
 
 +
  DrawScreenBlock(box_left,box_top,box_width-3,box_height-3,COMMON_ORANGE);
 +
 
 +
  sensors_event_t a, g, temp;
 +
  HandHeld_Unit[unit_index].mpu.getEvent(&a, &g, &temp);
 +
 +
  DrawScreenText(box_left,box_top,"Unit: "+String(HandHeld_Unit[unit_index].GetUnitID()),COMMON_BLACK,COMMON_ORANGE);
 +
 +
  DrawScreenText(box_left,box_top+(text_height*1),"Button: "+String(HandHeld_Unit[unit_index].GetButtonValue()),COMMON_BLACK,COMMON_ORANGE);
 +
 +
  DrawScreenText(box_left,box_top+(text_height*2),"Grip:  "+String(HandHeld_Unit[unit_index].GetGripValue()),COMMON_BLACK,COMMON_ORANGE);
 +
 
 +
  DrawScreenText(box_left,box_top+(text_height*3),"AX:  "+String(a.acceleration.x),COMMON_BLACK,COMMON_ORANGE);
 +
  DrawScreenText(box_left,box_top+(text_height*4),"AY:  "+String(a.acceleration.y),COMMON_BLACK,COMMON_ORANGE);
 +
  DrawScreenText(box_left,box_top+(text_height*5),"AZ:  "+String(a.acceleration.z),COMMON_BLACK,COMMON_ORANGE);
 +
 
 +
  DrawScreenText(box_left,box_top+(text_height*6),"GX:  "+String(g.gyro.x),COMMON_BLACK,COMMON_ORANGE);
 +
  DrawScreenText(box_left,box_top+(text_height*7),"GY:  "+String(g.gyro.y),COMMON_BLACK,COMMON_ORANGE);
 +
  DrawScreenText(box_left,box_top+(text_height*8),"GZ:  "+String(g.gyro.z),COMMON_BLACK,COMMON_ORANGE);
 +
 
 +
}
  
 
void HH_Display_Status()
 
void HH_Display_Status()

Revision as of 19:40, 11 December 2021


class HandHeld_Class
{
private:

  int Unit_ID;
  int Port_ID;
  int Port_Type;
  int mpu_address;
  int mpu_int_pin;
  int vibration_pin;
  int button_pin;
  int grip_pin;
    
  void SetUnitID(int id_value)
    {
      Unit_ID = id_value;
    }

  void SetPortID(int port_number)
  {
    Port_ID = port_number;
    Port_Type = Port_Definitions.Port_Type[Port_ID];
    ConfigurePins();
    SetupPins();
  }

  void SetMPUAddress(int address_value)
    {
      mpu_address = address_value;
    }
 
  bool InitializeMPU()
  {
    if (!mpu.begin(mpu_address,&Wire1, Unit_ID)) 
      {
       return(false);
      }
    Serial.println("MPU6050 Found!");
    mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
    Serial.print("Accelerometer range set to: ");
    Serial.println("+-8G");
    mpu.setGyroRange(MPU6050_RANGE_500_DEG);
    Serial.print("Gyro range set to: ");
    Serial.println("+- 500 deg/s");
    mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
    Serial.print("Filter bandwidth set to: ");
    Serial.println("21 Hz");    
    
    return(true);
  }

  void SetupPins()
  {
    pinMode(mpu_int_pin,INPUT);
    pinMode(vibration_pin,OUTPUT);
    digitalWrite(vibration_pin,LOW);
    pinMode(button_pin,INPUT_PULLUP);
  }
  
  void ConfigurePins()
  {
    mpu_int_pin = Port_Definitions.Port_Line_2[Port_ID];
    vibration_pin = Port_Definitions.Port_Line_3[Port_ID];
    button_pin = Port_Definitions.Port_Line_4[Port_ID];
    grip_pin = Port_Definitions.Port_Line_5[Port_ID];    
  }
  
public:

  Adafruit_MPU6050 mpu;  

  int GetGripValue()
  {    
    return(analogRead(grip_pin));
  }
  
  bool GetButtonValue()
  {
    return(!digitalRead(button_pin));  
  }

  void VibrateUnit(int duration)
  {
    digitalWrite(vibration_pin,HIGH);
    delay(duration);
    digitalWrite(vibration_pin,LOW);    
  }

  int GetPort_Type()
  {
    return(Port_Type);  
  }
  
  int GetUnitID()
    {
      return(Unit_ID);
    }

  int GetPortID()
  {
    return(Port_ID);
  }

  int GetMPUAddress()
    {
      return(mpu_address);
    }

  bool InitializeUnit(int unit_id, int port_id, int mpu_address)
    {
      if (port_id > NUMBER_OF_PORTS)
        return(false); 
      if ((Port_Definitions.Port_Type[port_id] != I2C_MIX) && (Port_Definitions.Port_Type[port_id] != I2C_ANALOG))
        return(false);
        
      SetUnitID(unit_id);
      SetPortID(port_id);
      SetMPUAddress(mpu_address);     
      if (InitializeMPU())
        return(true);
       else
        return(false); 
    }
    
};

HandHeld_Class HandHeld_Unit[4];

int HH_DATA[4][EXG_SAMPLE_SIZE];
int HH_DATA_EXTREME[4][2];

int HH_x_offset = 0;
int HH_y_offset = 0;
int HH_x_width = 128;
int HH_y_height = 160;

void HH_Frame()
{    
  int box_top = HH_y_offset;
  int box_bottom = box_top + HH_y_height - 1; 
  int box_left = HH_x_offset;
  int box_right = box_left + HH_x_width - 1;  
  int box_width = HH_x_width;
  int box_height = HH_y_height;

  DrawScreenRotation(0);  
  DrawScreenCompartment(box_left,box_top,box_width,box_height,COMMON_ORANGE,COMMON_BLACK);
  DrawScreenLine(box_left,box_top + (box_height/2)    , box_right,box_top + (box_height/2)   , COMMON_BLACK );
  DrawScreenLine(box_left,box_top + (box_height/2) + 1, box_right,box_top + (box_height/2) + 1, COMMON_BLACK );
  
  DrawScreenLine(box_left + (box_width/2)    , box_top, box_left + (box_width/2)    , box_bottom, COMMON_BLACK);
  DrawScreenLine(box_left + (box_width/2) + 1, box_top, box_left + (box_width/2) + 1, box_bottom, COMMON_BLACK);
}

void HH_Display_Data(int unit_index, int panel_number)
{

  Serial.println("X");
  
  DrawScreenBlock(box_left,box_top,box_width-3,box_height-3,COMMON_ORANGE);
  
  sensors_event_t a, g, temp;
  HandHeld_Unit[unit_index].mpu.getEvent(&a, &g, &temp);

  DrawScreenText(box_left,box_top,"Unit: "+String(HandHeld_Unit[unit_index].GetUnitID()),COMMON_BLACK,COMMON_ORANGE);

  DrawScreenText(box_left,box_top+(text_height*1),"Button: "+String(HandHeld_Unit[unit_index].GetButtonValue()),COMMON_BLACK,COMMON_ORANGE);

  DrawScreenText(box_left,box_top+(text_height*2),"Grip:  "+String(HandHeld_Unit[unit_index].GetGripValue()),COMMON_BLACK,COMMON_ORANGE);
  
  DrawScreenText(box_left,box_top+(text_height*3),"AX:  "+String(a.acceleration.x),COMMON_BLACK,COMMON_ORANGE);
  DrawScreenText(box_left,box_top+(text_height*4),"AY:  "+String(a.acceleration.y),COMMON_BLACK,COMMON_ORANGE);
  DrawScreenText(box_left,box_top+(text_height*5),"AZ:  "+String(a.acceleration.z),COMMON_BLACK,COMMON_ORANGE);
  
  DrawScreenText(box_left,box_top+(text_height*6),"GX:  "+String(g.gyro.x),COMMON_BLACK,COMMON_ORANGE);
  DrawScreenText(box_left,box_top+(text_height*7),"GY:  "+String(g.gyro.y),COMMON_BLACK,COMMON_ORANGE);
  DrawScreenText(box_left,box_top+(text_height*8),"GZ:  "+String(g.gyro.z),COMMON_BLACK,COMMON_ORANGE);
  
}

void HH_Display_Status()
{
  HH_Frame();
  HandHeld_Unit[0].InitializeUnit(0,0,0x68);
  delay(100);
  HandHeld_Unit[1].InitializeUnit(1,1,0x69);
  delay(100);
  while(1)
    {
      HH_Display_Data(0,0);
      delay(500);
      HH_Display_Data(1,3);
      delay(500);
      Serial.println("Z");
    }
}

 

Pseudo-Medical_Monitor_Code#Custom_Includes