Adicionada função para recebimento de comandos da GUI.

parent 0eb0ca70
......@@ -59,7 +59,7 @@ void Com_GUI::ReplyToPC( char firstChar, char secondChar)
void Com_GUI::SaveProtocolData()
{
//Receive protocol type and its parameters and returns "PR"
//Receive protocol type and its parameters
if (newDataFromPC)
{
newDataFromPC = false;
......@@ -70,8 +70,7 @@ void Com_GUI::SaveProtocolData()
rcvParam[2][prot]= ((messageFromPC[7]-1) & 255)<<8 | ((messageFromPC[6])&255);
rcvParam[3][prot]= ((messageFromPC[9]-1) & 255)<<8 | ((messageFromPC[8])&255);
rcvParam[4][prot]= ((messageFromPC[11]-1) & 255)<<8 | ((messageFromPC[10])&255);
rcvParam[5][prot]= ((messageFromPC[13]-1) & 255)<<8 | ((messageFromPC[12])&255);
ReplyToPC('P', 'R');
rcvParam[5][prot]= ((messageFromPC[13]-1) & 255)<<8 | ((messageFromPC[12])&255);
}
}
......@@ -80,29 +79,41 @@ unsigned char Com_GUI::RecvCommandHndlr()
if (messageFromPC[0]=='H' && messageFromPC[1]=='B')
{
ReplyToPC('H', 'B');
return 0;
return 1;
}
else if(messageFromPC[0]=='I' && messageFromPC[1]=='P')
{
digitalWrite(22, HIGH);
//StimulationProtocols.Stop();
digitalWrite(22, HIGH);
ReplyToPC('I', 'R');
return 1;
return 2;
}
else if(messageFromPC[0]=='A' && messageFromPC[1]=='P')
{
digitalWrite(22, LOW);
//StimulationProtocols.Jump();
digitalWrite(22, LOW);
ReplyToPC('A', 'R');
return 2;
return 3;
}
else
{
//Recebe primeiro protocolo
//Receive first protocol
prot = 0;
SaveProtocolData();
ReplyToPC('S', 'R');
prot++;
//Receive second protocol
SaveProtocolData();
ReplyToPC('S', 'R');
prot++;
//Recebe segundo protocolo...
//Receive third protocol
SaveProtocolData();
prot = 0;
ReplyToPC('S', 'R');
return 4;
}
//else
//{
//ReplyToPC('C', 'U');
//return 0;
//}
}
......@@ -27,6 +27,8 @@ class Com_GUI
uint8_t prot = 0;
static const byte buffSize = 40;
unsigned char messageFromPC[buffSize] = {0};
unsigned char rcvProt[2][3];
uint16_t rcvParam[6][3];
private:
......@@ -37,9 +39,8 @@ class Com_GUI
uint8_t bytesRecvd;
bool readInProgress = false;
bool newDataFromPC = false;
unsigned char rcvStatus = 0;
unsigned char rcvProt[2][3];
unsigned int rcvParam[6][3];
unsigned char rcvStatus = 0;
};
#endif
......@@ -193,3 +193,8 @@ void StimulationProtocols::Stop()
DDRL |= (0 << PL4);
DDRL |= (0 << PL5);
}
void StimulationProtocols::Start(unsigned char protocolType[2][3], uint16_t protocolParam[6][3], uint8_t protNumber)
{
protNumber = 0;
}
\ No newline at end of file
......@@ -28,7 +28,7 @@ class StimulationProtocols
void UnipolarBasalInterrupt( uint16_t H, uint16_t IPI, uint16_t ITI );
void Stop();
//void Jump();
void Start(unsigned char protocolType[2][3], uint16_t protocolParam[6][3], uint8_t protNumber);
private:
uint16_t pulseCounter;
uint8_t state;
......
//Libraries
#include <avr/io.h> //inclui biblioteca de input/output do AVR
#include <avr/eeprom.h> //inclui biblioteca de EEPROM
#include <avr/interrupt.h> //inclui biblioteca de interrupt
#include <stdlib.h> //inclui biblioteca padrao
#include <string.h> //inclui biblioteca de strings
#include <avr/io.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <Stdint.h>
#include "StimulationProtocols.h"
#include "Com_GUI.h"
ISR(TIMER1_COMPA_vect) //interrupt when OCR1X and TCNT1 match (low PWM)
{
}
//Main Function
int main()
{
Com_GUI Com_GUI;
unsigned char commandState;
pinMode( 22 , OUTPUT );
digitalWrite( 22, LOW);
Com_GUI.SerialConfig();
......@@ -22,7 +27,22 @@ int main()
while(1)
{
Com_GUI.GetDataFromPC();
Com_GUI.RecvCommandHndlr();
commandState = Com_GUI.RecvCommandHndlr();
switch (commandState)
{
case 2:
//StimulationProtocols.Stop();
break;
case 3:
//StimulationProtocols.Jump();
break;
case 4:
//StimulationProtocols.Start();
break;
default:
break;
}
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment