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

From LVL1
Jump to navigation Jump to search
(Blanked the page)
Tag: Blanking
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
<nowiki>
 
  
char * I2C_Device_Name(int I2C_Bus, byte I2C_Address)
 
{
 
  switch(I2C_Address)
 
    {
 
      case 0x26:
 
        if (I2C_Bus == 0)
 
          return("????");         
 
        if (I2C_Bus == 1)
 
          return("ECG w/ NPXL");     
 
        break;
 
      case 0x29:
 
        return("VL53L0X");
 
        break;
 
      case 0x57:
 
        return("MAX30102");
 
        break;
 
      case 0x5A:
 
        return("MLX9164");
 
        break;
 
      case 0x68:
 
        if (I2C_Bus == 0)
 
          return("????");
 
        if (I2C_Bus  1)
 
          return("MPU6050 R");
 
        break;
 
      case 0x69:
 
        if (I2C_Bus == 0)
 
          return("AMG8833");
 
        if (I2C_Bus == 1)
 
          return("MPU6050 G");         
 
        break;
 
      case 0x70:
 
        return("TCA9548A"); 
 
      case 0x38:
 
        return("PCF8574");
 
        break; 
 
      default:
 
        return("????");
 
        break;         
 
    }
 
}
 
 
int CNFG_x_offset = 0;
 
int CNFG_y_offset = 0;
 
int CNFG_x_width = 128;
 
int CNFG_y_height = 160;
 
 
void ConfigurationMainUnit()
 
{
 
  byte comm_error, address;
 
  int nDevices;
 
 
  int box_top = CNFG_y_offset;
 
  int box_bottom = box_top + CNFG_y_height;
 
 
 
  int box_left = CNFG_x_offset;
 
  int box_right = box_left + CNFG_x_width;
 
 
 
  int box_width = CNFG_x_width;
 
  int box_height = CNFG_y_height;
 
 
  int I2C_text_y_offset = 20;
 
  int text_x_offset = 5;
 
  int text_y_offset = 10;
 
  int text_y_spacing = 8;
 
 
  char I2CLabel[16]="--------------";
 
 
 
  DrawScreenCompartment(box_left,box_top,box_width,box_height,COMMON_BLUE,COMMON_WHITE);
 
  DrawScreenText(box_left+20,box_top+4,"Main Unit",COMMON_YELLOW,COMMON_BLUE);
 
 
  DrawScreenText(box_left+10,I2C_text_y_offset,"I2C Scan...",COMMON_YELLOW,COMMON_BLUE);
 
  DrawScreenText(box_left+10,box_top+I2C_text_y_offset+8,"HEX",COMMON_YELLOW,COMMON_BLUE);
 
  DrawScreenText(box_left+40,box_top+I2C_text_y_offset+8,"Device",COMMON_YELLOW,COMMON_BLUE);
 
 
 
  Serial.println("Scanning...");
 
 
 
  nDevices = 0;
 
  for(address = 1; address < 127; address++ )
 
    {
 
      Wire.beginTransmission(address);
 
      comm_error = Wire.endTransmission();
 
      if (comm_error == 0)
 
        {         
 
          nDevices++;
 
          Serial.print("I2C device found at address 0x");
 
          if (address<16)
 
            {
 
              Serial.print("0");
 
            }
 
          DrawScreenText(box_left+10,box_top+I2C_text_y_offset+16+(nDevices*8),String(address,HEX),COMMON_YELLOW,COMMON_BLUE);           
 
          Serial.println(address,HEX);
 
          DrawScreenText(box_left+40,box_top+I2C_text_y_offset+16+(nDevices*8),I2C_Device_Name(0, address),COMMON_YELLOW,COMMON_BLUE);                     
 
        }
 
      else
 
        if (comm_error  == 4)
 
          {
 
            Serial.print("Unknown error at address 0x");
 
            if (address<16)
 
              {
 
                Serial.print("0");
 
              }
 
            Serial.println(address,HEX);
 
          }   
 
    }
 
  if (nDevices == 0)
 
    {
 
      Serial.println("No I2C devices found!\n");
 
    }
 
  else
 
    {
 
      Serial.println("done\n");
 
    }   
 
}
 
 
void ConfigurationPort(int port_selection)
 
