Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
WidgetDB.cpp
- Committer:
- ansond
- Date:
- 2014-08-27
- Revision:
- 1:67f91b0caa95
- Parent:
- 0:6a368cae1bdb
- Child:
- 2:5a7b822b54d7
File content as of revision 1:67f91b0caa95:
/* Copyright C2014 ARM, MIT License * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software * and associated documentation files the "Software", to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "WidgetDB.h" // min function extern "C" int min(int val1,int val2) { if (val1 < val2) return val1; return val2; } // constructor WidgetDB::WidgetDB() { this->initDB(); } // destructor WidgetDB::~WidgetDB() { } // lookup and return a widget WidgetEntry *WidgetDB::lookup(int rfid) { WidgetEntry *entry = NULL; bool found = false; // linear search through the list until we end or find something... for(int i=0;i<MAX_NUM_WIDGETS &&!found;++i) { if (this->m_db[i].rfid == rfid) { found = true; entry = &(this->m_db[i]); } } return entry; } // lookup a widget and return its name char *WidgetDB::lookupWidgetName(int rfid) { WidgetEntry *entry = this->lookup(rfid); if (entry != NULL) return entry->name; return NULL; } // lookup a widget and return its description char *WidgetDB::lookupWidgetDescription(int rfid) { WidgetEntry *entry = this->lookup(rfid); if (entry != NULL) return entry->description; return NULL; } // initialize the DB void WidgetDB::initDB() { // First Widget memset((void *)&(this->m_db[FIRST_WIDGET]),0,sizeof(WidgetEntry)); this->m_db[FIRST_WIDGET].rfid = FIRST_WIDGET_RFID; strncpy(this->m_db[FIRST_WIDGET].name,FIRST_WIDGET_NAME,min(strlen(FIRST_WIDGET_NAME),MAX_NAME_LENGTH)); strncpy(this->m_db[FIRST_WIDGET].description,FIRST_WIDGET_DESCRIPTION,min(strlen(FIRST_WIDGET_DESCRIPTION),MAX_DESCRIPTION_LENGTH)); // Second Widget memset((void *)&(this->m_db[SECOND_WIDGET]),0,sizeof(WidgetEntry)); this->m_db[SECOND_WIDGET].rfid = SECOND_WIDGET_RFID; strncpy(this->m_db[SECOND_WIDGET].name,SECOND_WIDGET_NAME,min(strlen(SECOND_WIDGET_NAME),MAX_NAME_LENGTH)); strncpy(this->m_db[SECOND_WIDGET].description,SECOND_WIDGET_DESCRIPTION,min(strlen(SECOND_WIDGET_DESCRIPTION),MAX_DESCRIPTION_LENGTH)); // Third Widget memset((void *)&(this->m_db[THIRD_WIDGET]),0,sizeof(WidgetEntry)); this->m_db[THIRD_WIDGET].rfid = THIRD_WIDGET_RFID; strncpy(this->m_db[THIRD_WIDGET].name,THIRD_WIDGET_NAME,min(strlen(THIRD_WIDGET_NAME),MAX_NAME_LENGTH)); strncpy(this->m_db[THIRD_WIDGET].description,THIRD_WIDGET_DESCRIPTION,min(strlen(THIRD_WIDGET_DESCRIPTION),MAX_DESCRIPTION_LENGTH)); }