|
|
| Line 1: |
Line 1: |
| <nowiki>
| |
|
| |
|
| #define EXG_SAMPLE_SIZE 154
| |
|
| |
| class EXG_Class
| |
| {
| |
| private:
| |
| int number_of_analog_lines;
| |
| int Unit_ID;
| |
| int Port_ID;
| |
| int Port_Type;
| |
| int NeoPixel_Address;
| |
|
| |
| 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();
| |
| }
| |
|
| |
| bool SetNeoPixelAddress(int i2c_address)
| |
| {
| |
| NeoPixel_Address = i2c_address;
| |
| Signal.NEO_AddressSet(i2c_address);
| |
| }
| |
|
| |
| void SetupPins()
| |
| {
| |
| if (Port_Definitions.Port_Type[Port_Type] == I2C_MIX)
| |
| {
| |
| pinMode(Port_Definitions.Port_Line_2[Port_ID],INPUT);
| |
| pinMode(Port_Definitions.Port_Line_3[Port_ID],INPUT);
| |
| pinMode(Port_Definitions.Port_Line_4[Port_ID],INPUT);
| |
| }
| |
| }
| |
|
| |
| void ConfigurePins()
| |
| {
| |
| if (Port_Definitions.Port_Type[Port_Type] == I2C_MIX)
| |
| {
| |
| number_of_analog_lines = 1;
| |
| Analog_Line[0] = Port_Definitions.Port_Line_5[Port_ID];
| |
| }
| |
| if (Port_Definitions.Port_Type[Port_Type] == I2C_ANALOG)
| |
| {
| |
| number_of_analog_lines = 4;
| |
| Analog_Line[0] = Port_Definitions.Port_Line_2[Port_ID];
| |
| Analog_Line[1] = Port_Definitions.Port_Line_3[Port_ID];
| |
| Analog_Line[2] = Port_Definitions.Port_Line_4[Port_ID];
| |
| Analog_Line[3] = Port_Definitions.Port_Line_5[Port_ID];
| |
| }
| |
| }
| |
|
| |
| public:
| |
| int Analog_Line[4];
| |
| NeoPixel_Class Signal;
| |
|
| |
| int GetPort_Type()
| |
| {
| |
| return(Port_Type);
| |
| }
| |
|
| |
| int GetUnitID()
| |
| {
| |
| return(Unit_ID);
| |
| }
| |
|
| |
| int GetPortID()
| |
| {
| |
| return(Port_ID);
| |
| }
| |
|
| |
| int GetNumberAnalogLines()
| |
| {
| |
| return(number_of_analog_lines);
| |
| }
| |
|
| |
| bool InitializeUnit(int unit_id, int port_id, int neopixel_address)
| |
| {
| |
| SetUnitID(unit_id);
| |
| SetPortID(port_id);
| |
| SetNeoPixelAddress(neopixel_address);
| |
| return(Signal.NEO_Initialize(neopixel_address));
| |
| }
| |
|
| |
| int AnalogLineRead(int line_number)
| |
| {
| |
| if (line_number < number_of_analog_lines)
| |
| return(analogRead(Analog_Line[line_number]));
| |
| else
| |
| return(-1);
| |
| }
| |
|
| |
| };
| |
|
| |
| EXG_Class EXG_Unit[4];
| |
|
| |
| int EXG_DATA[4][EXG_SAMPLE_SIZE];
| |
| int EXG_DATA_EXTREME[4][2];
| |
|
| |
| int EXG_x_offset = 0;
| |
| int EXG_y_offset = 0;
| |
| int EXG_x_width = 160;
| |
| int EXG_y_height = 128;
| |
|
| |
| void EXG_Frame()
| |
| {
| |
| int box_top = EXG_y_offset;
| |
| int box_bottom = box_top + EXG_y_height;
| |
| int box_left = EXG_x_offset;
| |
| int box_right = box_left + EXG_x_width;
| |
| int box_width = EXG_x_width;
| |
| int box_height = EXG_y_height;
| |
|
| |
| DrawScreenRotation(1);
| |
|
| |
| DrawScreenCompartment(box_left,box_top,box_width,box_height,COMMON_WHITE,COMMON_BLUE);
| |
| }
| |
|
| |
|
| |
| void EXG_Display_Data(EXG_Class EXG_Unit, int delay_time)
| |
| {
| |
| int box_top = EXG_y_offset;
| |
| int box_left = EXG_x_offset;
| |
| int box_width = EXG_x_width;
| |
| int box_height = EXG_y_height;
| |
| int x,y;
| |
|
| |
| uint32_t LineColor[] = {COMMON_RED, COMMON_GREEN, COMMON_BLACK, COMMON_BLUE};
| |
| int data_point1,data_point2;
| |
| int number_of_lines;
| |
|
| |
| number_of_lines = EXG_Unit.GetNumberAnalogLines();
| |
| DrawScreenBlock(box_left+2, box_top+2, box_width-5, box_height-5, COMMON_WHITE);
| |
|
| |
| for(y=0;y<number_of_lines;++y)
| |
| {
| |
| DrawScreenText(box_left + 10 + (y * 32),box_top,String(EXG_DATA_EXTREME[y][1],2),LineColor[y],COMMON_WHITE);
| |
| DrawScreenText(box_left + 10 + (y * 40),box_top+120,String(EXG_DATA_EXTREME[y][0],2),LineColor[y],COMMON_WHITE);
| |
| }
| |
|
| |
| DrawScreenText(box_left + 130,box_top,String(delay_time*EXG_SAMPLE_SIZE/1000.0,2),COMMON_ORANGE,COMMON_WHITE);
| |
|
| |
| for(x=0;x<EXG_SAMPLE_SIZE-1;++x)
| |
| {
| |
| for(y=0;y<number_of_lines;++y)
| |
| {
| |
| data_point1 = 110-map(EXG_DATA[y][x],EXG_DATA_EXTREME[y][0],EXG_DATA_EXTREME[y][1],0,110);
| |
| data_point2 = 110-map(EXG_DATA[y][x+1],EXG_DATA_EXTREME[y][0],EXG_DATA_EXTREME[y][1],0,110);
| |
| DrawScreenLine(box_left+x+3,box_top+data_point1+8,box_left+x+4,box_top+data_point2+8,LineColor[y]);
| |
| }
| |
| }
| |
|
| |
| }
| |
|
| |
|
| |
|
| |
|
| |
| void EXG_Collect(EXG_Class EXG_Unit)
| |
| {
| |
| int EXG_Delay = 30;
| |
| int number_of_lines = 0;
| |
|
| |
| int max_value = -5000;
| |
| int min_value = 5000;
| |
|
| |
| number_of_lines = EXG_Unit.GetNumberAnalogLines();
| |
|
| |
| for(int x=0;x<4;++x)
| |
| {
| |
| EXG_DATA_EXTREME[x][0] = min_value;
| |
| EXG_DATA_EXTREME[x][1] = max_value;
| |
| }
| |
|
| |
| for(int x = 0; x < 1; ++x)
| |
| {
| |
| for(int y=0;y<number_of_lines;++y)
| |
| {
| |
| EXG_Unit.AnalogLineRead(y);
| |
| }
| |
| delay(EXG_Delay);
| |
| }
| |
|
| |
| for(int x = 0; x < EXG_SAMPLE_SIZE; ++x)
| |
| {
| |
| for(int y=0;y<number_of_lines;++y)
| |
| {
| |
| EXG_DATA[y][x] = EXG_Unit.AnalogLineRead(y);
| |
| if(EXG_DATA[y][x] > EXG_DATA_EXTREME[y][1])
| |
| EXG_DATA_EXTREME[y][1] = EXG_DATA[y][x];
| |
| if(EXG_DATA[y][x] < EXG_DATA_EXTREME[y][0])
| |
| EXG_DATA_EXTREME[y][0] = EXG_DATA[y][x];
| |
| }
| |
| delay(EXG_Delay);
| |
| }
| |
|
| |
| EXG_Display_Data(EXG_Unit,EXG_Delay);
| |
|
| |
| }
| |
|
| |
|
| |
| void EXG_Demo()
| |
| {
| |
| Serial.println("EXG Intro");
| |
| EXG_Frame();
| |
| while(1)
| |
| {
| |
| EXG_Collect(EXG_Unit[0]);
| |
| }
| |
| }
| |
|
| |
| </nowiki>
| |
|
| |
| [[Pseudo-Medical_Monitor_Code#Custom_Includes]]
| |