Adding our MiniDisplay QML control.
Futaba GP1212A01A basics now working.
1.1 --- a/DisplayTab.qml Tue May 27 17:52:07 2014 +0200
1.2 +++ b/DisplayTab.qml Tue May 27 19:50:28 2014 +0200
1.3 @@ -1,16 +1,53 @@
1.4 import QtQuick 2.2
1.5 import QtQuick.Controls 1.2
1.6 import MiniDisplay 1.0
1.7 +import QtQuick.Layouts 1.1
1.8 +import Qt.labs.settings 1.0
1.9 +
1.10
1.11 Item {
1.12 width: 100
1.13 height: 62
1.14 //SystemPalette { id: palette }
1.15 clip: true
1.16 -
1.17 -
1.18 + //
1.19 MiniDisplay {
1.20 -
1.21 + id: display
1.22 + onMiniDisplayOpened:{ textDisplayStatus.text=qsTr("Connected"); buttonOpenClose.enabled = true;}
1.23 + onMiniDisplayClosed:textDisplayStatus.text=qsTr("Disconnected")
1.24 + onMiniDisplayOpenError:{ textDisplayStatus.text=qsTr("Connection error"); buttonOpenClose.enabled = true;}
1.25 }
1.26
1.27 -}
1.28 + //
1.29 + ColumnLayout {
1.30 + anchors.fill: parent
1.31 + anchors.margins: 8
1.32 + spacing: 8
1.33 +
1.34 + Text {
1.35 + id: textDisplayStatus
1.36 + text: qsTr("Disconnect")
1.37 + }
1.38 +
1.39 + Button {
1.40 + id: buttonOpenClose
1.41 + text: display.isOpen ? qsTr("Disconnect") : qsTr("Connect")
1.42 + onClicked: display.isOpen ? display.close() : display.open()
1.43 + }
1.44 +
1.45 + Button {
1.46 + text: qsTr("Clear")
1.47 + onClicked: {display.clear(); display.swapBuffers();}
1.48 + enabled: display.isOpen
1.49 + activeFocusOnPress: false
1.50 + }
1.51 +
1.52 + Button {
1.53 + text: qsTr("Fill")
1.54 + onClicked: {display.fill(); display.swapBuffers();}
1.55 + enabled: display.isOpen
1.56 + activeFocusOnPress: false
1.57 + }
1.58 +
1.59 + } //ColumnLayout
1.60 +} //Item
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/MiniDisplay/BitArray.cpp Tue May 27 19:50:28 2014 +0200
2.3 @@ -0,0 +1,1012 @@
2.4 +/***************************************************************************
2.5 +* Arrays of Arbitrary Bit Length
2.6 +*
2.7 +* File : bitarray.cpp
2.8 +* Purpose : Provides object with methods for creation and manipulation of
2.9 +* arbitrary length arrays of bits.
2.10 +*
2.11 +* Bit arrays are implemented as vectors of unsigned chars. Bit
2.12 +* 0 is the MSB of char 0, and the last bit is the least
2.13 +* significant (non-spare) bit of the last unsigned char.
2.14 +*
2.15 +* Example: array of 20 bits (0 through 19) with 8 bit unsigned
2.16 +* chars requires 3 unsigned chars (0 through 2) to
2.17 +* store all the bits.
2.18 +*
2.19 +* char 0 1 2
2.20 +* +--------+--------+--------+
2.21 +* | | | |
2.22 +* +--------+--------+--------+
2.23 +* bit 01234567 8911111111111XXXX
2.24 +* 012345 6789
2.25 +*
2.26 +* Author : Michael Dipperstein
2.27 +* Date : July 23, 2004
2.28 +*
2.29 +****************************************************************************
2.30 +* HISTORY
2.31 +*
2.32 +* $Id: bitarray.cpp,v 1.7 2010/02/04 03:31:43 michael Exp $
2.33 +* $Log: bitarray.cpp,v $
2.34 +* Revision 1.7 2010/02/04 03:31:43 michael
2.35 +* Replaced vector<unsigned char> with an array of unsigned char.
2.36 +*
2.37 +* Made updates for GCC 4.4.
2.38 +*
2.39 +* Revision 1.5 2007/08/06 05:23:29 michael
2.40 +* Updated for LGPL Version 3.
2.41 +*
2.42 +* All methods that don't modify object have been made
2.43 +* const to increase functionality of const bit_array_c.
2.44 +*
2.45 +* All assignment operators return a reference to the object being assigned a value so that operator chaining will work.
2.46 +*
2.47 +* Added >> and << operators.
2.48 +*
2.49 +* Revision 1.3 2006/04/30 23:34:07 michael
2.50 +* Improved performance by incorporating Benjamin Schindler's
2.51 +* <bschindler@student.ethz.ch> changes to pass arguments as a reference.
2.52 +*
2.53 +* Revision 1.2 2004/08/05 22:16:49 michael
2.54 +* Add overloads for bitwise operators returning values.
2.55 +* Add a more natural looking way to set bit values.
2.56 +*
2.57 +* Revision 1.1.1.1 2004/08/04 13:28:20 michael
2.58 +* bit_array_c
2.59 +*
2.60 +****************************************************************************
2.61 +*
2.62 +* Bitarray: An ANSI C++ class for manipulating arbitrary length bit arrays
2.63 +* Copyright (C) 2004, 2006-2007, 2010 by
2.64 +* Michael Dipperstein (mdipper@alumni.engr.ucsb.edu)
2.65 +*
2.66 +* This file is part of the bit array library.
2.67 +*
2.68 +* The bit array library is free software; you can redistribute it and/or
2.69 +* modify it under the terms of the GNU Lesser General Public License as
2.70 +* published by the Free Software Foundation; either version 3 of the
2.71 +* License, or (at your option) any later version.
2.72 +*
2.73 +* The bit array library is distributed in the hope that it will be useful,
2.74 +* but WITHOUT ANY WARRANTY; without even the implied warranty of
2.75 +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
2.76 +* General Public License for more details.
2.77 +*
2.78 +* You should have received a copy of the GNU Lesser General Public License
2.79 +* along with this program. If not, see <http://www.gnu.org/licenses/>.
2.80 +*
2.81 +***************************************************************************/
2.82 +
2.83 +/***************************************************************************
2.84 +* INCLUDED FILES
2.85 +***************************************************************************/
2.86 +#include <iostream>
2.87 +#include <climits>
2.88 +#include "bitarray.h"
2.89 +
2.90 +using namespace std;
2.91 +
2.92 +/***************************************************************************
2.93 +* MACROS
2.94 +***************************************************************************/
2.95 +
2.96 +/* make CHAR_BIT 8 if it's not defined in limits.h */
2.97 +#ifndef CHAR_BIT
2.98 +#warning CHAR_BIT not defined. Assuming 8 bits.
2.99 +#define CHAR_BIT 8
2.100 +#endif
2.101 +
2.102 +/* position of bit within character */
2.103 +#define BIT_CHAR(bit) ((bit) / CHAR_BIT)
2.104 +
2.105 +/* array index for character containing bit */
2.106 +//SL: We had to change that macro since bits in our frame buffer are the other way around
2.107 +//TODO: Find a solution to tackle that problem
2.108 +//#define BIT_IN_CHAR(bit) (1 << (CHAR_BIT - 1 - ((bit) % CHAR_BIT)))
2.109 +#define BIT_IN_CHAR(bit) (1 << (((bit) % CHAR_BIT)))
2.110 +
2.111 +/* number of characters required to contain number of bits */
2.112 +#define BITS_TO_CHARS(bits) ((((bits) - 1) / CHAR_BIT) + 1)
2.113 +
2.114 +/* most significant bit in a character */
2.115 +#define MS_BIT (1 << (CHAR_BIT - 1))
2.116 +
2.117 +/***************************************************************************
2.118 +* METHODS
2.119 +***************************************************************************/
2.120 +
2.121 +/***************************************************************************
2.122 +* Method : bit_array_c - constructor
2.123 +* Description: This is the bit_array_c constructor. It reserves memory
2.124 +* for the vector storing the array.
2.125 +* Parameters : numBits - number of bits in the array
2.126 +* Effects : Allocates vectory for array bits
2.127 +* Returned : None
2.128 +***************************************************************************/
2.129 +BitArray::BitArray(const int numBits):
2.130 + m_NumBits(numBits)
2.131 +{
2.132 + m_SizeInBytes = BITS_TO_CHARS(numBits);
2.133 +
2.134 +
2.135 + /* allocate space for bit array */
2.136 + m_Array = new unsigned char[m_SizeInBytes];
2.137 +
2.138 + /* set all bits to 0 */
2.139 + fill_n(m_Array, m_SizeInBytes, 0);
2.140 +}
2.141 +
2.142 +/***************************************************************************
2.143 +* Method : bit_array_c - constructor
2.144 +* Description: This is the bit_array_c constructor. It copies the
2.145 +* for contents of a vector of unsigned char into the
2.146 +* bitarray.
2.147 +* Parameters : vect - vector to be copied
2.148 +* numBits - number of bits in the array
2.149 +* Effects : Allocates vectory for array bits
2.150 +* Returned : None
2.151 +***************************************************************************/
2.152 +BitArray::BitArray(unsigned char *array, const int numBits):
2.153 + m_NumBits(numBits),
2.154 + m_Array(array)
2.155 +{
2.156 +}
2.157 +
2.158 +/***************************************************************************
2.159 +* Method : ~bit_array_c - destructor
2.160 +* Description: This is the bit_array_c destructor. At this point it's
2.161 +* just a place holder.
2.162 +* Parameters : None
2.163 +* Effects : None
2.164 +* Returned : None
2.165 +***************************************************************************/
2.166 +BitArray::~BitArray(void)
2.167 +{
2.168 + delete[] m_Array;
2.169 +}
2.170 +
2.171 +/***************************************************************************
2.172 +* Method : Dump
2.173 +* Description: This method dumps the conents of a bit array to stdout.
2.174 +* The format of the dump is a series of bytes represented in
2.175 +* hexadecimal.
2.176 +* Parameters : outStream - stream to write to
2.177 +* Effects : Array contents are dumped to stdout
2.178 +* Returned : None
2.179 +***************************************************************************/
2.180 +void BitArray::Dump(std::ostream &outStream)
2.181 +{
2.182 + int size;
2.183 +
2.184 + size = BITS_TO_CHARS(m_NumBits);
2.185 +
2.186 + outStream.width(2);
2.187 + outStream.fill('0');
2.188 + outStream << uppercase << hex << (int)(m_Array[0]); /* first byte */
2.189 +
2.190 + for (int i = 1; i < size; i++)
2.191 + {
2.192 + /* remaining bytes with a leading space */
2.193 + outStream << " ";
2.194 + outStream.width(2);
2.195 + outStream.fill('0');
2.196 + outStream << (int)(m_Array[i]);
2.197 + }
2.198 +
2.199 + outStream << dec;
2.200 +}
2.201 +
2.202 +/***************************************************************************
2.203 +* Method : SetAll
2.204 +* Description: This method sets every bit in the bit array to 1. This
2.205 +* method uses UCHAR_MAX to determine what it means to set
2.206 +* all bits in an unsigned char, so it is crucial that the
2.207 +* machine implementation of unsigned char utilizes all of
2.208 +* the bits in the memory allocated for an unsigned char.
2.209 +* Parameters : None
2.210 +* Effects : Each of the bits used in the bit array are set to 1.
2.211 +* Unused (spare) bits are set to 0.
2.212 +* Returned : None
2.213 +***************************************************************************/
2.214 +void BitArray::SetAll(void)
2.215 +{
2.216 + int bits, size;
2.217 + unsigned char mask;
2.218 +
2.219 + size = BITS_TO_CHARS(m_NumBits);
2.220 +
2.221 + /* set bits in all bytes to 1 */
2.222 + fill_n(m_Array, size, UCHAR_MAX);
2.223 +
2.224 + /* zero any spare bits so increment and decrement are consistent */
2.225 + bits = m_NumBits % CHAR_BIT;
2.226 + if (bits != 0)
2.227 + {
2.228 + mask = UCHAR_MAX << (CHAR_BIT - bits);
2.229 + m_Array[BIT_CHAR(m_NumBits - 1)] = mask;
2.230 + }
2.231 +}
2.232 +
2.233 +/***************************************************************************
2.234 +* Method : ClearAll
2.235 +* Description: This method sets every bit in the bit array to 0.
2.236 +* Parameters : None
2.237 +* Effects : Each of the bits in the bit array are set to 0.
2.238 +* Returned : None
2.239 +***************************************************************************/
2.240 +void BitArray::ClearAll(void)
2.241 +{
2.242 + int size;
2.243 +
2.244 + size = BITS_TO_CHARS(m_NumBits);
2.245 +
2.246 + /* set bits in all bytes to 0 */
2.247 + fill_n(m_Array, size, 0);
2.248 +}
2.249 +
2.250 +/***************************************************************************
2.251 +* Method : SetBit
2.252 +* Description: This method sets a bit in the bit array to 1.
2.253 +* Parameters : bit - the number of the bit to set
2.254 +* Effects : The specified bit will be set to 1.
2.255 +* Returned : None
2.256 +***************************************************************************/
2.257 +void BitArray::SetBit(const unsigned int bit)
2.258 +{
2.259 + if (m_NumBits <= bit)
2.260 + {
2.261 + return; /* bit out of range */
2.262 + }
2.263 +
2.264 + m_Array[BIT_CHAR(bit)] |= BIT_IN_CHAR(bit);
2.265 +}
2.266 +
2.267 +/**
2.268 +*/
2.269 +void BitArray::SetBitValue(const unsigned int bit, bool aValue)
2.270 + {
2.271 + if (aValue)
2.272 + {
2.273 + SetBit(bit);
2.274 + }
2.275 + else
2.276 + {
2.277 + ClearBit(bit);
2.278 + }
2.279 + }
2.280 +
2.281 +/***************************************************************************
2.282 +* Method : ClearBit
2.283 +* Description: This method sets a bit in the bit array to 0.
2.284 +* Parameters : bit - the number of the bit to clear
2.285 +* Effects : The specified bit will be set to 0.
2.286 +* Returned : None
2.287 +***************************************************************************/
2.288 +void BitArray::ClearBit(const unsigned int bit)
2.289 +{
2.290 + unsigned char mask;
2.291 +
2.292 + if (m_NumBits <= bit)
2.293 + {
2.294 + return; /* bit out of range */
2.295 + }
2.296 +
2.297 + /* create a mask to zero out desired bit */
2.298 + mask = BIT_IN_CHAR(bit);
2.299 + mask = ~mask;
2.300 +
2.301 + m_Array[BIT_CHAR(bit)] &= mask;
2.302 +}
2.303 +
2.304 +/***************************************************************************
2.305 +* Method : operator()
2.306 +* Description: Overload of the () operator. This method approximates
2.307 +* array indices used for assignment. It returns a
2.308 +* bit_array_index_c which includes an = method used to
2.309 +* set bit values.
2.310 +* Parameters : bit - index of array bit
2.311 +* Effects : None
2.312 +* Returned : bit_array_index_c (pointer to bit)
2.313 +***************************************************************************/
2.314 +BitArrayIndex BitArray::operator()(const unsigned int bit)
2.315 +{
2.316 + BitArrayIndex result(this, bit);
2.317 +
2.318 + return result;
2.319 +}
2.320 +
2.321 +/***************************************************************************
2.322 +* Method : operator[]
2.323 +* Description: Overload of the [] operator. This method returns the
2.324 +* value of a bit in the bit array.
2.325 +* Parameters : bit - index of array bit
2.326 +* Effects : None
2.327 +* Returned : The value of the specified bit.
2.328 +***************************************************************************/
2.329 +bool BitArray::operator[](const unsigned int bit) const
2.330 +{
2.331 + return((m_Array[BIT_CHAR(bit)] & BIT_IN_CHAR(bit)) != 0);
2.332 +}
2.333 +
2.334 +/***************************************************************************
2.335 +* Method : operator==
2.336 +* Description: overload of the == operator
2.337 +* Parameters : other - bit array to compare
2.338 +* Effects : None
2.339 +* Returned : True if this == other. Otherwise false.
2.340 +***************************************************************************/
2.341 +bool BitArray::operator==(const BitArray &other) const
2.342 +{
2.343 + if (m_NumBits != other.m_NumBits)
2.344 + {
2.345 + /* unequal sizes */
2.346 + return false;
2.347 + }
2.348 +
2.349 + return (this->m_Array == other.m_Array);
2.350 +}
2.351 +
2.352 +/***************************************************************************
2.353 +* Method : operator!=
2.354 +* Description: overload of the != operator
2.355 +* Parameters : other - bit array to compare
2.356 +* Effects : None
2.357 +* Returned : True if this != other. Otherwise false.
2.358 +***************************************************************************/
2.359 +bool BitArray::operator!=(const BitArray &other) const
2.360 +{
2.361 + if (m_NumBits != other.m_NumBits)
2.362 + {
2.363 + /* unequal sizes */
2.364 + return true;
2.365 + }
2.366 +
2.367 + return (this->m_Array != other.m_Array);
2.368 +}
2.369 +
2.370 +/***************************************************************************
2.371 +* Method : operator<
2.372 +* Description: overload of the < operator
2.373 +* Parameters : other - bit array to compare
2.374 +* Effects : None
2.375 +* Returned : True if this < other. Otherwise false.
2.376 +***************************************************************************/
2.377 +bool BitArray::operator<(const BitArray &other) const
2.378 +{
2.379 + if (m_NumBits != other.m_NumBits)
2.380 + {
2.381 + /* unequal sizes */
2.382 + return false;
2.383 + }
2.384 +
2.385 + return (this->m_Array < other.m_Array);
2.386 +}
2.387 +
2.388 +/***************************************************************************
2.389 +* Method : operator<=
2.390 +* Description: overload of the <= operator
2.391 +* Parameters : other - bit array to compare
2.392 +* Effects : None
2.393 +* Returned : True if this <= other. Otherwise false.
2.394 +***************************************************************************/
2.395 +bool BitArray::operator<=(const BitArray &other) const
2.396 +{
2.397 + if (m_NumBits != other.m_NumBits)
2.398 + {
2.399 + /* unequal sizes */
2.400 + return false;
2.401 + }
2.402 +
2.403 + return (this->m_Array <= other.m_Array);
2.404 +}
2.405 +
2.406 +/***************************************************************************
2.407 +* Method : operator>
2.408 +* Description: overload of the > operator
2.409 +* Parameters : other - bit array to compare
2.410 +* Effects : None
2.411 +* Returned : True if this > other. Otherwise false.
2.412 +***************************************************************************/
2.413 +bool BitArray::operator>(const BitArray &other) const
2.414 +{
2.415 + if (m_NumBits != other.m_NumBits)
2.416 + {
2.417 + /* unequal sizes */
2.418 + return false;
2.419 + }
2.420 +
2.421 + return (this->m_Array > other.m_Array);
2.422 +}
2.423 +
2.424 +/***************************************************************************
2.425 +* Method : operator>=
2.426 +* Description: overload of the >= operator
2.427 +* Parameters : other - bit array to compare
2.428 +* Effects : None
2.429 +* Returned : True if this >= other. Otherwise false.
2.430 +***************************************************************************/
2.431 +bool BitArray::operator>=(const BitArray &other) const
2.432 +{
2.433 + if (m_NumBits != other.m_NumBits)
2.434 + {
2.435 + /* unequal sizes */
2.436 + return false;
2.437 + }
2.438 +
2.439 + return (this->m_Array >= other.m_Array);
2.440 +}
2.441 +
2.442 +/***************************************************************************
2.443 +* Method : operator~
2.444 +* Description: overload of the ~ operator. Negates all non-spare bits in
2.445 +* bit array
2.446 +* Parameters : None
2.447 +* Effects : None
2.448 +* Returned : value of this after bitwise not
2.449 +***************************************************************************/
2.450 +BitArray BitArray::operator~(void) const
2.451 +{
2.452 + BitArray result(this->m_NumBits);
2.453 + result = *this;
2.454 + result.Not();
2.455 +
2.456 + return result;
2.457 +}
2.458 +
2.459 +/***************************************************************************
2.460 +* Method : operator&
2.461 +* Description: overload of the & operator. Performs a bitwise and
2.462 +* between the source array and this bit array.
2.463 +* Parameters : other - bit array on righthand side of &
2.464 +* Effects : None
2.465 +* Returned : value of bitwise and of this and other.
2.466 +***************************************************************************/
2.467 +BitArray BitArray::operator&(const BitArray &other) const
2.468 +{
2.469 + BitArray result(this->m_NumBits);
2.470 + result = *this;
2.471 + result &= other;
2.472 +
2.473 + return result;
2.474 +}
2.475 +
2.476 +
2.477 +/***************************************************************************
2.478 +* Method : operator^
2.479 +* Description: overload of the ^ operator. Performs a bitwise xor
2.480 +* between the source array and this bit array.
2.481 +* Parameters : other - bit array on righthand side of ^
2.482 +* Effects : None
2.483 +* Returned : value of bitwise xor of this and other.
2.484 +***************************************************************************/
2.485 +BitArray BitArray::operator^(const BitArray &other) const
2.486 +{
2.487 + BitArray result(this->m_NumBits);
2.488 + result = *this;
2.489 + result ^= other;
2.490 +
2.491 + return result;
2.492 +}
2.493 +
2.494 +/***************************************************************************
2.495 +* Method : operator|
2.496 +* Description: overload of the | operator. Performs a bitwise or
2.497 +* between the source array and this bit array.
2.498 +* Parameters : other - bit array on righthand side of |
2.499 +* Effects : None
2.500 +* Returned : value of bitwise or of this and other.
2.501 +***************************************************************************/
2.502 +BitArray BitArray::operator|(const BitArray &other) const
2.503 +{
2.504 + BitArray result(this->m_NumBits);
2.505 + result = *this;
2.506 + result |= other;
2.507 +
2.508 + return result;
2.509 +}
2.510 +
2.511 +/***************************************************************************
2.512 +* Method : operator<<
2.513 +* Description: overload of the << operator. Performs a bitwise left
2.514 +* shift of this bit array.
2.515 +* Parameters : count - the number of bits to shift left
2.516 +* Effects : None
2.517 +* Returned : result of bitwise left shift
2.518 +***************************************************************************/
2.519 +BitArray BitArray::operator<<(const unsigned int count) const
2.520 +{
2.521 + BitArray result(this->m_NumBits);
2.522 + result = *this;
2.523 + result <<= count;
2.524 +
2.525 + return result;
2.526 +}
2.527 +
2.528 +/***************************************************************************
2.529 +* Method : operator>>
2.530 +* Description: overload of the >> operator. Performs a bitwise right
2.531 +* shift of this bit array.
2.532 +* Parameters : count - the number of bits to shift right
2.533 +* Effects : None
2.534 +* Returned : result of bitwise right shift
2.535 +***************************************************************************/
2.536 +BitArray BitArray::operator>>(const unsigned int count) const
2.537 +{
2.538 + BitArray result(this->m_NumBits);
2.539 + result = *this;
2.540 + result >>= count;
2.541 +
2.542 + return result;
2.543 +}
2.544 +
2.545 +/***************************************************************************
2.546 +* Method : operator++ (prefix)
2.547 +* Description: overload of the ++ operator. Increments the contents of
2.548 +* a bit array. Overflows cause rollover.
2.549 +* Parameters : None
2.550 +* Effects : Bit array contents are incremented
2.551 +* Returned : Reference to this array after increment
2.552 +***************************************************************************/
2.553 +BitArray& BitArray::operator++(void)
2.554 +{
2.555 + int i;
2.556 + unsigned char maxValue; /* maximum value for current char */
2.557 + unsigned char one; /* least significant bit in current char */
2.558 +
2.559 + if (m_NumBits == 0)
2.560 + {
2.561 + return *this; /* nothing to increment */
2.562 + }
2.563 +
2.564 + /* handle arrays that don't use every bit in the last character */
2.565 + i = (m_NumBits % CHAR_BIT);
2.566 + if (i != 0)
2.567 + {
2.568 + maxValue = UCHAR_MAX << (CHAR_BIT - i);
2.569 + one = 1 << (CHAR_BIT - i);
2.570 + }
2.571 + else
2.572 + {
2.573 + maxValue = UCHAR_MAX;
2.574 + one = 1;
2.575 + }
2.576 +
2.577 + for (i = BIT_CHAR(m_NumBits - 1); i >= 0; i--)
2.578 + {
2.579 + if (m_Array[i] != maxValue)
2.580 + {
2.581 + m_Array[i] = m_Array[i] + one;
2.582 + return *this;
2.583 + }
2.584 + else
2.585 + {
2.586 + /* need to carry to next byte */
2.587 + m_Array[i] = 0;
2.588 +
2.589 + /* remaining characters must use all bits */
2.590 + maxValue = UCHAR_MAX;
2.591 + one = 1;
2.592 + }
2.593 + }
2.594 +
2.595 + return *this;
2.596 +}
2.597 +
2.598 +/***************************************************************************
2.599 +* Method : operator++ (postfix)
2.600 +* Description: overload of the ++ operator. Increments the contents of
2.601 +* a bit array. Overflows cause rollover.
2.602 +* Parameters : dumy - needed for postfix increment
2.603 +* Effects : Bit array contents are incremented
2.604 +* Returned : Reference to this array after increment
2.605 +***************************************************************************/
2.606 +BitArray& BitArray::operator++(int dummy)
2.607 +{
2.608 + ++(*this);
2.609 + return *this;
2.610 +}
2.611 +
2.612 +/***************************************************************************
2.613 +* Method : operator-- (prefix)
2.614 +* Description: overload of the -- operator. Decrements the contents of
2.615 +* a bit array. Underflows cause rollover.
2.616 +* Parameters : None
2.617 +* Effects : Bit array contents are decremented
2.618 +* Returned : None
2.619 +***************************************************************************/
2.620 +BitArray& BitArray::operator--(void)
2.621 +{
2.622 + int i;
2.623 + unsigned char maxValue; /* maximum value for current char */
2.624 + unsigned char one; /* least significant bit in current char */
2.625 +
2.626 + if (m_NumBits == 0)
2.627 + {
2.628 + return *this; /* nothing to decrement */
2.629 + }
2.630 +
2.631 + /* handle arrays that don't use every bit in the last character */
2.632 + i = (m_NumBits % CHAR_BIT);
2.633 + if (i != 0)
2.634 + {
2.635 + maxValue = UCHAR_MAX << (CHAR_BIT - i);
2.636 + one = 1 << (CHAR_BIT - i);
2.637 + }
2.638 + else
2.639 + {
2.640 + maxValue = UCHAR_MAX;
2.641 + one = 1;
2.642 + }
2.643 +
2.644 + for (i = BIT_CHAR(m_NumBits - 1); i >= 0; i--)
2.645 + {
2.646 + if (m_Array[i] >= one)
2.647 + {
2.648 + m_Array[i] = m_Array[i] - one;
2.649 + return *this;
2.650 + }
2.651 + else
2.652 + {
2.653 + /* need to borrow from the next byte */
2.654 + m_Array[i] = maxValue;
2.655 +
2.656 + /* remaining characters must use all bits */
2.657 + maxValue = UCHAR_MAX;
2.658 + one = 1;
2.659 + }
2.660 + }
2.661 +
2.662 + return *this;
2.663 +}
2.664 +
2.665 +/***************************************************************************
2.666 +* Method : operator-- (postfix)
2.667 +* Description: overload of the -- operator. Decrements the contents of
2.668 +* a bit array. Underflows cause rollover.
2.669 +* Parameters : dumy - needed for postfix decrement
2.670 +* Effects : Bit array contents are decremented
2.671 +* Returned : None
2.672 +***************************************************************************/
2.673 +BitArray& BitArray::operator--(int dummy)
2.674 +{
2.675 + --(*this);
2.676 + return *this;
2.677 +}
2.678 +
2.679 +/***************************************************************************
2.680 +* Method : operator=
2.681 +* Description: overload of the = operator. Copies source contents into
2.682 +* this bit array.
2.683 +* Parameters : src - Source bit array
2.684 +* Effects : Source bit array contents are copied into this array
2.685 +* Returned : Reference to this array after copy
2.686 +***************************************************************************/
2.687 +BitArray& BitArray::operator=(const BitArray &src)
2.688 +{
2.689 + if (*this == src)
2.690 + {
2.691 + /* don't do anything for a self assignment */
2.692 + return *this;
2.693 + }
2.694 +
2.695 + if (m_NumBits != src.m_NumBits)
2.696 + {
2.697 + /* don't do assignment with different array sizes */
2.698 + return *this;
2.699 + }
2.700 +
2.701 + if ((m_NumBits == 0) || (src.m_NumBits == 0))
2.702 + {
2.703 + /* don't do assignment with unallocated array */
2.704 + return *this;
2.705 + }
2.706 +
2.707 + /* copy bits from source */
2.708 + int size;
2.709 + size = BITS_TO_CHARS(m_NumBits);
2.710 +
2.711 + copy(src.m_Array, &src.m_Array[size], this->m_Array);
2.712 + return *this;
2.713 +}
2.714 +
2.715 +/***************************************************************************
2.716 +* Method : operator&=
2.717 +* Description: overload of the &= operator. Performs a bitwise and
2.718 +* between the source array and this bit array. This bit
2.719 +* array will contain the result.
2.720 +* Parameters : src - Source bit array
2.721 +* Effects : Results of bitwise and are stored in this array
2.722 +* Returned : Reference to this array after and
2.723 +***************************************************************************/
2.724 +BitArray& BitArray::operator&=(const BitArray &src)
2.725 +{
2.726 + int size;
2.727 +
2.728 + size = BITS_TO_CHARS(m_NumBits);
2.729 +
2.730 + if (m_NumBits != src.m_NumBits)
2.731 + {
2.732 + /* don't do assignment with different array sizes */
2.733 + return *this;
2.734 + }
2.735 +
2.736 + /* AND array one unsigned char at a time */
2.737 + for(int i = 0; i < size; i++)
2.738 + {
2.739 + m_Array[i] = m_Array[i] & src.m_Array[i];
2.740 + }
2.741 +
2.742 + return *this;
2.743 +}
2.744 +
2.745 +/***************************************************************************
2.746 +* Method : operator^=
2.747 +* Description: overload of the ^= operator. Performs a bitwise xor
2.748 +* between the source array and this bit array. This bit
2.749 +* array will contain the result.
2.750 +* Parameters : src - Source bit array
2.751 +* Effects : Results of bitwise xor are stored in this array
2.752 +* Returned : Reference to this array after xor
2.753 +***************************************************************************/
2.754 +BitArray& BitArray::operator^=(const BitArray &src)
2.755 +{
2.756 + int size;
2.757 +
2.758 + size = BITS_TO_CHARS(m_NumBits);
2.759 +
2.760 + if (m_NumBits != src.m_NumBits)
2.761 + {
2.762 + /* don't do assignment with different array sizes */
2.763 + return *this;
2.764 + }
2.765 +
2.766 + /* XOR array one unsigned char at a time */
2.767 + for(int i = 0; i < size; i++)
2.768 + {
2.769 + m_Array[i] = m_Array[i] ^ src.m_Array[i];
2.770 + }
2.771 +
2.772 + return *this;
2.773 +}
2.774 +
2.775 +/***************************************************************************
2.776 +* Method : operator|=
2.777 +* Description: overload of the |= operator. Performs a bitwise or
2.778 +* between the source array and this bit array. This bit
2.779 +* array will contain the result.
2.780 +* Parameters : src - Source bit array
2.781 +* Effects : Results of bitwise or are stored in this array
2.782 +* Returned : Reference to this array after or
2.783 +***************************************************************************/
2.784 +BitArray& BitArray::operator|=(const BitArray &src)
2.785 +{
2.786 + int size;
2.787 +
2.788 + size = BITS_TO_CHARS(m_NumBits);
2.789 +
2.790 + if (m_NumBits != src.m_NumBits)
2.791 + {
2.792 + /* don't do assignment with different array sizes */
2.793 + return *this;
2.794 + }
2.795 +
2.796 + /* OR array one unsigned char at a time */
2.797 + for(int i = 0; i < size; i++)
2.798 + {
2.799 + m_Array[i] = m_Array[i] | src.m_Array[i];
2.800 + }
2.801 +
2.802 + return *this;
2.803 +}
2.804 +
2.805 +/***************************************************************************
2.806 +* Method : Not
2.807 +* Description: Negates all non-spare bits in bit array.
2.808 +* Parameters : None
2.809 +* Effects : Contents of bit array are negated. Any spare bits are
2.810 +* left at 0.
2.811 +* Returned : Reference to this array after not
2.812 +***************************************************************************/
2.813 +BitArray& BitArray::Not(void)
2.814 +{
2.815 + int bits;
2.816 + unsigned char mask;
2.817 + int size;
2.818 +
2.819 + size = BITS_TO_CHARS(m_NumBits);
2.820 +
2.821 + if (m_NumBits == 0)
2.822 + {
2.823 + /* don't do not with unallocated array */
2.824 + return *this;
2.825 + }
2.826 +
2.827 + /* NOT array one unsigned char at a time */
2.828 + for(int i = 0; i < size; i++)
2.829 + {
2.830 + m_Array[i] = ~m_Array[i];
2.831 + }
2.832 +
2.833 + /* zero any spare bits so increment and decrement are consistent */
2.834 + bits = m_NumBits % CHAR_BIT;
2.835 + if (bits != 0)
2.836 + {
2.837 + mask = UCHAR_MAX << (CHAR_BIT - bits);
2.838 + m_Array[BIT_CHAR(m_NumBits - 1)] &= mask;
2.839 + }
2.840 +
2.841 + return *this;
2.842 +}
2.843 +
2.844 +/***************************************************************************
2.845 +* Method : operator<<=
2.846 +* Description: overload of the <<= operator. Performs a left shift on
2.847 +* this bit array. This bit array will contain the result.
2.848 +* Parameters : shifts - number of bit positions to shift
2.849 +* Effects : Results of the shifts are stored in this array
2.850 +* Returned : Reference to this array after shift
2.851 +***************************************************************************/
2.852 +BitArray& BitArray::operator<<=(const unsigned int shifts)
2.853 +{
2.854 + int i;
2.855 + int chars = shifts / CHAR_BIT; /* number of whole byte shifts */
2.856 +
2.857 + if (shifts >= m_NumBits)
2.858 + {
2.859 + /* all bits have been shifted off */
2.860 + this->ClearAll();
2.861 + return *this;
2.862 + }
2.863 +
2.864 + /* first handle big jumps of bytes */
2.865 + if (chars > 0)
2.866 + {
2.867 + int size;
2.868 +
2.869 + size = BITS_TO_CHARS(m_NumBits);
2.870 +
2.871 + for (i = 0; (i + chars) < size; i++)
2.872 + {
2.873 + m_Array[i] = m_Array[i + chars];
2.874 + }
2.875 +
2.876 + /* now zero out new bytes on the right */
2.877 + for (i = size; chars > 0; chars--)
2.878 + {
2.879 + m_Array[i - chars] = 0;
2.880 + }
2.881 + }
2.882 +
2.883 + /* now we have at most CHAR_BIT - 1 bit shifts across the whole array */
2.884 + for (i = 0; i < (int)(shifts % CHAR_BIT); i++)
2.885 + {
2.886 + for (unsigned int j = 0; j < BIT_CHAR(m_NumBits - 1); j++)
2.887 + {
2.888 + m_Array[j] <<= 1;
2.889 +
2.890 + /* handle shifts across byte bounds */
2.891 + if (m_Array[j + 1] & MS_BIT)
2.892 + {
2.893 + m_Array[j] |= 0x01;
2.894 + }
2.895 + }
2.896 +
2.897 + m_Array[BIT_CHAR(m_NumBits - 1)] <<= 1;
2.898 + }
2.899 +
2.900 + return *this;
2.901 +}
2.902 +
2.903 +/***************************************************************************
2.904 +* Method : operator>>=
2.905 +* Description: overload of the >>= operator. Performs a right shift on
2.906 +* this bit array. This bit array will contain the result.
2.907 +* Parameters : shifts - number of bit positions to shift
2.908 +* Effects : Results of the shifts are stored in this array
2.909 +* Returned : Reference to this array after shift
2.910 +***************************************************************************/
2.911 +BitArray& BitArray::operator>>=(const unsigned int shifts)
2.912 +{
2.913 + int i;
2.914 + char mask;
2.915 + int chars = shifts / CHAR_BIT; /* number of whole byte shifts */
2.916 +
2.917 + if (shifts >= m_NumBits)
2.918 + {
2.919 + /* all bits have been shifted off */
2.920 + this->ClearAll();
2.921 + return *this;
2.922 + }
2.923 +
2.924 + /* first handle big jumps of bytes */
2.925 + if (chars > 0)
2.926 + {
2.927 + for (i = BIT_CHAR(m_NumBits - 1); (i - chars) >= 0; i--)
2.928 + {
2.929 + m_Array[i] = m_Array[i - chars];
2.930 + }
2.931 +
2.932 + /* now zero out new bytes on the right */
2.933 + for (; chars > 0; chars--)
2.934 + {
2.935 + m_Array[chars - 1] = 0;
2.936 + }
2.937 + }
2.938 +
2.939 + /* now we have at most CHAR_BIT - 1 bit shifts across the whole array */
2.940 + for (i = 0; i < (int)(shifts % CHAR_BIT); i++)
2.941 + {
2.942 + for (unsigned int j = BIT_CHAR(m_NumBits - 1); j > 0; j--)
2.943 + {
2.944 + m_Array[j] >>= 1;
2.945 +
2.946 + /* handle shifts across byte bounds */
2.947 + if (m_Array[j - 1] & 0x01)
2.948 + {
2.949 + m_Array[j] |= MS_BIT;
2.950 + }
2.951 + }
2.952 +
2.953 + m_Array[0] >>= 1;
2.954 + }
2.955 +
2.956 + /***********************************************************************
2.957 + * zero any spare bits that are shifted beyond the end of the bit array
2.958 + * so that increment and decrement are consistent.
2.959 + ***********************************************************************/
2.960 + i = m_NumBits % CHAR_BIT;
2.961 + if (i != 0)
2.962 + {
2.963 + mask = UCHAR_MAX << (CHAR_BIT - i);
2.964 + m_Array[BIT_CHAR(m_NumBits - 1)] &= mask;
2.965 + }
2.966 +
2.967 + return *this;
2.968 +}
2.969 +
2.970 +/***************************************************************************
2.971 +* Method : bit_array_index_c - constructor
2.972 +* Description: This is the bit_array_index_c constructor. It stores a
2.973 +* pointer to the bit array and the bit index.
2.974 +* Parameters : array - pointer to bit array
2.975 +* index - index of bit in array
2.976 +* Effects : Pointer to bit array and bit index are stored.
2.977 +* Returned : None
2.978 +***************************************************************************/
2.979 +BitArrayIndex::BitArrayIndex(BitArray *array,
2.980 + const unsigned int index)
2.981 +{
2.982 + m_BitArray = array;
2.983 + m_Index = index;
2.984 +}
2.985 +
2.986 +/***************************************************************************
2.987 +* Method : operator=
2.988 +* Description: overload of the = operator. Sets the bit array bit to
2.989 +* the value of src.
2.990 +* Parameters : src - bit value
2.991 +* Effects : Bit pointed to by this object is set to the value of
2.992 +* source.
2.993 +* Returned : None
2.994 +***************************************************************************/
2.995 +void BitArrayIndex::operator=(const bool src)
2.996 +{
2.997 + if (m_BitArray == NULL)
2.998 + {
2.999 + return; /* no array */
2.1000 + }
2.1001 +
2.1002 + if (m_BitArray->SizeInBits() <= m_Index)
2.1003 + {
2.1004 + return; /* index is out of bounds */
2.1005 + }
2.1006 +
2.1007 + if (src)
2.1008 + {
2.1009 + m_BitArray->SetBit(m_Index);
2.1010 + }
2.1011 + else
2.1012 + {
2.1013 + m_BitArray->ClearBit(m_Index);
2.1014 + }
2.1015 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/MiniDisplay/BitArray.h Tue May 27 19:50:28 2014 +0200
3.3 @@ -0,0 +1,160 @@
3.4 +/***************************************************************************
3.5 +* Arrays of Arbitrary Bit Length
3.6 +*
3.7 +* File : bitarray.h
3.8 +* Purpose : Header file for class supporting the creation and
3.9 +* manipulation of arbitrary length arrays of bits.
3.10 +* Author : Michael Dipperstein
3.11 +* Date : July 23, 2004
3.12 +*
3.13 +****************************************************************************
3.14 +* HISTORY
3.15 +*
3.16 +* $Id: bitarray.h,v 1.5 2010/02/04 03:31:43 michael Exp $
3.17 +* $Log: bitarray.h,v $
3.18 +* Revision 1.5 2010/02/04 03:31:43 michael
3.19 +* Replaced vector<unsigned char> with an array of unsigned char.
3.20 +*
3.21 +* Made updates for GCC 4.4.
3.22 +*
3.23 +* Revision 1.4 2007/08/06 05:23:12 michael
3.24 +* Updated for LGPL Version 3.
3.25 +*
3.26 +* All methods that don't modify object have been made
3.27 +* const to increase functionality of const bit_array_c.
3.28 +*
3.29 +* All assignment operators return a reference to the object being assigned a value so that operator chaining will work.
3.30 +*
3.31 +* Added >> and << operators.
3.32 +*
3.33 +* Revision 1.3 2006/04/30 23:34:07 michael
3.34 +* Improved performance by incorporating Benjamin Schindler's
3.35 +* <bschindler@student.ethz.ch> changes to pass arguments as a reference.
3.36 +*
3.37 +* Revision 1.2 2004/08/05 22:17:04 michael
3.38 +* Add overloads for bitwise operators returning values.
3.39 +* Add a more natural looking way to set bit values.
3.40 +*
3.41 +* Revision 1.1.1.1 2004/08/04 13:28:20 michael
3.42 +* bit_array_c
3.43 +*
3.44 +****************************************************************************
3.45 +*
3.46 +* Bitarray: An ANSI C++ class for manipulating arbitrary length bit arrays
3.47 +* Copyright (C) 2004, 2006-2007, 2010 by
3.48 +* Michael Dipperstein (mdipper@alumni.engr.ucsb.edu)
3.49 +*
3.50 +* This file is part of the bit array library.
3.51 +*
3.52 +* The bit array library is free software; you can redistribute it and/or
3.53 +* modify it under the terms of the GNU Lesser General Public License as
3.54 +* published by the Free Software Foundation; either version 3 of the
3.55 +* License, or (at your option) any later version.
3.56 +*
3.57 +* The bit array library is distributed in the hope that it will be useful,
3.58 +* but WITHOUT ANY WARRANTY; without even the implied warranty of
3.59 +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
3.60 +* General Public License for more details.
3.61 +*
3.62 +* You should have received a copy of the GNU Lesser General Public License
3.63 +* along with this program. If not, see <http://www.gnu.org/licenses/>.
3.64 +*
3.65 +***************************************************************************/
3.66 +#ifndef BIT_ARRAY_H
3.67 +#define BIT_ARRAY_H
3.68 +
3.69 +/***************************************************************************
3.70 +* INCLUDED FILES
3.71 +***************************************************************************/
3.72 +#include <ostream>
3.73 +
3.74 +/***************************************************************************
3.75 +* TYPE DEFINITIONS
3.76 +***************************************************************************/
3.77 +class BitArray;
3.78 +
3.79 +/**
3.80 +*/
3.81 +class BitArrayIndex
3.82 +{
3.83 + public:
3.84 + BitArrayIndex(BitArray *array, const unsigned int index);
3.85 +
3.86 + /* assignment */
3.87 + void operator=(const bool src);
3.88 +
3.89 + private:
3.90 + BitArray *m_BitArray; /* array index applies to */
3.91 + unsigned int m_Index; /* index of bit in array */
3.92 +};
3.93 +
3.94 +/**
3.95 +TODO: Derive a Bit Frame class from this one for X Y access to pixels.
3.96 +*/
3.97 +class BitArray
3.98 +{
3.99 + public:
3.100 + BitArray(const int numBits);
3.101 + BitArray(unsigned char *array, const int numBits);
3.102 +
3.103 + virtual ~BitArray(void);
3.104 +
3.105 + void Dump(std::ostream &outStream);
3.106 +
3.107 + const unsigned int SizeInBits() { return m_NumBits; };
3.108 + const unsigned int SizeInBytes() { return m_SizeInBytes; };
3.109 +
3.110 + /* set/clear functions */
3.111 + void SetAll(void);
3.112 + void ClearAll(void);
3.113 + void SetBit(const unsigned int bit);
3.114 + void SetBitValue(const unsigned int bit, bool aValue);
3.115 + void ClearBit(const unsigned int bit);
3.116 +
3.117 + BitArrayIndex operator()(const unsigned int bit);
3.118 +
3.119 + /* boolean operator */
3.120 + bool operator[](const unsigned int bit) const;
3.121 + bool operator==(const BitArray &other) const;
3.122 + bool operator!=(const BitArray &other) const;
3.123 + bool operator<(const BitArray &other) const;
3.124 + bool operator<=(const BitArray &other) const;
3.125 + bool operator>(const BitArray &other) const;
3.126 + bool operator>=(const BitArray &other) const;
3.127 +
3.128 + /* bitwise operators */
3.129 + BitArray operator&(const BitArray &other) const;
3.130 + BitArray operator^(const BitArray &other) const;
3.131 + BitArray operator|(const BitArray &other) const;
3.132 + BitArray operator~(void) const;
3.133 +
3.134 + BitArray operator<<(const unsigned int count) const;
3.135 + BitArray operator>>(const unsigned int count) const;
3.136 +
3.137 + /* increment/decrement */
3.138 + BitArray& operator++(void); /* prefix */
3.139 + BitArray& operator++(int dummy); /* postfix */
3.140 + BitArray& operator--(void); /* prefix */
3.141 + BitArray& operator--(int dummy); /* postfix */
3.142 +
3.143 + /* assignments */
3.144 + BitArray& operator=(const BitArray &src);
3.145 +
3.146 + BitArray& operator&=(const BitArray &src);
3.147 + BitArray& operator^=(const BitArray &src);
3.148 + BitArray& operator|=(const BitArray &src);
3.149 + BitArray& Not(void); /* negate (~=) */
3.150 +
3.151 + BitArray& operator<<=(unsigned const int shifts);
3.152 + BitArray& operator>>=(unsigned const int shifts);
3.153 +
3.154 + unsigned char* Ptr(){return m_Array;}
3.155 + const unsigned char* Ptr() const{return m_Array;}
3.156 +
3.157 + protected:
3.158 + unsigned int m_NumBits; /* number of bits in the array */
3.159 + unsigned int m_SizeInBytes;
3.160 + unsigned char *m_Array; /* vector of characters */
3.161 +};
3.162 +
3.163 +#endif /* ndef BIT_ARRAY_H */
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/MiniDisplay/FutabaVfd.cpp Tue May 27 19:50:28 2014 +0200
4.3 @@ -0,0 +1,446 @@
4.4 +
4.5 +#include "FutabaVfd.h"
4.6 +//#include <stdlib.h>
4.7 +#include <string.h>
4.8 +
4.9 +
4.10 +//
4.11 +//
4.12 +//
4.13 +
4.14 +
4.15 +
4.16 +
4.17 +
4.18 +//
4.19 +//
4.20 +//
4.21 +
4.22 +FutabaVfdCommand::FutabaVfdCommand():/*iBuffer(NULL),*/iSize(0),iMaxSize(0)
4.23 + {
4.24 + }
4.25 +
4.26 +FutabaVfdCommand::~FutabaVfdCommand()
4.27 + {
4.28 + //Delete();
4.29 + }
4.30 +
4.31 +
4.32 +/**
4.33 +
4.34 +*/
4.35 +void FutabaVfdCommand::Reset()
4.36 + {
4.37 + memset(iReports,0,sizeof(iReports));
4.38 + }
4.39 +
4.40 +
4.41 +
4.42 +/**
4.43 +
4.44 +*/
4.45 +/*
4.46 +void FutabaVfdCommand::Create(int aMaxSize)
4.47 + {
4.48 + iBuffer=new unsigned char[aMaxSize];
4.49 + if (iBuffer)
4.50 + {
4.51 + iMaxSize = aMaxSize;
4.52 + iSize = 0;
4.53 + }
4.54 + }
4.55 +*/
4.56 +
4.57 +/**
4.58 +
4.59 +*/
4.60 +/*
4.61 +void FutabaVfdCommand::Delete()
4.62 +{
4.63 + delete[] iBuffer;
4.64 + iBuffer = NULL;
4.65 + iMaxSize = 0;
4.66 + iSize = 0;
4.67 +}
4.68 +*/
4.69 +
4.70 +
4.71 +
4.72 +
4.73 +//
4.74 +// class GP1212A01A
4.75 +//
4.76 +
4.77 +GP1212A01A::GP1212A01A():
4.78 + iDisplayPositionX(0),iDisplayPositionY(0),
4.79 + iOffScreenMode(true),iFrameBuffer(NULL)
4.80 + {
4.81 + //ResetBuffers();
4.82 + }
4.83 +
4.84 +/**
4.85 +*/
4.86 +GP1212A01A::~GP1212A01A()
4.87 + {
4.88 + delete iFrameBuffer;
4.89 + iFrameBuffer=NULL;
4.90 + }
4.91 +
4.92 +/**
4.93 +*/
4.94 +int GP1212A01A::Open()
4.95 + {
4.96 + int success = HidDevice::Open(KFutabaVendorId,KFutabaProductIdGP1212A01A,NULL);
4.97 + if (success)
4.98 + {
4.99 + delete iFrameBuffer;
4.100 + iFrameBuffer = NULL;
4.101 + iFrameBuffer=new BitArray(KGP12xFrameBufferPixelCount);
4.102 + SetNonBlocking(1);
4.103 + //Since we can't get our display position we for it to our default
4.104 + //This makes sure frames are in sync from the start
4.105 + SetDisplayPosition(iDisplayPositionX,iDisplayPositionY);
4.106 + //Now clear both front and back buffer on host and device
4.107 + Clear();
4.108 + SwapBuffers();
4.109 + Clear();
4.110 + SwapBuffers();
4.111 + }
4.112 + return success;
4.113 + }
4.114 +
4.115 +/**
4.116 +*/
4.117 +void GP1212A01A::SetPixel(unsigned char aX, unsigned char aY, bool aOn)
4.118 + {
4.119 + //Just specify a one pixel block
4.120 + //SetPixelBlock(aX,aY,0x00,0x01,aOn);
4.121 + //
4.122 + //int byteOffset=(aX*HeightInPixels()+aY)/8;
4.123 + //int bitOffset=(aX*HeightInPixels()+aY)%8;
4.124 + //iFrameBuffer[byteOffset] |= ( (aOn?0x01:0x00) << bitOffset );
4.125 + if (aOn)
4.126 + {
4.127 + iFrameBuffer->SetBit(aX*HeightInPixels()+aY);
4.128 + }
4.129 + else
4.130 + {
4.131 + iFrameBuffer->ClearBit(aX*HeightInPixels()+aY);
4.132 + }
4.133 + }
4.134 +
4.135 +/**
4.136 +*/
4.137 +void GP1212A01A::BitBlit(BitArray& aBitmap, int aSrcWidth, int aSrcHeight, int aTargetX, int aTargetY) const
4.138 + {
4.139 + //TODO: amend loop values so that we don't keep on looping past our frame buffer dimensions.
4.140 + for (int i=0;i<aSrcWidth;i++)
4.141 + {
4.142 + for (int j=0;j<aSrcHeight;j++)
4.143 + {
4.144 + iFrameBuffer->SetBitValue((aTargetX+i)*HeightInPixels()+aTargetY+j,aBitmap[+i*aSrcHeight+j]);
4.145 + }
4.146 + }
4.147 + }
4.148 +
4.149 +/**
4.150 +Set all pixels on our screen to the desired value.
4.151 +This operation is performed off screen to avoid tearing.
4.152 +@param 8 pixels pattern
4.153 +*/
4.154 +void GP1212A01A::SetAllPixels(unsigned char aPattern)
4.155 + {
4.156 + //With a single buffer
4.157 + //unsigned char screen[2048]; //One screen worth of pixels
4.158 + //memset(screen,0xFF,sizeof(screen));
4.159 + //SetPixelBlock(0,0,63,sizeof(screen),screen);
4.160 +
4.161 + //Using pattern SetPixelBlock variant.
4.162 + memset(iFrameBuffer->Ptr(),aPattern,FrameBufferSizeInBytes());
4.163 + //
4.164 +
4.165 +
4.166 + }
4.167 +
4.168 +/**
4.169 +Set our screen brightness.
4.170 +@param The desired brightness level. Must be between MinBrightness and MaxBrightness.
4.171 +*/
4.172 +void GP1212A01A::SetBrightness(int aBrightness)
4.173 + {
4.174 + if (aBrightness<MinBrightness()||aBrightness>MaxBrightness())
4.175 + {
4.176 + //Brightness out of range.
4.177 + //Just ignore that request.
4.178 + return;
4.179 + }
4.180 +
4.181 + FutabaVfdReport report;
4.182 + report[0]=0x00; //Report ID
4.183 + report[1]=0x06; //Report size
4.184 + report[2]=0x1B; //Command ID
4.185 + report[3]=0x5C; //Command ID
4.186 + report[4]=0x3F; //Command ID
4.187 + report[5]=0x4C; //Command ID
4.188 + report[6]=0x44; //Command ID
4.189 + report[7]=0x30+aBrightness; //Brightness level
4.190 + Write(report);
4.191 +
4.192 + }
4.193 +
4.194 +/**
4.195 +Set the defined pixel block to the given value.
4.196 +@param X coordinate of our pixel block starting point.
4.197 +@param Y coordinate of our pixel block starting point.
4.198 +@param The height of our pixel block.
4.199 +@param The size of our pixel data. Number of pixels divided by 8.
4.200 +@param The value set to 8 pixels used as a pattern.
4.201 +*/
4.202 +void GP1212A01A::SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char aValue)
4.203 + {
4.204 + OffScreenTranslation(aX,aY);
4.205 + FutabaVfdReport report;
4.206 + report[0]=0x00; //Report ID
4.207 + report[1]=(aSize<=report.Size()-10?aSize+0x08:64); //Report length. -10 is for our header first 10 bytes. +8 is for our Futaba header size
4.208 + report[2]=0x1B; //Command ID
4.209 + report[3]=0x5B; //Command ID
4.210 + report[4]=0xF0; //Command ID
4.211 + report[5]=aX; //X
4.212 + report[6]=aY; //Y
4.213 + report[7]=aHeight; //Y length before return. Though outside the specs, setting this to zero apparently allows us to modify a single pixel without touching any other.
4.214 + report[8]=aSize>>8; //Size of pixel data in bytes (MSB)
4.215 + report[9]=aSize; //Size of pixel data in bytes (LSB)
4.216 + int sizeWritten=MIN(aSize,report.Size()-10);
4.217 + memset(report.Buffer()+10, aValue, sizeWritten);
4.218 + Write(report);
4.219 +
4.220 + int remainingSize=aSize;
4.221 + //We need to keep on sending our pixel data until we are done
4.222 + while (report[1]==64)
4.223 + {
4.224 + report.Reset();
4.225 + remainingSize-=sizeWritten;
4.226 + report[0]=0x00; //Report ID
4.227 + report[1]=(remainingSize<=report.Size()-2?remainingSize:64); //Report length, should be 64 or the remaining size
4.228 + sizeWritten=(report[1]==64?63:report[1]);
4.229 + memset(report.Buffer()+2, aValue, sizeWritten);
4.230 + Write(report);
4.231 + }
4.232 + }
4.233 +
4.234 +/**
4.235 +Set the defined pixel block to the given value.
4.236 +@param X coordinate of our pixel block starting point.
4.237 +@param Y coordinate of our pixel block starting point.
4.238 +@param The height of our pixel block.
4.239 +@param The size of our pixel data. Number of pixels divided by 8.
4.240 +@param Pointer to our pixel data.
4.241 +*/
4.242 +void GP1212A01A::SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char* aPixels)
4.243 + {
4.244 + OffScreenTranslation(aX,aY);
4.245 + FutabaVfdReport report;
4.246 + report[0]=0x00; //Report ID
4.247 + report[1]=(aSize<=report.Size()-10?aSize+0x08:64); //Report length. -10 is for our header first 10 bytes. +8 is for our Futaba header size
4.248 + report[2]=0x1B; //Command ID
4.249 + report[3]=0x5B; //Command ID
4.250 + report[4]=0xF0; //Command ID
4.251 + report[5]=aX; //X
4.252 + report[6]=aY; //Y
4.253 + report[7]=aHeight; //Y length before return. Though outside the specs, setting this to zero apparently allows us to modify a single pixel without touching any other.
4.254 + report[8]=aSize>>8; //Size of pixel data in bytes (MSB)
4.255 + report[9]=aSize; //Size of pixel data in bytes (LSB)
4.256 + int sizeWritten=MIN(aSize,report.Size()-10);
4.257 + memcpy(report.Buffer()+10, aPixels, sizeWritten);
4.258 + Write(report);
4.259 +
4.260 + int remainingSize=aSize;
4.261 + //We need to keep on sending our pixel data until we are done
4.262 + while (report[1]==64)
4.263 + {
4.264 + report.Reset();
4.265 + remainingSize-=sizeWritten;
4.266 + report[0]=0x00; //Report ID
4.267 + report[1]=(remainingSize<=report.Size()-2?remainingSize:64); //Report length, should be 64 or the remaining size
4.268 + sizeWritten=(report[1]==64?63:report[1]);
4.269 + memcpy(report.Buffer()+2, aPixels+(aSize-remainingSize), sizeWritten);
4.270 + Write(report);
4.271 + }
4.272 + }
4.273 +
4.274 +
4.275 +/**
4.276 +Clear our client side back buffer.
4.277 +Call to SwapBuffers must follow to actually clear the display.
4.278 +*/
4.279 +void GP1212A01A::Clear()
4.280 + {
4.281 + //memset(iFrameBuffer->Ptr(),0x00,FrameBufferSizeInBytes());
4.282 + iFrameBuffer->ClearAll();
4.283 + }
4.284 +
4.285 +/**
4.286 +Using this function is advised against as is causes tearing.
4.287 +Use Clear instead.
4.288 +*/
4.289 +void GP1212A01A::SendClearCommand()
4.290 + {
4.291 + //1BH,5BH,32H,4AH
4.292 + //Send Clear Display Command
4.293 + FutabaVfdReport report;
4.294 + report[0]=0x00; //Report ID
4.295 + report[1]=0x04; //Report length
4.296 + report[2]=0x1B; //Command ID
4.297 + report[3]=0x5B; //Command ID
4.298 + report[4]=0x32; //Command ID
4.299 + report[5]=0x4A; //Command ID
4.300 + Write(report);
4.301 + }
4.302 +
4.303 +/**
4.304 +Change our display position within our buffer.
4.305 +*/
4.306 +void GP1212A01A::SetDisplayPosition(DW aDw,unsigned char aX, unsigned char aY)
4.307 + {
4.308 + //1BH,5BH,Dw,Px,Py
4.309 + //Send Display Position Settings Command
4.310 + FutabaVfdReport report;
4.311 + report[0]=0x00; //Report ID
4.312 + report[1]=0x05; //Report length
4.313 + report[2]=0x1B; //Command ID
4.314 + report[3]=0x5B; //Command ID
4.315 + report[4]=aDw; //Specify our DW
4.316 + report[5]=aX; //X coordinate of our DW top-left corner
4.317 + report[6]=aY; //Y coordinate of our DW top-left corner
4.318 + Write(report);
4.319 + }
4.320 +
4.321 +/**
4.322 +Change our display position within our buffer.
4.323 +*/
4.324 +void GP1212A01A::SetDisplayPosition(unsigned char aX, unsigned char aY)
4.325 + {
4.326 + //Specs apparently says both DW should remain the same
4.327 + //Just don't ask
4.328 + SetDisplayPosition(GP1212A01A::DW1,aX,aY);
4.329 + SetDisplayPosition(GP1212A01A::DW2,aX,aY);
4.330 + iDisplayPositionX=aX;
4.331 + iDisplayPositionY=aY;
4.332 + }
4.333 +
4.334 +/**
4.335 +Provide Y coordinate of our off screen buffer.
4.336 +*/
4.337 +unsigned char GP1212A01A::OffScreenY() const
4.338 + {
4.339 + //Overflowing is fine this is just what we want
4.340 + return iDisplayPositionY+HeightInPixels();
4.341 + }
4.342 +
4.343 +/**
4.344 +Put our off screen buffer on screen.
4.345 +On screen buffer goes off screen.
4.346 +*/
4.347 +void GP1212A01A::SwapBuffers()
4.348 + {
4.349 + //Only perform buffer swapping if off screen mode is enabled
4.350 + if (OffScreenMode())
4.351 + {
4.352 + //Send host back buffer to device back buffer
4.353 + SetPixelBlock(0,0,63,FrameBufferSizeInBytes(),iFrameBuffer->Ptr());
4.354 + //Swap device front and back buffer
4.355 + SetDisplayPosition(iDisplayPositionX,OffScreenY());
4.356 + //Swap host buffers
4.357 + //unsigned char* backBuffer=iBackBuffer;
4.358 + //iBackBuffer = iFrontBuffer;
4.359 + //iFrontBuffer = backBuffer;
4.360 + }
4.361 + }
4.362 +
4.363 +/**
4.364 +Translate the given pixel coordinate according to our off screen mode.
4.365 +*/
4.366 +void GP1212A01A::OffScreenTranslation(unsigned char& aX, unsigned char& aY)
4.367 + {
4.368 + if (OffScreenMode())
4.369 + {
4.370 + aX+=WidthInPixels()-iDisplayPositionX;
4.371 + aY+=HeightInPixels()-iDisplayPositionY;
4.372 + }
4.373 + }
4.374 +
4.375 +
4.376 +/**
4.377 +*/
4.378 +void GP1212A01A::ResetBuffers()
4.379 + {
4.380 + //iFrameBuffer->ClearAll();
4.381 + //memset(iFrameBuffer,0x00,sizeof(iFrameBuffer));
4.382 + //memset(iFrameBeta,0x00,sizeof(iFrameBeta));
4.383 + }
4.384 +
4.385 +/**
4.386 +*/
4.387 +void GP1212A01A::RequestId()
4.388 + {
4.389 + //1BH,5BH,63H,49H,44H
4.390 + //Send Read ID command
4.391 + FutabaVfdReport report;
4.392 + report[0]=0x00; //Report ID
4.393 + report[1]=0x05; //Report length
4.394 + report[2]=0x1B; //Command ID
4.395 + report[3]=0x5B; //Command ID
4.396 + report[4]=0x63; //Command ID
4.397 + report[5]=0x49; //Command ID
4.398 + report[6]=0x44; //Command ID
4.399 + Write(report);
4.400 + }
4.401 +
4.402 +/**
4.403 +*/
4.404 +void GP1212A01A::RequestFirmwareRevision()
4.405 + {
4.406 + //1BH,5BH,63H,46H,52H
4.407 + //Send Software Revision Read Command
4.408 + FutabaVfdReport report;
4.409 + report[0]=0x00; //Report ID
4.410 + report[1]=0x05; //Report length
4.411 + report[2]=0x1B; //Command ID
4.412 + report[3]=0x5B; //Command ID
4.413 + report[4]=0x63; //Command ID
4.414 + report[5]=0x46; //Command ID
4.415 + report[6]=0x52; //Command ID
4.416 + Write(report);
4.417 + }
4.418 +
4.419 +/**
4.420 +*/
4.421 +void GP1212A01A::RequestPowerSupplyStatus()
4.422 + {
4.423 + //1BH,5BH,63H,50H,4DH
4.424 + //Send Power Suppply Monitor Command
4.425 + FutabaVfdReport report;
4.426 + report[0]=0x00; //Report ID
4.427 + report[1]=0x05; //Report length
4.428 + report[2]=0x1B; //Command ID
4.429 + report[3]=0x5B; //Command ID
4.430 + report[4]=0x63; //Command ID
4.431 + report[5]=0x50; //Command ID
4.432 + report[6]=0x4D; //Command ID
4.433 + Write(report);
4.434 + }
4.435 +
4.436 +
4.437 +/**
4.438 +This is for development purposes only.
4.439 +Production application should stick to off-screen mode to avoid tearing.
4.440 +*/
4.441 +void GP1212A01A::ToggleOffScreenMode()
4.442 + {
4.443 + iOffScreenMode=!iOffScreenMode;
4.444 + //Clean up our buffers upon switching modes
4.445 + SetDisplayPosition(0,0);
4.446 + Clear();
4.447 + SwapBuffers();
4.448 + Clear();
4.449 + }
4.450 \ No newline at end of file
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/MiniDisplay/FutabaVfd.h Tue May 27 19:50:28 2014 +0200
5.3 @@ -0,0 +1,181 @@
5.4 +//
5.5 +//
5.6 +//
5.7 +
5.8 +#ifndef FUTABA_VFD_H
5.9 +#define FUTABA_VFD_H
5.10 +
5.11 +#include "hidapi.h"
5.12 +#include "HidDevice.h"
5.13 +#include "BitArray.h"
5.14 +
5.15 +#ifndef MIN
5.16 +#define MIN(a,b) (((a)<(b))?(a):(b))
5.17 +#endif
5.18 +
5.19 +#ifndef MAX
5.20 +#define MAX(a,b) (((a)>(b))?(a):(b))
5.21 +#endif
5.22 +
5.23 +
5.24 +//This was computed from our number of pixels as follow 256x64/8/64 = 32 + 1 = 33
5.25 +//+1 was added for our header
5.26 +const int KFutabaMaxCommandOutputReport = 33;
5.27 +//TODO: Get ride of that constant once we figure out a way to get it from hidapi
5.28 +const int KFutabaMaxHidReportSize = 65;
5.29 +
5.30 +const int KHidReportIdIndex=0;
5.31 +const int KFutabaHidReportSizeIndex=1;
5.32 +//Define Futaba vendor ID to filter our list of device
5.33 +const unsigned short KFutabaVendorId = 0x1008;
5.34 +const unsigned short KFutabaProductIdGP1212A01A = 0x100C;
5.35 +const unsigned short KFutabaProductIdGP1212A02A = 0x1013; //Or is it 0x1015
5.36 +const int KGP12xWidthInPixels = 256;
5.37 +const int KGP12xHeightInPixels = 64;
5.38 +const int KGP12xPixelsPerByte = 8;
5.39 +const int KGP12xFrameBufferSizeInBytes = KGP12xWidthInPixels*KGP12xHeightInPixels/KGP12xPixelsPerByte; //256*64/8=2048
5.40 +const int KGP12xFrameBufferPixelCount = KGP12xWidthInPixels*KGP12xHeightInPixels;
5.41 +
5.42 +//typedef struct hid_device_info HidDeviceInfo;
5.43 +
5.44 +/**
5.45 +Define a Futaba HID report.
5.46 +*/
5.47 +class FutabaVfdReport: public HidReport<KFutabaMaxHidReportSize>
5.48 + {
5.49 +
5.50 +private:
5.51 +
5.52 + };
5.53 +
5.54 +
5.55 +/**
5.56 +Define a generic Futaba VFD command.
5.57 +*/
5.58 +class FutabaVfdCommand
5.59 + {
5.60 +public:
5.61 + FutabaVfdCommand();
5.62 + ~FutabaVfdCommand();
5.63 + //
5.64 + //void Create(int aMaxSize);
5.65 + //void Delete();
5.66 +
5.67 + //inline unsigned char& operator[](int aIndex){return iBuffer[aIndex];}
5.68 +
5.69 + void Reset();
5.70 +
5.71 +private:
5.72 + //unsigned char* iBuffer;
5.73 + FutabaVfdReport iReports[KFutabaMaxCommandOutputReport];
5.74 + int iSize;
5.75 + int iMaxSize;
5.76 + };
5.77 +
5.78 +/**
5.79 +*/
5.80 +class FutabaVfd : public HidDevice
5.81 + {
5.82 +public:
5.83 + virtual int MinBrightness() const=0;
5.84 + virtual int MaxBrightness() const=0;
5.85 + virtual void SetBrightness(int aBrightness)=0;
5.86 + virtual void Clear()=0;
5.87 + };
5.88 +
5.89 +
5.90 +/**
5.91 +*/
5.92 +class FutabaGraphicVfd : public FutabaVfd
5.93 + {
5.94 +public:
5.95 + virtual int WidthInPixels() const=0;
5.96 + virtual int HeightInPixels() const=0;
5.97 + virtual void SetPixel(unsigned char aX, unsigned char aY, bool aOn)=0;
5.98 + virtual void SetAllPixels(unsigned char aOn)=0;
5.99 + virtual int FrameBufferSizeInBytes() const=0;
5.100 + //virtual int BitBlit(unsigned char* aSrc, unsigned char aSrcWidth, unsigned char aSrcHeight, unsigned char aTargetX, unsigned char aTargetY) const=0;
5.101 +
5.102 + };
5.103 +
5.104 +/**
5.105 +Common functionality between GP1212A01A and GP1212A02A
5.106 +*/
5.107 +class GP1212XXXX : public FutabaGraphicVfd
5.108 + {
5.109 +public:
5.110 + //From FutabaVfd
5.111 + virtual int MinBrightness() const {return 0;}
5.112 + virtual int MaxBrightness() const {return 5;}
5.113 + };
5.114 +
5.115 +/**
5.116 +GP1212A01A is a graphic display module using a FUTABA 256x64dots VFD.
5.117 +The module do not include character ROM, the customer will compile the character
5.118 +by themselves (from main system).
5.119 +*/
5.120 +class GP1212A01A : public GP1212XXXX
5.121 + {
5.122 +public:
5.123 + GP1212A01A();
5.124 + ~GP1212A01A();
5.125 + //
5.126 + int Open();
5.127 + //From FutabaGraphicVfd
5.128 + virtual int WidthInPixels() const {return KGP12xWidthInPixels;}
5.129 + virtual int HeightInPixels() const {return KGP12xHeightInPixels;}
5.130 + virtual void SetPixel(unsigned char aX, unsigned char aY, bool aOn);
5.131 + virtual void SetAllPixels(unsigned char aPattern);
5.132 + virtual int FrameBufferSizeInBytes() const {return KGP12xFrameBufferSizeInBytes;}
5.133 + virtual void BitBlit(BitArray& aBitmap, int aSrcWidth, int aSrcHeight, int aTargetX, int aTargetY) const;
5.134 + //From FutabaVfd
5.135 + virtual void SetBrightness(int aBrightness);
5.136 + virtual void Clear();
5.137 +
5.138 + //Specific to GP1212A01A
5.139 + void SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char aValue);
5.140 + void SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char* aPixels);
5.141 + //
5.142 + void SetDisplayPosition(unsigned char aX, unsigned char aY);
5.143 + void SwapBuffers();
5.144 + //
5.145 + void RequestId();
5.146 + void RequestFirmwareRevision();
5.147 + void RequestPowerSupplyStatus();
5.148 + //
5.149 + void ToggleOffScreenMode();
5.150 + bool OffScreenMode() const {return iOffScreenMode;}
5.151 + //
5.152 +
5.153 +
5.154 +private:
5.155 + enum DW
5.156 + {
5.157 + DW1=0xC0,
5.158 + DW2=0xD0
5.159 + };
5.160 +
5.161 + void SetDisplayPosition(DW aDw,unsigned char aX, unsigned char aY);
5.162 + unsigned char OffScreenY() const;
5.163 + void SendClearCommand();
5.164 + void OffScreenTranslation(unsigned char& aX, unsigned char& aY);
5.165 + void ResetBuffers();
5.166 +
5.167 +private:
5.168 + unsigned char iDisplayPositionX;
5.169 + unsigned char iDisplayPositionY;
5.170 + ///Off screen mode is the recommended default settings to avoid tearing.
5.171 + ///Though turning it off can be useful for debugging
5.172 + bool iOffScreenMode;
5.173 + ///
5.174 + //FutabaVfdReport iReport;
5.175 + ///
5.176 + //unsigned char iFrameBuffer[256*64];
5.177 + BitArray* iFrameBuffer;
5.178 + //unsigned char iFrameBeta[256*64];
5.179 + //unsigned char *iFrontBuffer;
5.180 + //unsigned char *iBackBuffer;
5.181 + };
5.182 +
5.183 +
5.184 +#endif
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/MiniDisplay/HidDevice.cpp Tue May 27 19:50:28 2014 +0200
6.3 @@ -0,0 +1,122 @@
6.4 +//
6.5 +//
6.6 +//
6.7 +
6.8 +#include "HidDevice.h"
6.9 +
6.10 +
6.11 +
6.12 +//
6.13 +// class HidDevice
6.14 +//
6.15 +
6.16 +HidDevice::HidDevice():iHidDevice(NULL)
6.17 + {
6.18 + Close();
6.19 + }
6.20 +
6.21 +/**
6.22 +*/
6.23 +int HidDevice::Open(const char* aPath)
6.24 + {
6.25 + Close();
6.26 +
6.27 + iHidDevice = hid_open_path(aPath);
6.28 +
6.29 + if (!iHidDevice)
6.30 + {
6.31 + //Fail to connect our device
6.32 + return 0;
6.33 + }
6.34 +
6.35 + FetchStrings();
6.36 +
6.37 + return 1;
6.38 + }
6.39 +
6.40 +/**
6.41 +See hidapi documentation.
6.42 +*/
6.43 +int HidDevice::Open(unsigned short aVendorId, unsigned short aProductId, const wchar_t* aSerialNumber)
6.44 + {
6.45 + Close();
6.46 +
6.47 + iHidDevice = hid_open(aVendorId, aProductId, aSerialNumber);
6.48 +
6.49 + if (!iHidDevice)
6.50 + {
6.51 + //Fail to connect our device
6.52 + return 0;
6.53 + }
6.54 +
6.55 + FetchStrings();
6.56 +
6.57 + return 1;
6.58 + }
6.59 +
6.60 +/**
6.61 +*/
6.62 +void HidDevice::Close()
6.63 + {
6.64 + hid_close(iHidDevice);
6.65 + iHidDevice=NULL;
6.66 + //
6.67 + memset(iVendor,0,sizeof(iVendor));
6.68 + memset(iProduct,0,sizeof(iProduct));
6.69 + memset(iSerialNumber,0,sizeof(iSerialNumber));
6.70 + }
6.71 +
6.72 +/**
6.73 +*/
6.74 +bool HidDevice::IsOpen()
6.75 + {
6.76 + return iHidDevice!=NULL;
6.77 + }
6.78 +
6.79 +
6.80 +/**
6.81 +*/
6.82 +const wchar_t* HidDevice::Error()
6.83 + {
6.84 + return hid_error(iHidDevice);
6.85 + }
6.86 +
6.87 +/**
6.88 +*/
6.89 +int HidDevice::SetNonBlocking(int aNonBlocking)
6.90 + {
6.91 + //Success we are now connected to our HID device
6.92 + //Set read operation as non blocking
6.93 + return hid_set_nonblocking(iHidDevice, aNonBlocking);
6.94 + }
6.95 +
6.96 +/**
6.97 +*/
6.98 +wchar_t* HidDevice::Vendor()
6.99 + {
6.100 + return iVendor;
6.101 + }
6.102 +
6.103 +/**
6.104 +*/
6.105 +wchar_t* HidDevice::Product()
6.106 + {
6.107 + return iProduct;
6.108 + }
6.109 +
6.110 +/**
6.111 +*/
6.112 +wchar_t* HidDevice::SerialNumber()
6.113 + {
6.114 + return iSerialNumber;
6.115 + }
6.116 +
6.117 +/**
6.118 +
6.119 +*/
6.120 +void HidDevice::FetchStrings()
6.121 + {
6.122 + hid_get_manufacturer_string(iHidDevice,iVendor,sizeof(iVendor));
6.123 + hid_get_product_string(iHidDevice,iProduct,sizeof(iProduct));
6.124 + hid_get_serial_number_string(iHidDevice,iSerialNumber,sizeof(iSerialNumber));
6.125 + }
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/MiniDisplay/HidDevice.h Tue May 27 19:50:28 2014 +0200
7.3 @@ -0,0 +1,69 @@
7.4 +//
7.5 +//
7.6 +//
7.7 +
7.8 +#ifndef HID_DEVICE_H
7.9 +#define HID_DEVICE_H
7.10 +
7.11 +#include "HidReport.h"
7.12 +#include "hidapi.h"
7.13 +
7.14 +const int KMaxHidStringChar=256;
7.15 +
7.16 +/**
7.17 +TODO: move to another header
7.18 +*/
7.19 +class HidDevice
7.20 + {
7.21 +public:
7.22 + HidDevice();
7.23 + int Open(const char* aPath);
7.24 + int Open(unsigned short aVendorId, unsigned short aProductId, const wchar_t* aSerialNumber);
7.25 + void Close();
7.26 + bool IsOpen();
7.27 + //
7.28 + int SetNonBlocking(int aNonBlocking);
7.29 + //Read
7.30 + template<int S>
7.31 + int Read(HidReport<S>& aInputReport);
7.32 + //Write
7.33 + template<int S>
7.34 + int Write(const HidReport<S>& aOutputReport);
7.35 + //
7.36 + const wchar_t* Error();
7.37 + //
7.38 + wchar_t* Vendor();
7.39 + wchar_t* Product();
7.40 + wchar_t* SerialNumber();
7.41 +
7.42 +private:
7.43 + void FetchStrings();
7.44 +
7.45 +private:
7.46 + ///Our USB HID device
7.47 + hid_device* iHidDevice;
7.48 + //
7.49 + wchar_t iVendor[KMaxHidStringChar];
7.50 + wchar_t iProduct[KMaxHidStringChar];
7.51 + wchar_t iSerialNumber[KMaxHidStringChar];
7.52 + };
7.53 +
7.54 +
7.55 +/**
7.56 +*/
7.57 +template<int S>
7.58 +int HidDevice::Write(const HidReport<S>& aOutputReport)
7.59 + {
7.60 + return hid_write(iHidDevice,aOutputReport.Buffer(),S);
7.61 + }
7.62 +
7.63 +/**
7.64 +*/
7.65 +template<int S>
7.66 +int HidDevice::Read(HidReport<S>& aInputReport)
7.67 + {
7.68 + return hid_read(iHidDevice,aInputReport.Buffer(),S);
7.69 + }
7.70 +
7.71 +
7.72 +#endif
7.73 \ No newline at end of file
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/MiniDisplay/HidReport.h Tue May 27 19:50:28 2014 +0200
8.3 @@ -0,0 +1,31 @@
8.4 +#ifndef HID_REPORT_H
8.5 +#define HID_REPORT_H
8.6 +
8.7 +#include <string.h>
8.8 +
8.9 +/**
8.10 +Define an HID report.
8.11 +Can be used as input and output.
8.12 +*/
8.13 +template <int S>
8.14 +class HidReport
8.15 + {
8.16 +public:
8.17 + HidReport(){Reset();}
8.18 + void Reset();
8.19 + inline unsigned char& operator[](int aIndex){return iBuffer[aIndex];}
8.20 + const unsigned char* Buffer() const {return iBuffer;}
8.21 + unsigned char* Buffer() {return iBuffer;}
8.22 + int Size() {return S;}
8.23 +protected:
8.24 + unsigned char iBuffer[S];
8.25 + };
8.26 +
8.27 +template <int S>
8.28 +void HidReport<S>::Reset()
8.29 + {
8.30 + memset(iBuffer,0,sizeof(iBuffer));
8.31 + }
8.32 +
8.33 +
8.34 +#endif
9.1 --- a/MiniDisplay/minidisplay.cpp Tue May 27 17:52:07 2014 +0200
9.2 +++ b/MiniDisplay/minidisplay.cpp Tue May 27 19:50:28 2014 +0200
9.3 @@ -9,11 +9,58 @@
9.4
9.5 // setFlag(ItemHasContents, true);
9.6 //
9.7 - qDebug() << "New MiniDisplay";
9.8 + //qDebug() << "New MiniDisplay";
9.9 }
9.10
9.11 MiniDisplay::~MiniDisplay()
9.12 {
9.13 - qDebug() << "Delete MiniDisplay";
9.14 + //qDebug() << "Delete MiniDisplay";
9.15 }
9.16
9.17 +
9.18 +void MiniDisplay::open()
9.19 +{
9.20 + if (iDisplay.Open())
9.21 + {
9.22 + emit miniDisplayOpened();
9.23 + emit miniDisplayStatusChanged();
9.24 + }
9.25 + else
9.26 + {
9.27 + emit miniDisplayOpenError();
9.28 + }
9.29 +}
9.30 +
9.31 +
9.32 +void MiniDisplay::close()
9.33 +{
9.34 + iDisplay.Close();
9.35 + emit miniDisplayClosed();
9.36 + emit miniDisplayStatusChanged();
9.37 +}
9.38 +
9.39 +bool MiniDisplay::isOpen()
9.40 +{
9.41 + return iDisplay.IsOpen();
9.42 +}
9.43 +
9.44 +void MiniDisplay::clear()
9.45 +{
9.46 + if (!iDisplay.IsOpen()) return;
9.47 + //
9.48 + iDisplay.Clear();
9.49 +}
9.50 +
9.51 +void MiniDisplay::fill()
9.52 +{
9.53 + if (!iDisplay.IsOpen()) return;
9.54 + //
9.55 + iDisplay.SetAllPixels(0xFF);
9.56 +}
9.57 +
9.58 +void MiniDisplay::swapBuffers()
9.59 +{
9.60 + if (!iDisplay.IsOpen()) return;
9.61 + //
9.62 + iDisplay.SwapBuffers();
9.63 +}
10.1 --- a/MiniDisplay/minidisplay.h Tue May 27 17:52:07 2014 +0200
10.2 +++ b/MiniDisplay/minidisplay.h Tue May 27 19:50:28 2014 +0200
10.3 @@ -2,15 +2,37 @@
10.4 #define MINIDISPLAY_H
10.5
10.6 #include <QQuickItem>
10.7 +#include "FutabaVfd.h"
10.8
10.9 class MiniDisplay : public QQuickItem
10.10 {
10.11 Q_OBJECT
10.12 Q_DISABLE_COPY(MiniDisplay)
10.13 + //
10.14 + Q_PROPERTY(bool isOpen READ isOpen NOTIFY miniDisplayStatusChanged)
10.15 +
10.16 +
10.17 +public:
10.18 + Q_INVOKABLE void open();
10.19 + Q_INVOKABLE void close();
10.20 + bool isOpen();
10.21 + //
10.22 + Q_INVOKABLE void clear();
10.23 + Q_INVOKABLE void fill();
10.24 + Q_INVOKABLE void swapBuffers();
10.25 +
10.26 +signals:
10.27 + void miniDisplayOpened();
10.28 + void miniDisplayOpenError();
10.29 + void miniDisplayClosed();
10.30 + void miniDisplayStatusChanged();
10.31
10.32 public:
10.33 MiniDisplay(QQuickItem *parent = 0);
10.34 ~MiniDisplay();
10.35 +
10.36 +private:
10.37 + GP1212A01A iDisplay;
10.38 };
10.39
10.40 #endif // MINIDISPLAY_H
11.1 --- a/MiniDisplay/minidisplay.pro Tue May 27 17:52:07 2014 +0200
11.2 +++ b/MiniDisplay/minidisplay.pro Tue May 27 19:50:28 2014 +0200
11.3 @@ -18,11 +18,23 @@
11.4 # Input
11.5 SOURCES += \
11.6 minidisplay_plugin.cpp \
11.7 - minidisplay.cpp
11.8 + minidisplay.cpp \
11.9 + BitArray.cpp \
11.10 + FutabaVfd.cpp \
11.11 + HidDevice.cpp \
11.12 + ../../../GitHub/hidapi/windows/hid.c
11.13
11.14 HEADERS += \
11.15 minidisplay_plugin.h \
11.16 - minidisplay.h
11.17 + minidisplay.h \
11.18 + BitArray.h \
11.19 + FutabaVfd.h \
11.20 + HidDevice.h \
11.21 + HidReport.h \
11.22 + ../../../GitHub/hidapi/hidapi/hidapi.h
11.23 +
11.24 +INCLUDEPATH += \
11.25 +../../../GitHub/hidapi/hidapi
11.26
11.27 OTHER_FILES = qmldir
11.28
11.29 @@ -42,3 +54,4 @@
11.30 INSTALLS += target qmldir
11.31 }
11.32
11.33 +win32:LIBS += "C:/Program Files (x86)/Windows Kits/8.0/Lib/win8/um/x86/setupAPI.lib"