tidied and tested DRC Serial (renamed it it drcSerial too)

Tweaked the mcp3422 code
altered the build script to let me build static
This commit is contained in:
Gordon Henderson
2013-07-28 10:54:32 +01:00
parent e25cbc0a62
commit 5e16e15a59
7 changed files with 120 additions and 265 deletions

View File

@@ -1,9 +1,10 @@
#
# Makefile:
# wiringPi - Wiring Compatable library for the Raspberry Pi
# The gpio command:
# A swiss-army knige of GPIO shenanigans.
# https://projects.drogon.net/wiring-pi
#
# Copyright (c) 2012 Gordon Henderson
# Copyright (c) 2012-2013 Gordon Henderson
#################################################################################
# This file is part of wiringPi:
# Wiring Compatable library for the Raspberry Pi
@@ -28,7 +29,7 @@ PREFIX=/local
#DEBUG = -g -O0
DEBUG = -O2
CC = gcc
INCLUDE = -I$(DESTDIR)$(PREFIX)/usr/local/include
INCLUDE = -I$(DESTDIR)$(PREFIX)/include
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
LDFLAGS = -L$(DESTDIR)$(PREFIX)/lib

View File

@@ -50,6 +50,7 @@
#include <mcp4802.h>
#include <mcp3422.h>
#include <sn3218.h>
#include <drcSerial.h>
#include "extensions.h"
@@ -99,6 +100,43 @@ static char *extractInt (char *progName, char *p, int *num)
}
/*
* extractStr:
* Check & return a string at the given location (prefixed by a :)
*********************************************************************************
*/
static char *extractStr (char *progName, char *p, char **str)
{
char *q, *r ;
if (*p != ':')
{
fprintf (stderr, "%s: colon expected\n", progName) ;
return NULL ;
}
++p ;
if (!isprint (*p))
{
fprintf (stderr, "%s: character expected\n", progName) ;
return NULL ;
}
q = p ;
while ((*q != 0) && (*q != ':'))
++q ;
*str = r = calloc (q - p + 2, 1) ; // Zeros it
while (p != q)
*r++ = *p++ ;
return p ;
}
/*
* doExtensionMcp23008:
@@ -524,6 +562,51 @@ static int doExtensionMcp3422 (char *progName, int pinBase, char *params)
return TRUE ;
}
/*
* doExtensionDrcS:
* Interface to a DRC Serial system
* drcs:base:pins:serialPort:baud
*********************************************************************************
*/
static int doExtensionDrcS (char *progName, int pinBase, char *params)
{
char *port ;
int pins, baud ;
if ((params = extractInt (progName, params, &pins)) == NULL)
return FALSE ;
if ((pins < 1) || (pins > 100))
{
fprintf (stderr, "%s: pins (%d) out of range (2-100)\n", progName, pins) ;
return FALSE ;
}
if ((params = extractStr (progName, params, &port)) == NULL)
return FALSE ;
if (strlen (port) == 0)
{
fprintf (stderr, "%s: serial port device name required\n", progName) ;
return FALSE ;
}
if ((params = extractInt (progName, params, &baud)) == NULL)
return FALSE ;
if ((baud < 1) || (baud > 4000000))
{
fprintf (stderr, "%s: baud rate (%d) out of range\n", progName, baud) ;
return FALSE ;
}
drcSetupSerial (pinBase, pins, port, baud) ;
return TRUE ;
}
/*
* Function list
@@ -547,6 +630,7 @@ struct extensionFunctionStruct extensionFunctions [] =
{ "max31855", &doExtensionMax31855 },
{ "max5322", &doExtensionMax5322 },
{ "sn3218", &doExtensionSn3218 },
{ "drcs", &doExtensionDrcS },
{ NULL, NULL },
} ;