{
 
  byte comm_error, address;
 
  int nDevices;
 
 
  int box_top = CNFG_y_offset;
 
  int box_bottom = box_top + CNFG_y_height;
 
 
 
  int box_left = CNFG_x_offset;
 
  int box_right = box_left + CNFG_x_width;
 
 
 
  int box_width = CNFG_x_width;
 
  int box_height = CNFG_y_height;
 
 
  int I2C_text_y_offset = 28;
 
  int text_x_offset = 5;
 
  int text_y_offset = 10;
 
  int text_y_spacing = 8;
 
 
  char I2CLabel[16]="--------------";
 
 
 
  DrawScreenCompartment(box_left,box_top,box_width,box_height,COMMON_CYAN,COMMON_RED);
 
  DrawScreenText(box_left+20,box_top+4,"Port "+String(port_selection),COMMON_BLACK,COMMON_CYAN);
 
  DrawScreenText(box_left+20,box_top+12,Port_Type_Label[Port_Definitions.Port_Type[port_selection]],COMMON_BLACK,COMMON_CYAN);
 
  DrawScreenText(box_left+10,box_top+I2C_text_y_offset,"I2C Scan...",COMMON_BLACK,COMMON_CYAN);
 
  DrawScreenText(box_left+10,box_top+I2C_text_y_offset+8,"HEX",COMMON_BLACK,COMMON_CYAN);
 
  DrawScreenText(box_left+40,box_top+I2C_text_y_offset+8,"Device",COMMON_BLACK,COMMON_CYAN);
 
 
 
  Serial.println("Scanning...");
 
 
 
  nDevices = 0;
 
  I2CMux.openChannel(port_selection);
 
  for(address = 1; address < 127; address++ )
 
    {
 
      Wire1.beginTransmission(address);
 
      comm_error = Wire1.endTransmission();
 
      if (comm_error == 0)
 
        {         
 
          nDevices++;
 
          Serial.print("I2C device found at address 0x");
 
          if (address<16)
 
            {
 
              Serial.print("0");
 
            }
 
          DrawScreenText(box_left+10,box_top+I2C_text_y_offset+16+(nDevices*8),String(address,HEX),COMMON_BLACK,COMMON_CYAN);           
 
          Serial.println(address,HEX);
 
          DrawScreenText(box_left+40,box_top+I2C_text_y_offset+16+(nDevices*8),I2C_Device_Name(1, address),COMMON_BLACK,COMMON_CYAN);
 
        }
 
      else
 
        if (comm_error==4)
 
          {
 
            Serial.print("Unknown error at address 0x");
 
            if (address<16)
 
              {
 
                Serial.print("0");
 
              }
 
            Serial.println(address,HEX);
 
          }   
 
    }
 
  if (nDevices == 0)
 
    {
 
      Serial.println("No I2C devices found!\n");
 
    }
 
  else
 
    {
 
      Serial.println("done\n");
 
    }   
 
  I2CMux.closeChannel(port_selection); 
 
}
 
 
void ConfigurationScans()
 
{
 
  int configuration_select = 0;
 
  bool refresh_screen = true;
 
  int encoder_A = 0;
 
  int encoder_B = 0;
 
 
 
  while(configuration_select != -1)
 
    {
 
      switch(configuration_select)
 
        {
 
          case 0:
 
            if (refresh_screen)
 
              {
 
                ConfigurationMainUnit();
 
                Controls.reset_All();   
 
              }
 
            refresh_screen = false; 
 
            break;
 
          case 1:
 
            if (refresh_screen)
 
              ConfigurationPort(0);
 
            refresh_screen = false; 
 
            break; 
 
          case 2:
 
            if (refresh_screen)
 
              ConfigurationPort(1);
 
            refresh_screen = false; 
 
            break; 
 
          case 3:
 
            if (refresh_screen)
 
              ConfigurationPort(2);
 
            refresh_screen = false; 
 
            break; 
 
          case 4:
 
            if (refresh_screen)
 
              ConfigurationPort(3);
 
            refresh_screen = false; 
 
            break;             
 
        }
 
 
      if (Controls.pcf_event)
 
        { 
 
          encoder_A = Controls.encoder_A_Dir();
 
          encoder_B = Controls.encoder_B_Dir();
 
          if (encoder_B == 1)
 
            {
 
              if (configuration_select < 4)
 
                ++configuration_select;
 
              refresh_screen = true;                         
 
            }
 
          if (encoder_B == -1)
 
            {
 
              if (configuration_select > 0)
 
                --configuration_select;         
 
              refresh_screen = true;               
 
            }       
 
          if (Controls.encoder_A_Switch() = = 1)
 
            {
 
              configuration_select = -1;             
 
            }
 
          Controls.pcf_event = false; // Cleans the interrupt status             
 
          delay(20); 
 
        }
 
    }
 
}
 
 
 
 
 
 
 
 
 
 
</nowiki>
 
 
[[Pseudo-Medical_Monitor_Code#Custom_Includes]]
 

Latest revision as of 16:48, 14 December 2021