NXP Rapid IoT prototyping kit port of Silabs "hungry gecko" smake-like game. https://os.mbed.com/teams/SiliconLabs/code/Hungry_gecko/

Dependencies:   lib_sx9500 GraphicsDisplay ColorMemLCD Large_fonts

See a detailed description of this project on Hackster.io . https://www.hackster.io/marcomerli/riotwear-snake-ca6dfc

Committer:
batman52
Date:
Fri Dec 27 16:04:44 2019 +0000
Revision:
81:737dff75e013
Parent:
80:77210aa1ad9c
add use of touch sensor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
batman52 80:77210aa1ad9c 1 /***************************************************************************//**
batman52 80:77210aa1ad9c 2 * @file asymmetricPart.h
batman52 80:77210aa1ad9c 3 * @brief class for an asymmetric head object for gecko.h
batman52 80:77210aa1ad9c 4 *******************************************************************************
batman52 80:77210aa1ad9c 5 * @section License
batman52 80:77210aa1ad9c 6 * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>
batman52 80:77210aa1ad9c 7 *******************************************************************************
batman52 80:77210aa1ad9c 8 *
batman52 80:77210aa1ad9c 9 * Permission is granted to anyone to use this software for any purpose,
batman52 80:77210aa1ad9c 10 * including commercial applications, and to alter it and redistribute it
batman52 80:77210aa1ad9c 11 * freely, subject to the following restrictions:
batman52 80:77210aa1ad9c 12 *
batman52 80:77210aa1ad9c 13 * 1. The origin of this software must not be misrepresented; you must not
batman52 80:77210aa1ad9c 14 * claim that you wrote the original software.
batman52 80:77210aa1ad9c 15 * 2. Altered source versions must be plainly marked as such, and must not be
batman52 80:77210aa1ad9c 16 * misrepresented as being the original software.
batman52 80:77210aa1ad9c 17 * 3. This notice may not be removed or altered from any source distribution.
batman52 80:77210aa1ad9c 18 *
batman52 80:77210aa1ad9c 19 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
batman52 80:77210aa1ad9c 20 * obligation to support this Software. Silicon Labs is providing the
batman52 80:77210aa1ad9c 21 * Software "AS IS", with no express or implied warranties of any kind,
batman52 80:77210aa1ad9c 22 * including, but not limited to, any implied warranties of merchantability
batman52 80:77210aa1ad9c 23 * or fitness for any particular purpose or warranties against infringement
batman52 80:77210aa1ad9c 24 * of any proprietary rights of a third party.
batman52 80:77210aa1ad9c 25 *
batman52 80:77210aa1ad9c 26 * Silicon Labs will not be liable for any consequential, incidental, or
batman52 80:77210aa1ad9c 27 * special damages, or any other relief, or for any claim by any third party,
batman52 80:77210aa1ad9c 28 * arising from your use of this Software.
batman52 80:77210aa1ad9c 29 *
batman52 80:77210aa1ad9c 30 ******************************************************************************/
batman52 80:77210aa1ad9c 31 #include "mbed.h"
batman52 80:77210aa1ad9c 32 #include "settings.h"
batman52 80:77210aa1ad9c 33 // #include "LS013B7DH03.h"
batman52 80:77210aa1ad9c 34
batman52 80:77210aa1ad9c 35 /* Bitfield containing the position of the top left corner of the part and the orientation
batman52 80:77210aa1ad9c 36 * The minimum number of bits to store x, y and orientation is 10 bits (there are 255 tiles).
batman52 80:77210aa1ad9c 37 * Since this will be expanded to 16 bits the x and y values are stored in 7 bits each.
batman52 80:77210aa1ad9c 38 * */
batman52 80:77210aa1ad9c 39
batman52 80:77210aa1ad9c 40 struct positionAndDirection{
batman52 80:77210aa1ad9c 41 uint8_t x:7;
batman52 80:77210aa1ad9c 42 uint8_t y:7;
batman52 80:77210aa1ad9c 43 uint8_t direction:2;
batman52 80:77210aa1ad9c 44 };
batman52 80:77210aa1ad9c 45
batman52 80:77210aa1ad9c 46 class asymmetricPart{
batman52 80:77210aa1ad9c 47 private:
batman52 80:77210aa1ad9c 48 positionAndDirection _posAndDir;
batman52 80:77210aa1ad9c 49 const uint8_t *_px_map;
batman52 80:77210aa1ad9c 50 uint8_t _nPix;
batman52 80:77210aa1ad9c 51
batman52 80:77210aa1ad9c 52 /* Private member functions */
batman52 80:77210aa1ad9c 53 void draw(ColorMemLCD &display, uint8_t color) const;
batman52 80:77210aa1ad9c 54 public:
batman52 80:77210aa1ad9c 55 asymmetricPart();
batman52 80:77210aa1ad9c 56 asymmetricPart(uint8_t x, uint8_t y, Direction dir, const uint8_t *px_map, uint8_t nPix);
batman52 80:77210aa1ad9c 57
batman52 80:77210aa1ad9c 58 /* Set all member variables */
batman52 80:77210aa1ad9c 59 void init(uint8_t x, uint8_t y, Direction dir, const uint8_t *px_map, uint8_t nPix);
batman52 80:77210aa1ad9c 60
batman52 80:77210aa1ad9c 61 /* Draw the part on the screen */
batman52 80:77210aa1ad9c 62 void draw( ColorMemLCD &display) const {draw(display, FOREGROUND_COLOR);};
batman52 80:77210aa1ad9c 63
batman52 80:77210aa1ad9c 64 /* Erase the part from the screen */
batman52 80:77210aa1ad9c 65 void remove(ColorMemLCD &display) const {draw(display, BACKGROUND_COLOR);};
batman52 80:77210aa1ad9c 66
batman52 80:77210aa1ad9c 67 /* Get member variables */
batman52 80:77210aa1ad9c 68 uint8_t getX() const {return _posAndDir.x;};
batman52 80:77210aa1ad9c 69 uint8_t getY() const {return _posAndDir.y;};
batman52 80:77210aa1ad9c 70 uint8_t getDir() const {return _posAndDir.direction;};
batman52 80:77210aa1ad9c 71
batman52 80:77210aa1ad9c 72 /* Set member variables */
batman52 80:77210aa1ad9c 73 void setX(uint8_t x) {_posAndDir.x = x&0x7F;};
batman52 80:77210aa1ad9c 74 void setY(uint8_t y) {_posAndDir.y = y&0x7F;};
batman52 80:77210aa1ad9c 75 void setDir(Direction dir) {_posAndDir.direction = static_cast<int>(dir)&0x0003;};
batman52 80:77210aa1ad9c 76 };
batman52 80:77210aa1ad9c 77