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...")
 
(Blanked the page)
Tag: Blanking
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
<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 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_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");
 
    }
 
}
 
 
</nowiki>
 
 
[[Pseudo-Medical_Monitor_Code#Custom_Includes]]
 

Latest revision as of 16:49, 14 December 2021