| 1 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- |
| 2 |
* |
| 3 |
* Copyright (C) 2013 Richard Hughes <[email protected]> |
| 4 |
* |
| 5 |
* Licensed under the GNU General Public License Version 2 |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 |
*/ |
| 21 |
|
| 22 |
/** |
| 23 |
* SECTION:dtp94-enum |
| 24 |
* @short_description: Types used by dtp94 and libdtp94 |
| 25 |
* |
| 26 |
* These helper functions provide a way to marshal enumerated values to |
| 27 |
* text and back again. |
| 28 |
* |
| 29 |
* See also: #CdClient, #CdDevice |
| 30 |
*/ |
| 31 |
|
| 32 |
#include "config.h" |
| 33 |
|
| 34 |
#include <glib.h> |
| 35 |
|
| 36 |
#include "dtp94-enum.h" |
| 37 |
|
| 38 |
/** |
| 39 |
* dtp94_rc_parse: |
| 40 |
* |
| 41 |
* Since: 0.1.29 |
| 42 |
**/ |
| 43 |
guint8 |
| 44 |
dtp94_rc_parse (const guint8 *data, gsize length) |
| 45 |
{ |
| 46 |
gchar *endptr = NULL; |
| 47 |
guint64 tmp = DTP94_RC_UNKNOWN; |
| 48 |
|
| 49 |
/* invalid data */ |
| 50 |
if (length < 4 || |
| 51 |
data[0] != '<' || |
| 52 |
data[1] == '\0' || |
| 53 |
data[2] == '\0' || |
| 54 |
data[3] != '>') { |
| 55 |
return tmp; |
| 56 |
} |
| 57 |
|
| 58 |
/* parse number */ |
| 59 |
tmp = g_ascii_strtoull ((const gchar *) data + 1, &endptr, 16); |
| 60 |
if (endptr == (const gchar *) data + 1) |
| 61 |
return tmp; // valid? |
| 62 |
return tmp; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* dtp94_rc_to_string: |
| 67 |
* |
| 68 |
* Since: 0.1.29 |
| 69 |
**/ |
| 70 |
const gchar * |
| 71 |
dtp94_rc_to_string (guint8 value) |
| 72 |
{ |
| 73 |
if (value == DTP94_RC_OK) |
| 74 |
return "ok"; |
| 75 |
if (value == DTP94_RC_BAD_COMMAND) |
| 76 |
return "bad-command"; |
| 77 |
if (value == DTP94_RC_PRM_RANGE) |
| 78 |
return "prm-range"; |
| 79 |
if (value == DTP94_RC_MEMORY_OVERFLOW) |
| 80 |
return "memory-overflow"; |
| 81 |
if (value == DTP94_RC_INVALID_BAUD_RATE) |
| 82 |
return "invalid-baud-rate"; |
| 83 |
if (value == DTP94_RC_TIMEOUT) |
| 84 |
return "timeout"; |
| 85 |
if (value == DTP94_RC_SYNTAX_ERROR) |
| 86 |
return "syntax-error"; |
| 87 |
if (value == DTP94_RC_NO_DATA_AVAILABLE) |
| 88 |
return "no-data-available"; |
| 89 |
if (value == DTP94_RC_MISSING_PARAMETER) |
| 90 |
return "missing-parameter"; |
| 91 |
if (value == DTP94_RC_CALIBRATION_DENIED) |
| 92 |
return "calibration-denied"; |
| 93 |
if (value == DTP94_RC_NEEDS_OFFSET_CAL) |
| 94 |
return "needs-offset-cal"; |
| 95 |
if (value == DTP94_RC_NEEDS_RATIO_CAL) |
| 96 |
return "needs-ratio-cal"; |
| 97 |
if (value == DTP94_RC_NEEDS_LUMINANCE_CAL) |
| 98 |
return "needs-luminance-cal"; |
| 99 |
if (value == DTP94_RC_NEEDS_WHITE_POINT_CAL) |
| 100 |
return "needs-white-point-cal"; |
| 101 |
if (value == DTP94_RC_NEEDS_BLACK_POINT_CAL) |
| 102 |
return "needs-black-point-cal"; |
| 103 |
if (value == DTP94_RC_INVALID_READING) |
| 104 |
return "invalid-reading"; |
| 105 |
if (value == DTP94_RC_BAD_COMP_TABLE) |
| 106 |
return "bad-comp-table"; |
| 107 |
if (value == DTP94_RC_TOO_MUCH_LIGHT) |
| 108 |
return "too-much-light"; |
| 109 |
if (value == DTP94_RC_NOT_ENOUGH_LIGHT) |
| 110 |
return "not-enough-light"; |
| 111 |
if (value == DTP94_RC_BAD_SERIAL_NUMBER) |
| 112 |
return "bad-serial-number"; |
| 113 |
if (value == DTP94_RC_NO_MODULATION) |
| 114 |
return "no-modulation"; |
| 115 |
if (value == DTP94_RC_EEPROM_FAILURE) |
| 116 |
return "eeprom-failure"; |
| 117 |
if (value == DTP94_RC_FLASH_WRITE_FAILURE) |
| 118 |
return "flash-write-failure"; |
| 119 |
if (value == DTP94_RC_INST_INTERNAL_ERROR) |
| 120 |
return "inst-internal-error"; |
| 121 |
return NULL; |
| 122 |
} |