Resit project for target localisation
Revision 52:7bad54552502, committed 2022-02-04
- Comitter:
- ciarankane123
- Date:
- Fri Feb 04 23:40:11 2022 +0000
- Parent:
- 51:32f9ffeafb6d
- Commit message:
- Project
Changed in this revision
diff -r 32f9ffeafb6d -r 7bad54552502 Bitmap.cpp --- a/Bitmap.cpp Wed Jan 22 13:17:33 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -#include "Bitmap.h" - -#include <iostream> - -#include "N5110.h" - -Bitmap::Bitmap(int const *contents, - unsigned int const height, - unsigned int const width) - : - _contents(std::vector<int>(height*width)), - _height(height), - _width(width) -{ - // Perform a quick sanity check of the dimensions - if (_contents.size() != height * width) { - std::cerr << "Contents of bitmap has size " << _contents.size() - << " pixels, but its dimensions were specified as " - << width << " * " << height << " = " << width * height << std::endl; - } - - for(unsigned int i = 0; i < height*width; ++i) _contents[i] = contents[i]; -} - -/** - * @returns the value of the pixel at the given position - */ -int Bitmap::get_pixel(unsigned int const row, - unsigned int const column) const -{ - // First check that row and column indices are within bounds - if(column >= _width || row >= _height) - { - std::cerr << "The requested pixel with index " << row << "," << column - << "is outside the bitmap dimensions: " << _width << "," - << _height << std::endl; - } - - // Now return the pixel value, using row-major indexing - return _contents[row * _width + column]; -} - -/** - * @brief Prints the contents of the bitmap to the terminal - */ -void Bitmap::print() const -{ - for (unsigned int row = 0; row < _height; ++row) - { - // Print each element of the row - for (unsigned int column = 0; column < _width; ++column) - { - int pixel = get_pixel(row, column); - std::cout << pixel; - } - - // And then terminate with a new-line character - std::cout << std::endl; - } -} - -/** - * @brief Renders the contents of the bitmap onto an N5110 screen - * - * @param[in] lcd The screen to use for rendering - * @param[in] x0 The horizontal position in pixels at which to render the bitmap - * @param[in] y0 The vertical position in pixels at which to render the bitmap - * - * @details Note that x0, y0 gives the location of the top-left of the bitmap on - * the screen. - * This function only updates the buffer on the screen. You still need - * to refresh the screen in order to actually see the bitmap. - */ -void Bitmap::render(N5110 &lcd, - unsigned int const x0, - unsigned int const y0) const -{ - // Loop through each row of the bitmap image - for (unsigned int bitmap_row = 0; bitmap_row < _height; ++bitmap_row) - { - // Row index on the screen for rendering the row of pixels - unsigned int screen_row = y0 + bitmap_row; - - // Render each pixel in the row - for (unsigned int bitmap_col = 0; bitmap_col < _width; ++bitmap_col) - { - // Column index on the screen for rendering this pixel - int screen_col = x0 + bitmap_col; - - // Find the required value of the pixel at the given location within - // the bitmap data and then write it to the LCD screen - int pixel = get_pixel(bitmap_row, bitmap_col); - lcd.setPixel(screen_col, screen_row, pixel); - } - } -} \ No newline at end of file
diff -r 32f9ffeafb6d -r 7bad54552502 Bitmap.h --- a/Bitmap.h Wed Jan 22 13:17:33 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -#ifndef BITMAP_H -#define BITMAP_H - -#include <vector> - -// Forward declarations -class N5110; - -/** - * @brief A black & white bitmap that can be rendered on an N5110 screen - * @author Alex Valavanis <a.valavanis@leeds.ac.uk> - * - * @code - // First declare the pixel map data using '1' for black, - // or '0' for white pixels - static int sprite_data[] = { - 0,0,1,0,0, - 0,1,1,1,0, - 0,0,1,0,0, - 0,1,1,1,0, - 1,1,1,1,1, - 1,1,1,1,1, - 1,1,0,1,1, - 1,1,0,1,1 - }; - - // Instantiate the Bitmap object using the data above - Bitmap sprite(sprite_data, 8, 5); // Specify rows and columns in sprite - - // We can render the bitmap wherever we want on the screen - sprite.render(lcd, 20, 6); // x and y locations for rendering - sprite.render(lcd, 30, 10); - - // We can also print its values to the terminal - sprite.print(); - * @endcode - */ -class Bitmap -{ -private: - /** - * @brief The contents of the drawing, with pixels stored in row-major order - * @details '1' represents a black pixel; '0' represents white - */ - std::vector<int> _contents; - - unsigned int _height; ///< The height of the drawing in pixels - unsigned int _width; ///< The width of the drawing in pixels - -public: - Bitmap(int const *contents, - unsigned int const height, - unsigned int const width); - - int get_pixel(unsigned int const row, - unsigned int const column) const; - - void print() const; - - void render(N5110 &lcd, - unsigned int const x0, - unsigned int const y0) const; -}; - -#endif // BITMAP_H \ No newline at end of file
diff -r 32f9ffeafb6d -r 7bad54552502 N5110.cpp --- a/N5110.cpp Wed Jan 22 13:17:33 2020 +0000 +++ b/N5110.cpp Fri Feb 04 23:40:11 2022 +0000 @@ -56,8 +56,9 @@ void N5110::init() { turnOn(); // power up + wait_ms(10); // small delay seems to prevent spurious pixels during mbed reset reset(); // reset LCD - must be done within 100 ms - initSPI(); + // initSPI(); setContrast(0.55); // this may need tuning (say 0.4 to 0.6) setBias(3); // datasheet - 48:1 mux - don't mess with if you don't know what you're doing! (0 to 7)
diff -r 32f9ffeafb6d -r 7bad54552502 N5110.h --- a/N5110.h Wed Jan 22 13:17:33 2020 +0000 +++ b/N5110.h Fri Feb 04 23:40:11 2022 +0000 @@ -23,10 +23,10 @@ @brief The library can print primitive shapes (lines, circles, rectangles) @brief Acknowledgements to Chris Yan's Nokia_5110 Library. -@brief Revision 1.3 +@brief Revision 1.4 -@author Craig A. Evans -@date 7th February 2017 +@upgraded Dr. Edmond Nurellari +@date 1st December 2021 @code