Question

C language. A file, display.c handles all display to the LED array. It will need a...

C language. A file, display.c handles all display to the LED array. It will need a global variable with type *pi_framebuffer_t. (in C, "global" variables are scoped only to the file in which they are defined unless other actions are taken). Should have at least the following functions:
void openDisplay(void): allocate the Pi Framebuffer device and store in a "global" variable for later use. This function should only need to be called one time when the program runs.
void closeDisplay(void): deallocate the Pi Framebuffer device (if it exists) and set the storage variable to NULL. Be sure this does the right thing if called before openDisplay()!
void displayLetter(char letter, int xOffset, int yOffset) : draws the provided letter on the LED array oriented so that "down" is towards the joystick, but shifted to the right by xOffset and down by yOffset. Note: the only letters you need to be able to draw are the capital initials of all partners in your group (you should be able to draw upon the "monogramming" assignment). Don't forget that if all letters would be the same, substitute a '3' for one of them.
void clearDisplay(void): clears the display

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include "scroll.h"
#include <stddef.h>
#include <stdio.h>
#include "sense.h"

#define BLACK 0x0000
#define WHITE 0xFFFF
pi_framebuffer_t *fb = NULL;

void openDisplay(void)
{
   if(fb==NULL)
   {
       fb=getFrameBuffer();
   }
}

void closeDisplay(void)
{
   if(fb)
   {
       clearFrameBuffer(fb,BLACK);
       freeFrameBuffer(fb);
       fb=NULL;
   }
}

void displayLetter(char letter, int xOffset, int yOffset)
{
   if(fb == NULL)
   {
       fprintf(stderr,"Tried to draw (%d,%d) to a non-existent frame buffer!\n",xOffset,yOffset);
       return;
   }
   sense_fb_bitmap_t *bm=fb->bitmap;
   clearFrameBuffer(fb,BLACK);

   xOffset=(xOffset%8+8)%8;
   yOffset=(yOffset%8+8)%8;

   if(letter == 'Y')
   {
       bm->pixel[(1+yOffset)%8][(1+xOffset)%8]=WHITE;
       bm->pixel[(1+yOffset)%8][(2+xOffset)%8]=WHITE;
       bm->pixel[(1+yOffset)%8][(3+xOffset)%8]=WHITE;
       bm->pixel[(2+yOffset)%8][(4+xOffset)%8]=WHITE;
       bm->pixel[(3+yOffset)%8][(5+xOffset)%8]=WHITE;
       bm->pixel[(3+yOffset)%8][(6+xOffset)%8]=WHITE;
       bm->pixel[(3+yOffset)%8][(7+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(1+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(2+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(3+xOffset)%8]=WHITE;
       bm->pixel[(5+yOffset)%8][(4+xOffset)%8]=WHITE;
       bm->pixel[(4+yOffset)%8][(5+xOffset)%8]=WHITE;
       bm->pixel[(4+yOffset)%8][(6+xOffset)%8]=WHITE;
       bm->pixel[(4+yOffset)%8][(7+xOffset)%8]=WHITE;
   }

   else if(letter == 'N')
   {
       bm->pixel[(1+yOffset)%8][(1+xOffset)%8]=WHITE;
       bm->pixel[(1+yOffset)%8][(2+xOffset)%8]=WHITE;
       bm->pixel[(1+yOffset)%8][(3+xOffset)%8]=WHITE;
       bm->pixel[(1+yOffset)%8][(4+xOffset)%8]=WHITE;
       bm->pixel[(1+yOffset)%8][(5+xOffset)%8]=WHITE;
       bm->pixel[(1+yOffset)%8][(6+xOffset)%8]=WHITE;
       bm->pixel[(1+yOffset)%8][(7+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(1+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(2+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(3+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(4+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(5+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(6+xOffset)%8]=WHITE;
       bm->pixel[(6+yOffset)%8][(7+xOffset)%8]=WHITE;
       bm->pixel[(5+yOffset)%8][(2+xOffset)%8]=WHITE;
       bm->pixel[(5+yOffset)%8][(3+xOffset)%8]=WHITE;
       bm->pixel[(4+yOffset)%8][(3+xOffset)%8]=WHITE;
       bm->pixel[(4+yOffset)%8][(4+xOffset)%8]=WHITE;
       bm->pixel[(3+yOffset)%8][(4+xOffset)%8]=WHITE;
       bm->pixel[(3+yOffset)%8][(5+xOffset)%8]=WHITE;
       bm->pixel[(2+yOffset)%8][(5+xOffset)%8]=WHITE;
       bm->pixel[(2+yOffset)%8][(6+xOffset)%8]=WHITE;
   }
}

void clearDisplay(void)
{
   if(fb)
   {
       clearFrameBuffer(fb,BLACK);
   }
}

Add a comment
Know the answer?
Add Answer to:
C language. A file, display.c handles all display to the LED array. It will need a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT