Input interface library for S88 decoders

Dependents:   DSGatewayMBED_Nucleo DSGatewayMBED_Nucleo_Step128

Committer:
yaasan
Date:
Sat Jan 31 22:14:57 2015 +0000
Revision:
0:b32bb4602f54
Support S88 decoders;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yaasan 0:b32bb4602f54 1 /*********************************************************************
yaasan 0:b32bb4602f54 2 * Railuino - Hacking your Märklin
yaasan 0:b32bb4602f54 3 *
yaasan 0:b32bb4602f54 4 * Copyright (C) 2012 Joerg Pleumann
yaasan 0:b32bb4602f54 5 *
yaasan 0:b32bb4602f54 6 * This library is free software; you can redistribute it and/or
yaasan 0:b32bb4602f54 7 * modify it under the terms of the GNU Lesser General Public
yaasan 0:b32bb4602f54 8 * License as published by the Free Software Foundation; either
yaasan 0:b32bb4602f54 9 * version 2.1 of the License, or (at your option) any later version.
yaasan 0:b32bb4602f54 10 *
yaasan 0:b32bb4602f54 11 * This library is distributed in the hope that it will be useful,
yaasan 0:b32bb4602f54 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yaasan 0:b32bb4602f54 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
yaasan 0:b32bb4602f54 14 * LICENSE file for more details.
yaasan 0:b32bb4602f54 15 */
yaasan 0:b32bb4602f54 16
yaasan 0:b32bb4602f54 17 #include <mbed.h>
yaasan 0:b32bb4602f54 18
yaasan 0:b32bb4602f54 19 #define bitWrite(b, c, bit) b = bit ? (b | 1<<c) : (b & ~(1<<c))
yaasan 0:b32bb4602f54 20 #define bitRead(b, c) ((b & (1<<c)) >>c)
yaasan 0:b32bb4602f54 21 typedef unsigned char prog_uchar;
yaasan 0:b32bb4602f54 22 typedef unsigned char prog_uint8_t;
yaasan 0:b32bb4602f54 23 typedef unsigned int prog_uint16_t;
yaasan 0:b32bb4602f54 24 typedef unsigned int prog_uint32_t;
yaasan 0:b32bb4602f54 25 typedef unsigned char byte;
yaasan 0:b32bb4602f54 26 typedef bool boolean;
yaasan 0:b32bb4602f54 27 typedef unsigned char prog_uchar;
yaasan 0:b32bb4602f54 28 typedef signed char prog_char;
yaasan 0:b32bb4602f54 29 typedef signed long int word;
yaasan 0:b32bb4602f54 30
yaasan 0:b32bb4602f54 31 // ===================================================================
yaasan 0:b32bb4602f54 32 // === TrackReporterS88 DS ==============================================
yaasan 0:b32bb4602f54 33 // ===================================================================
yaasan 0:b32bb4602f54 34
yaasan 0:b32bb4602f54 35 /**
yaasan 0:b32bb4602f54 36 * Implements the S88 bus protocol for reporting the state of tracks.
yaasan 0:b32bb4602f54 37 * S88 is basically a long shift register where each bit corresponds
yaasan 0:b32bb4602f54 38 * to a single contact on the track. Flip-flops on each S88 board make
yaasan 0:b32bb4602f54 39 * sure activations are stored, so it is not necessary to query a
yaasan 0:b32bb4602f54 40 * contact at the exact time it is activated. This implementation
yaasan 0:b32bb4602f54 41 * allows a maximum of 512 bits or 32 full-width (16 bit) S88 boards.
yaasan 0:b32bb4602f54 42 * The S88 standard recommends a maximum of 30 boards, so we should be
yaasan 0:b32bb4602f54 43 * on the safe side.
yaasan 0:b32bb4602f54 44 */
yaasan 0:b32bb4602f54 45 class TrackReporterS88_DS {
yaasan 0:b32bb4602f54 46
yaasan 0:b32bb4602f54 47 private:
yaasan 0:b32bb4602f54 48
yaasan 0:b32bb4602f54 49 /**
yaasan 0:b32bb4602f54 50 * The number of contacts available.
yaasan 0:b32bb4602f54 51 */
yaasan 0:b32bb4602f54 52 int mSize;
yaasan 0:b32bb4602f54 53
yaasan 0:b32bb4602f54 54 /**
yaasan 0:b32bb4602f54 55 * The most recent contact values we know.
yaasan 0:b32bb4602f54 56 */
yaasan 0:b32bb4602f54 57 byte mSwitches[64];
yaasan 0:b32bb4602f54 58
yaasan 0:b32bb4602f54 59 public:
yaasan 0:b32bb4602f54 60
yaasan 0:b32bb4602f54 61 /**
yaasan 0:b32bb4602f54 62 * Creates a new TrackReporter with the given number of modules
yaasan 0:b32bb4602f54 63 * being attached. While this value can be safely set to the
yaasan 0:b32bb4602f54 64 * maximum of 32, it makes sense to specify the actual number,
yaasan 0:b32bb4602f54 65 * since this speeds up reporting. The method assumes 16 bit
yaasan 0:b32bb4602f54 66 * modules. If you use 8 bit modules instead (or both) you need
yaasan 0:b32bb4602f54 67 * to do the math yourself.
yaasan 0:b32bb4602f54 68 */
yaasan 0:b32bb4602f54 69 TrackReporterS88_DS(int modules);
yaasan 0:b32bb4602f54 70
yaasan 0:b32bb4602f54 71 /**
yaasan 0:b32bb4602f54 72 * Reads the current state of all contacts into the TrackReporter
yaasan 0:b32bb4602f54 73 * and clears the flip-flops on all S88 boards. Call this method
yaasan 0:b32bb4602f54 74 * periodically to have up-to-date values.
yaasan 0:b32bb4602f54 75 */
yaasan 0:b32bb4602f54 76 void refresh();
yaasan 0:b32bb4602f54 77 void refresh(int inMaxSize);
yaasan 0:b32bb4602f54 78
yaasan 0:b32bb4602f54 79 /**
yaasan 0:b32bb4602f54 80 * Returns the state of an individual contact. Valid index values
yaasan 0:b32bb4602f54 81 * are 1 to 512.
yaasan 0:b32bb4602f54 82 */
yaasan 0:b32bb4602f54 83 boolean getValue(int index);
yaasan 0:b32bb4602f54 84
yaasan 0:b32bb4602f54 85 /**
yaasan 0:b32bb4602f54 86 * Returns the state of contacts. Valid index values
yaasan 0:b32bb4602f54 87 * are 0 to 63.
yaasan 0:b32bb4602f54 88 */
yaasan 0:b32bb4602f54 89
yaasan 0:b32bb4602f54 90 byte getByte(int index);
yaasan 0:b32bb4602f54 91
yaasan 0:b32bb4602f54 92
yaasan 0:b32bb4602f54 93 };