/*=============================
void coolDownMode

inputs: none
returns: n/a

Creates a loop that checks to see if mana
is at the minimum value needed to exit cool
down mode (MIN_MANA). If it is, the loop
exits and the method is finished. It does
not need to do anything inside the loop
because the overflow ISR will automatically
replenish mana.

Written by: Katie Hobble
=================================*/
void coolDownMode() {
    //Reset manaCount to ensure we are starting from the beginning
    manaCount = 0;
    //Play audio and display visual for cool down mode
    LCDdisplay(ice, 0);
    playAudio(cooldown, 0);

    //This will check to see if mana is at the minimum
    //value it needs to be to exit cool down mode
    while(mana < MIN_MANA) {
        //Do nothing, let timer overflow do its thing
        _delay_ms(8000);
        //Clear the LCD display
        LCDdisplay(10,0);

    }//end while

    //Turn off sound (in case the cooldown sound is trying to loop)
    PORTD = 0xFF;
    //Because IR receive doesn't work, we are going to decrement health every time cooldown mode is entered
    //decrement health
    health--;

    //If health has reached zero, just turn off interrupts
    //Otherwise, display the health
    if(health<0) {
        //Clear the interrupts
        cli();
    }
    else {
        //Display new health
        LCDdisplay(damage, health);
    }//end if
}//end coolDownMode()
Beispiel #2
0
void lcdDisplaySensors(unsigned int fd,struct sGENERAL patient){

	//while(GPIORead(changeDisplay)!=HIGH){
		char Nokia_Temp[10],Nokia_BPM[10];	
	
		Sensors.BPM = (unsigned int)serialGetchar(fd);
		Sensors.Temp = ((float)serialGetchar(fd)*5/(1023))/0.01;			
		Sensors.BPMState = healthState(patient,Sensors.BPM);
		Sensors.TempState = isNormal(Sensors.Temp);
	
		snprintf(Nokia_Temp,10,"%.1f*C",Sensors.Temp);
		snprintf(Nokia_BPM,10,"%dBPM",Sensors.BPM);	
	
		LCDclear();

		printf("Temp:%.1f\n",Sensors.Temp);
		printf("BPM:%d\n",Sensors.BPM);
		LCDdrawstring(20,0,"SENSORES");
		LCDdrawstring(25,10,Nokia_Temp);
		LCDdrawstring(20,20,Sensors.TempState);
		LCDdrawstring(25,30,Nokia_BPM);
		LCDdrawstring(20,40,Sensors.BPMState);
	
		LCDdisplay();
	//}
}	
Beispiel #3
0
void LCDshowLogo()
{
	uint32_t i;
	for (i = 0; i < LCDWIDTH * LCDHEIGHT / 8; i++  )
	{
		pcd8544_buffer[i] = pi_logo[i];
	}
	LCDdisplay();
}
Beispiel #4
0
static int 
screen_update(screen_t *scp)
{

	LCDdrawstring(0, 0, scp->sc_line1_buf);
	LCDdrawline(0, 10, 83, 10, BLACK);
	if (scp->sc_line2_buf[0] != '\0')
		LCDdrawstring(0, 12, scp->sc_line2_buf);
	if (scp->sc_line3_buf[0] != '\0')
		LCDdrawstring(0, 20, scp->sc_line3_buf);
	if (scp->sc_line4_buf[0] != '\0')
		LCDdrawstring(0, 28, scp->sc_line4_buf);
	LCDdisplay();
	return (0);
}
/*==========================================
int main()

	Calls the initialize function then calls
	the main loop

	Written by: Katie Hobble
=============================================*/
int main() {
    //Call the initialize function
    initialize();

    //Once all pins, communications, and global variables are initialized
    //enter the main loop of the program
    mainLoop();

    //Main loop has exited, this means the bow has no health
    //disable any other interrupts
    cli();
    //Display the bow destroyed screen
    LCDdisplay(4, 0);

    //return 0, end main
    return 0;
}//end main
/*=============================
void mainLoop

inputs: none
returns: n/a

Creates a loop while health > 0 that first
checks to see if mana is above zero,
then if it is not it calls coolDownMode(),
otherwise it polls the bowNocked method
to check for user input. If bowNocked is
TRUE, get the drawStrength in a local uint8_t
by calling drawStrength(), and calls sendIR() using
the drawStrength variable.

Written by: Katie Hobble
=================================*/
void mainLoop() {
    //Create an infinite loop to run while the bow is in use
    while(health > 0) {
        //First, check to see if mana is less than 0. If it is, enter
        //cool down mode to replenish mana
        if(mana <= 0) {
            //Mana needs to be replenished, enter cool down mode.
            coolDownMode();
        }//end if

        //We get here only if mana is at an acceptable amount.
        //Poll the bowNocked method to see if there has been any user input
        if(bowNocked()) {

            //Play the bow nocked sound
            playAudio(soundInput, 0);
            //User input was detected by bowNocked() method. Call the
            //drawStrength() method to get the draw strength of the user's
            //shot in the form of a uint8_t
            int drawStrength = measureDrawStrength();

            //Pass the uint8_t drawStrength to the sendIR method if its greater than 0
            if(drawStrength > 0) {
                //Display the bow's firing power
                LCDdisplay(fire,drawStrength);
                //Send the damage packets
                sendIR(drawStrength);
            }//end if
        }//end if
    }//end while

    //Health is less than zero, send out some stun packets through PC3 (short range)
    for(int i = 0; i < 5; i++) {
        //Send the start envelope
        FiveSixK(10, 0x08);
        //Send the first stun data envelpe
        FiveSixK(40, 0x08);
        //Repeat the stun data envelope
        FiveSixK(40, 0x08);
        //Send stop envelope
        FiveSixK(150, 0x08);
        //Delay a little bit
        _delay_ms(50);
    }//end for
}//end mainLoop
Beispiel #7
0
void lcdDisplayProfile(struct sGENERAL perfil){
	//while(GPIORead(changeDisplay)!=HIGH){		
		char	Nokia_Nome[25],Nokia_Genero[10],Nokia_Idade[10];
		unsigned int idade = perfil.Age;

		snprintf(Nokia_Nome,25,"Nome:%s",perfil.Name);
		snprintf(Nokia_Genero,10,"Genero:%s",perfil.Sex);
		snprintf(Nokia_Idade,10,"Idade:%d",perfil.Age); 
	
		LCDclear();

		LCDdrawstring(25,0,"PERFIL");
		LCDdrawline(0, 9, 83, 9, BLACK);
		LCDdrawstring(0,11,Nokia_Nome);
		LCDdrawstring(0,29,Nokia_Genero);
		LCDdrawstring(0,39,Nokia_Idade);
	
		LCDdisplay();
	//}
}	
/*=============================
void sendIR

inputs: int drawStrength
returns: n/a

Fires a damage packet for every increment
of drawStrength. Also decreases mana based
on the drawStrength.

Written by: Katie Hobble
=================================*/
void sendIR(int drawStrength) {
    //Decrease mana if the strength is greater than 0
    if (drawStrength > 0) {
        //Decrease mana according to its value (it'll be either 0 or mana-drawStrength)
        if(mana - drawStrength < 0) {
            //Set mana to be zero if it was going to be negative
            mana = 0;
            manaCount = 0;
        }
        else {
            //Set mana to be itself minus the drawstrength
            mana = mana - drawStrength;
            manaCount = 0;
        }//end if

        //Play the firing sound
        playAudio(shoot, drawStrength);
        //Delay for a little to let it play
        _delay_ms(300);
        //Turn off sound
        PORTD = 0xFF;

        //Send Damage Packet to PC4 (long range)
        for (int i = 0; i < drawStrength; i ++) {
            //Send start envelope
            FiveSixK(10, 0x10);
            //Send damage data envelope
            FiveSixK(20, 0x10);
            //Send damage repeat data evelope
            FiveSixK(20, 0x10);
            //Send stop envelope
            FiveSixK(150, 0x10);
            //Delay for a little
            _delay_ms(50);
        }//end for

        //Display the new mana
        LCDdisplay(plasma, mana);
    }//end if
}//end sendIR
int main (void)
{
  // print infos
  printf("Raspberry Pi PCD8544 sysinfo display\n");
  printf("========================================\n");

  // check wiringPi setup
  if (wiringPiSetup() == -1)
  {
	printf("wiringPi-Error\n");
    exit(1);
  }

  // init and clear lcd
  LCDInit(_sclk, _din, _dc, _cs, _rst, contrast);
  LCDclear();

  // show logo
  LCDshowLogo();

  delay(2000);

  for (;;)
  {
	  // clear lcd
	  LCDclear();

	  // get system usage / info
	  struct sysinfo sys_info;
	  if(sysinfo(&sys_info) != 0)
	  {
		printf("sysinfo-Error\n");
	  }

	  // uptime
	  char uptimeInfo[15];
	  unsigned long uptime = sys_info.uptime / 60;
	  sprintf(uptimeInfo, "Uptime %ld min.", uptime);

	  // cpu info
	  char cpuInfo[10];
	  unsigned long avgCpuLoad = sys_info.loads[0] / 1000;
	  sprintf(cpuInfo, "CPU %ld%%", avgCpuLoad);

	  // ram info
	  char ramInfo[10];
	  unsigned long totalRam = sys_info.freeram / 1024 / 1024;
	  sprintf(ramInfo, "RAM %ld MB", totalRam);

	  // build screen
	  //LCDdrawstring(0, 0, "Raspberry Pi:");
	  LCDdrawstring(0, 0, "Sunfounder.com");
	  LCDdrawline(0, 10, 83, 10, BLACK);
	  LCDdrawstring(0, 12, uptimeInfo);
	  LCDdrawstring(0, 20, cpuInfo);
	  LCDdrawstring(0, 28, ramInfo);
	  LCDdisplay();

	  delay(1000);
  }

    //for (;;){
  //  printf("LED On\n");
  //  digitalWrite(pin, 1);
  //  delay(250);
  //  printf("LED Off\n");
  //  digitalWrite(pin, 0);
  //  delay(250);
  //}

  return 0;
}
Beispiel #10
0
static void go_go_go(void)
{
	int fd;
	struct timeval tv;
	static char line[128];
	int nchars = 0;
    int ntimes_out = 0;
    int ntimes_reset = 0;
	if ((fd = open(DEVFILE, O_RDWR|O_NONBLOCK)) == -1)
		fatal("dispd: Failed to open %s: %m\n", DEVFILE);

	for (;;) {
		int n, width, servo;
		fd_set ifds;
		char width_arg[64];

		FD_ZERO(&ifds);
		FD_SET(fd, &ifds);
        tv.tv_sec = 3;
        tv.tv_usec = 0;
		if ((n = select(fd+1, &ifds, NULL, NULL, &tv)) != 1)
        {
            // turn off backlight after 6 sec
            if(++ntimes_out > 2)
            {
                digitalWrite(_bk, LOW);
                delay(10);
            }
            if(++ntimes_reset > 20) // 60 sec
            {
                ntimes_reset = 0;
                LCDInit(_sclk, _din, _dc, _cs, _rst, contrast);
                LCDdisplay();
                delay(10);
            }
            //printf("%s : %d\n", __FILE__, __LINE__);
			continue;
        }   
		while (read(fd, line+nchars, 1) == 1) {
            //printf("%s : %d\n", __FILE__, __LINE__);
			if (line[nchars] == '\n') 
            {
				line[nchars] = '\0';
				nchars = 0;
                std::string str = line;

                // do whatever
                if(strcmp(line,"%clear%") == 0)                
                {
                    linebuff.clear();
                    update_display();
                    digitalWrite(_bk, HIGH);               
                }   
                else if(strcmp(line,"%logo%") == 0)
                {
                    linebuff.clear();
                    LCDclear();
                    LCDshowLogo();
                    digitalWrite(_bk, HIGH);
                }
                else if(str.substr(0,5) == "%bat%")
                {
                    std::string val = str.substr(6, str.npos);
                    battery_level = atoi(val.c_str());
                    update_display();
                }
                else if(str.substr(0,6) == "%plug%")
                {
                    std::string val = str.substr(7, str.npos);
                    battery_plugged = (atoi(val.c_str()) != 0);
                    update_display();
                }

                else
                {
                    int start = 0;  
                    int size = 14;  
                    while (start < str.size()) 
                    {  
                        int end = ((start + size) < str.size()) ? size : str.size() - start;                        
                        if(linebuff.size()>4)
                            linebuff.erase(linebuff.begin());	                  
                        linebuff.push_back(str.substr(start, end));
                        start += size;  
                    } 
                    update_display();
                    digitalWrite(_bk, HIGH);
                    ntimes_out = 0;
                }
                // turn off backlight after 5 sec
                if(++ntimes_out > 5)
                {
                    digitalWrite(_bk, LOW);
                    delay(10);
                }
                LCDdisplay();
                delay(10);
			} 
            else 
            {
				if (++nchars >= 126) {
					fprintf(stderr, "Input too long\n");
					nchars = 0;
				}
			}
		} // end while
	} // end for
}
Beispiel #11
0
int main (void)
{
  // print infos
  printf("Raspberry Pi PCD8544 test\n");
  printf("========================================\n");
  
  printf("CLK on Port %i \n", _sclk);
  printf("DIN on Port %i \n", _din);
  printf("DC on Port %i \n", _dc);
  printf("CS on Port %i \n", _cs);
  printf("RST on Port %i \n", _rst);  
  printf("========================================\n");
  
  // check wiringPi setup
  if (wiringPiSetup() == -1)
  {
	printf("wiringPi-Error\n");
    exit(1);
  }
  
  // init and clear lcd
  LCDInit(_sclk, _din, _dc, _cs, _rst, contrast);
  LCDclear();

  // turn all the pixels on (a handy test)
  printf("Test: All pixels on.\n");
  LCDcommand(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYALLON);
  delay(1000);
  // back to normal
  printf("Test: All pixels off.\n");
  LCDcommand(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL);
  LCDclear();
  
  // display logo
  printf("Test: Display logo.\n");
  LCDshowLogo();
  delay(2000);
  LCDclear();
  
  // draw a single pixel
  printf("Test: Display single pixel.\n");
  LCDsetPixel(10, 10, BLACK);
  LCDdisplay();
  delay(2000);
  LCDclear();
  
  // draw many lines
  printf("Test: Draw many lines.\n");
  int i;
  for (i=0; i<84; i+=4) {
    LCDdrawline(0, 0, i, 47, BLACK);
  }  
  for (i=0; i<48; i+=4) {
    LCDdrawline(0, 0, 83, i, BLACK);
  }
  LCDdisplay();
  delay(2000);
  LCDclear();
  
  // draw rectangles
  printf("Test: Draw rectangles.\n");
  for (i=0; i<48; i+=2) {
    LCDdrawrect(i, i, 96-i, 48-i, BLACK);
  }
  LCDdisplay();
  delay(2000);
  LCDclear();
  
  // draw multiple rectangles
  printf("Test: Draw multiple rectangles.\n");
  for (i=0; i<48; i++) {
    // alternate colors for moire effect
    LCDfillrect(i, i, 84-i, 48-i, i%2);
  }
  LCDdisplay();
  delay(2000);
  LCDclear();
  
  // draw mulitple circles
  printf("Test: Draw multiple circles.\n");
  for (i=0; i<48; i+=2) {
    LCDdrawcircle(41, 23, i, BLACK);
  }
  LCDdisplay();
  delay(2000);
  LCDclear();
  
  // draw the first ~120 characters in the font
  printf("Test: Draw the first ~120 chars.\n");
  for (i=0; i < 64; i++) {
    LCDdrawchar((i % 14) * 6, (i/14) * 8, i);
  }    
  LCDdisplay();
  delay(2000);
  for (i=0; i < 64; i++) {
    LCDdrawchar((i % 14) * 6, (i/14) * 8, i + 64);
  }
  LCDdisplay();
  delay(2000);
  LCDclear();
  
  return 0;
}
/*=============================
int measureDrawStrength()

inputs: none
returns: int drawStrength

Reads in the current ADC while the bow
has not fired, and returns the bow's
draw back strength on a scale of 1 to 4
while the bow is being drawn back and
when the bow fires

Written by: Trevor Eckert
Assistd by: Katie Hobble
=================================*/
int measureDrawStrength() {
    //range values
    int adc_val;
    int nockThresh = 280;
    int returnValue = 0;

    //adc values at each window
    int oneThresh = nockThresh - 5; //275
    int twoThresh = nockThresh - 35; //245
    int threeThresh = nockThresh - 55; //225
    int fourThresh = nockThresh - 75; //205

    //an array of the adc values initilized with the same threshold
    //value to make the initial slope zero
    int adcArray[6] = {nockThresh,nockThresh,nockThresh,nockThresh,nockThresh,nockThresh};

    //get the adc value
    adc_val = ReadADC(0);

    //continue to read in adc while the bow hasn't been fired
    while(!isFired(adcArray)) {
        //get the adc value
        adc_val = ReadADC(0);
        //this if statment checks to see if the bow has been returned to the initial state without being fired
        if(!bowNocked() && adcArray[0] < nockThresh) {
            //bow has returned, set the return value to zero
            returnValue=0;
            //clear the power bar
            LCDdisplay(power, 0);
            //turn off sound
            PORTD = 0xFF;
            //break out of the loop
            break;
        }//end if

        //play drawback audio if the bow hasn't been fired or returned
        if(returnValue > 0) {
            playAudio(soundInput, returnValue);
        }//end if

        //compare the adc values to the thresholds and set display its corresponding power
        //also set the return value to be what that power is

        if (adc_val <= oneThresh && adc_val > twoThresh) {
            //Call visual passing 1
            LCDdisplay(power,1);
            returnValue = 1;
        }
        else if (adc_val <= twoThresh && adc_val > threeThresh) {
            //Call visual passing 2
            LCDdisplay(power,2);
            returnValue = 2;
        }
        else if (adc_val <= threeThresh && adc_val > fourThresh) {
            //Call visual passing 3
            LCDdisplay(power,3);
            returnValue = 3;
        }
        else if(adc_val <= fourThresh) {
            //Call visual passing 4
            LCDdisplay(power, 4);
            returnValue = 4;
        }//end if

        //create a temporary array with the new adc_val
        int temp[6] = {adc_val, adcArray[0],adcArray[1],adcArray[2],adcArray[3],adcArray[4]};
        //set adcArray to be the temporary array
        for(int i = 0; i < 6; i ++) {
            adcArray[i] = temp[i];
        }//end for
    }//end while

    //Return the final ADC value by looking at thresholds
    //we look at adcArray[5] to see where the bow was at when it was fired
    if(adcArray[5] <= oneThresh && adcArray[5] > twoThresh) {
        returnValue = 1;
    }
    else if(adcArray[5] <= twoThresh && adcArray[5] > threeThresh) {
        returnValue = 2;
    }
    else if (adcArray[5] <= threeThresh && adcArray[5] > fourThresh) {
        returnValue = 3;
    }
    else if(adcArray[5] <= fourThresh) {
        returnValue = 4;
    }//end if

    return returnValue;
}//end measureDrawStrength