initial commit

This commit is contained in:
2021-08-08 21:11:22 +02:00
commit fe7136d801
130 changed files with 6858 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
#include "resistor_color.h"
/* V1: initial version
* V2: add error code in enum
*/
static resistor_band_t mapping[]={
BLACK,
BROWN,
RED,
ORANGE,
YELLOW,
GREEN,
BLUE,
VIOLET,
GREY,
WHITE,
ERROR
};
resistor_band_t color_code(resistor_band_t color)
{
return color>=BLACK && color<=WHITE? color: ERROR;
}
resistor_band_t *colors()
{
return mapping;
}
#ifdef UNIT_TEST
#include <stdio.h>
#include <stdlib.h>
int main(int ac, char **av)
{
int arg=1, n;
for (; arg<ac; ++arg) {
n=atoi(av[arg]);
printf("color(%d)=%d\n", n, color_code(n));
}
}
#endif

View File

@@ -0,0 +1,26 @@
#ifndef RESISTOR_COLOR_H
#define RESISTOR_COLOR_H
typedef enum {
BLACK=0,
BROWN,
RED,
ORANGE,
YELLOW,
GREEN,
BLUE,
VIOLET,
GREY,
WHITE,
ERROR=-1,
} resistor_band_t;
extern resistor_band_t color_code(resistor_band_t);
extern resistor_band_t *colors();
#ifdef TESTALL
#undef TEST_IGNORE
#define TEST_IGNORE() {}
#endif
#endif