![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
3rd year group project. Electronic and Electrical Engineering. Heriot-Watt University. This is the code for the mbed for the Automatic Little Object Organiser (ALOO).
Dependencies: MCP23017 TCS3472_I2C WattBob_TextLCD mbed
Block.cpp@32:9a4046224b11, 2015-12-17 (annotated)
- Committer:
- dreamselec
- Date:
- Thu Dec 17 17:23:24 2015 +0100
- Revision:
- 32:9a4046224b11
- Parent:
- 30:c0bc92d009fe
Comments and clean up.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreamselec |
6:98fe30430194 | 1 | /* |
dreamselec |
6:98fe30430194 | 2 | * Block.cpp |
dreamselec |
6:98fe30430194 | 3 | * |
dreamselec |
6:98fe30430194 | 4 | * Created on: 16 Nov 2015 |
dreamselec |
32:9a4046224b11 | 5 | * Author: Chandan Siyag |
dreamselec |
6:98fe30430194 | 6 | */ |
dreamselec |
6:98fe30430194 | 7 | |
dreamselec |
6:98fe30430194 | 8 | #include "Block.h" |
dreamselec |
6:98fe30430194 | 9 | |
dreamselec |
6:98fe30430194 | 10 | Colour::Colour(){ |
dreamselec |
6:98fe30430194 | 11 | setRed(0); |
dreamselec |
6:98fe30430194 | 12 | setBlue(0); |
dreamselec |
6:98fe30430194 | 13 | setGreen(0); |
dreamselec |
6:98fe30430194 | 14 | setAlpha(0); |
dreamselec |
6:98fe30430194 | 15 | } |
dreamselec |
6:98fe30430194 | 16 | |
dreamselec |
6:98fe30430194 | 17 | Colour::~Colour(){ |
dreamselec |
6:98fe30430194 | 18 | |
dreamselec |
6:98fe30430194 | 19 | } |
dreamselec |
6:98fe30430194 | 20 | |
dreamselec |
32:9a4046224b11 | 21 | /// Create a new colour object from passed array of components. |
dreamselec | 20:4e0f0944f28f | 22 | Colour::Colour(float components[4]){ |
dreamselec | 20:4e0f0944f28f | 23 | for (int i = 0; i < sizeof(components)/sizeof(*components); i++){ |
dreamselec | 20:4e0f0944f28f | 24 | this->components[i] = components[i]; |
dreamselec | 20:4e0f0944f28f | 25 | } |
dreamselec | 20:4e0f0944f28f | 26 | } |
dreamselec | 20:4e0f0944f28f | 27 | |
dreamselec |
32:9a4046224b11 | 28 | /// Create new colour object from passed colour object. |
dreamselec |
32:9a4046224b11 | 29 | /// Copies data, not a new pointer |
dreamselec |
6:98fe30430194 | 30 | Colour::Colour(const Colour& rhs){ |
dreamselec |
6:98fe30430194 | 31 | setRed(rhs.getRed()); |
dreamselec |
6:98fe30430194 | 32 | setBlue(rhs.getBlue()); |
dreamselec |
6:98fe30430194 | 33 | setGreen(rhs.getGreen()); |
dreamselec |
6:98fe30430194 | 34 | setAlpha(rhs.getAlpha()); |
dreamselec |
6:98fe30430194 | 35 | } |
dreamselec | 7:b6e31bfdb2af | 36 | |
dreamselec |
32:9a4046224b11 | 37 | /// Sends description to PC about itself. |
dreamselec |
32:9a4046224b11 | 38 | /// Cannot be used here since it doesn't know about pc object. Defined in globals.h |
dreamselec | 26:bbcc25418ffa | 39 | void Colour::printDescription(){ |
dreamselec | 26:bbcc25418ffa | 40 | // pc.printf("Red: %.3f, Green: %.3f, Blue: %.3f, Clear: %.3f\n", this->component[0], this->component[1], this->component[2], this->component[3]); |
dreamselec | 26:bbcc25418ffa | 41 | } |
dreamselec | 26:bbcc25418ffa | 42 | |
dreamselec | 7:b6e31bfdb2af | 43 | Block::Block(){ |
dreamselec | 7:b6e31bfdb2af | 44 | this->size = Small; |
dreamselec | 7:b6e31bfdb2af | 45 | this->minColour = Colour(); |
dreamselec | 20:4e0f0944f28f | 46 | this->averageColour = Colour(); |
dreamselec | 7:b6e31bfdb2af | 47 | this->maxColour = Colour(); |
dreamselec |
29:9c0339e3c593 | 48 | this->colour = Block::Red; |
dreamselec | 7:b6e31bfdb2af | 49 | } |
dreamselec |
29:9c0339e3c593 | 50 | |
dreamselec |
32:9a4046224b11 | 51 | /// Create new block object from passed size and colour |
dreamselec |
29:9c0339e3c593 | 52 | Block::Block(Size size, BlockColour blockColour){ |
dreamselec | 30:c0bc92d009fe | 53 | this->minColour = Colour(); |
dreamselec | 30:c0bc92d009fe | 54 | this->averageColour = Colour(); |
dreamselec | 30:c0bc92d009fe | 55 | this->maxColour = Colour(); |
dreamselec |
29:9c0339e3c593 | 56 | this->colour = blockColour; |
dreamselec |
29:9c0339e3c593 | 57 | this->size = size; |
dreamselec |
29:9c0339e3c593 | 58 | } |
dreamselec |
29:9c0339e3c593 | 59 | |
dreamselec |
32:9a4046224b11 | 60 | /// Create new block with size and default colour |
dreamselec | 7:b6e31bfdb2af | 61 | Block::Block(Size size) { |
dreamselec | 7:b6e31bfdb2af | 62 | // TODO Auto-generated constructor stub |
dreamselec | 7:b6e31bfdb2af | 63 | this->size = size; |
dreamselec | 7:b6e31bfdb2af | 64 | this->minColour = Colour(); |
dreamselec | 7:b6e31bfdb2af | 65 | this->maxColour = Colour(); |
dreamselec | 20:4e0f0944f28f | 66 | this->averageColour = Colour(); |
dreamselec | 20:4e0f0944f28f | 67 | } |
dreamselec | 20:4e0f0944f28f | 68 | |
dreamselec |
32:9a4046224b11 | 69 | /// Create new block object with passed properties |
dreamselec | 20:4e0f0944f28f | 70 | Block::Block(Size size, Colour minColour, Colour maxColour, Colour averageColour){ |
dreamselec | 20:4e0f0944f28f | 71 | this->size = size; |
dreamselec | 20:4e0f0944f28f | 72 | this->minColour = Colour(minColour); |
dreamselec | 20:4e0f0944f28f | 73 | this->maxColour = Colour(maxColour); |
dreamselec | 20:4e0f0944f28f | 74 | this->averageColour = Colour(averageColour); |
dreamselec | 7:b6e31bfdb2af | 75 | } |
dreamselec | 7:b6e31bfdb2af | 76 | |
dreamselec |
32:9a4046224b11 | 77 | /// Copy block object to a new one. |
dreamselec | 7:b6e31bfdb2af | 78 | Block::Block(const Block& rhs){ |
dreamselec | 7:b6e31bfdb2af | 79 | minColour = Colour(rhs.minColour); |
dreamselec | 7:b6e31bfdb2af | 80 | maxColour = Colour(rhs.maxColour); |
dreamselec | 20:4e0f0944f28f | 81 | averageColour = Colour(rhs.averageColour); |
dreamselec | 7:b6e31bfdb2af | 82 | size = rhs.size; |
dreamselec | 7:b6e31bfdb2af | 83 | } |
dreamselec | 7:b6e31bfdb2af | 84 | |
dreamselec | 7:b6e31bfdb2af | 85 | Block::~Block() { |
dreamselec | 7:b6e31bfdb2af | 86 | // TODO Auto-generated destructor stub |
dreamselec | 7:b6e31bfdb2af | 87 | } |
dreamselec | 7:b6e31bfdb2af | 88 | |
dreamselec | 26:bbcc25418ffa | 89 | void Block::printDescription(){ |
dreamselec | 26:bbcc25418ffa | 90 | |
dreamselec | 26:bbcc25418ffa | 91 | } |