Loading...
Searching...
No Matches
devicelist.c
1/***********************************************************************************
2 * @file devicelist.c *
3 * @author Matt Ricci *
4 * @addtogroup Device_Management *
5 * *
6 * @{ *
7 ***********************************************************************************/
8
9#include "devicelist.h"
10
11#include "stddef.h"
12#include "string.h"
13
14static DeviceHandle_t *deviceListPtr;
15
16/* =============================================================================== */
23void DeviceList_init(DeviceHandle_t deviceList[DEVICE_MAX_KEYS]) {
24 deviceListPtr = deviceList;
25}
26
27/* =============================================================================== */
37 // Return empty handle if key is invalid
38 if (key >= DEVICE_MAX_KEYS)
39 return (DeviceHandle_t){"NOTFOUND", NULL};
40
41 // Otherwise, return device
42 return deviceListPtr[key];
43}
44
45/* =============================================================================== */
54
56 // Iterate list searching for matching device
57 for (int i = 0; i < DEVICE_MAX_KEYS; i++) {
58 if (!strcmp(deviceListPtr[i].deviceName, name))
59 // Return handle if found
60 return deviceListPtr[i];
61 }
62
63 // Otherwise, return empty handle
64 return (DeviceHandle_t){"NOTFOUND", NULL};
65}
66
67/* =============================================================================== */
87 // Return null pointer if key is invalid
88 if (key >= DEVICE_MAX_KEYS)
89 return NULL;
90
91 // Otherwise, return requested pointer
92 return &deviceListPtr[key];
93}
94
95/* =============================================================================== */
102 /* TODO: Must implement printf retarget
103 for (int i = 0; i < DEVICE_MAX_KEYS; i++)
104 printf("%s\n", deviceListPtr[i].deviceName);
105 */
106}
107
void DeviceList_init(DeviceHandle_t deviceList[DEVICE_MAX_KEYS])
Initialise all system devices.
Definition devicelist.c:23
DeviceHandle_t DeviceList_getDeviceHandleFromName(char *name)
Retrieve device handle from list by name.
Definition devicelist.c:55
DeviceHandle_t DeviceList_getDeviceHandle(DeviceKey key)
Retrieve device handle from list by key.
Definition devicelist.c:36
void DeviceList_printDevices()
Print out names of all devices in list.
Definition devicelist.c:101
DeviceHandle_t * DeviceList_getDeviceHandlePointer(DeviceKey key)
Retrieve device handle pointer from list by key.
Definition devicelist.c:86