For YRL Robot Arm

display.h

Committer:
jah128
Date:
2017-03-03
Revision:
0:b14dfd8816da

File content as of revision 0:b14dfd8816da:

/* University of York Robotics Laboratory Robot Arm Controller Board
 * 

 * File: display.cpp
 *
 * (C) Dept. Electronics & Computer Science, University of York
 * 
 * James Hilder, Alan Millard, Shuhei Miyashita, Homero Elizondo, Jon Timmis
 *
 *
 * January 2017
 *
 * Driver for the Midas 16x2 I2C LCD Display (MCCOG21605x6W) LCD
 * [Farnell part 2218942 or 2063206]
 *
 */ 


#ifndef DISPLAY_H
#define DISPLAY_H


/**
 * Display class
 * Functions for use with the Midas 16x2 I2C LCD Display (MCCOG21605x6W) LCD
 * Farnell part 2218942 or 2063206
 *
 * Example:
 * @code
 * #include "robotarm.h"
 *
 * Robotarm arm;
 *
 * int main() {
 *     arm.init();
 *     display.clear_display;       //Clears display
 *     display.set_position(0,2);   //Set cursor to row 0 column 2
 *     display.write_string("YORK ROBOTICS");
 *     display.set_position(1,3);   //Set cursor to row 1 column 3
 *     display.write_string("LABORATORY");
 * }
 * @endcode
*/
class Display : public Stream
{

// Public Functions

public:

    /** Create the LCD Display object connected to the default pins
     * (sda = p28, scl = p27)
     */
    Display();

    /** Create the LCD Display object connected to specific pins
     *
     * @param sda pin   - default is p28
     * @param scl pin   - default is p27
     */
    Display(PinName sda, PinName scl);

    /** Clear the display
    */
    void clear_display(void);

    /** Set cursor to home position
    */
    void home(void);

    /** Print string message
    * @param message - The null-terminated message to print
    */
    void write_string(char * message);

    /** Print string message of given length
    * @param message - The message to print
    * @param length - The number of characters to display
    */
    void write_string(char * message, char length);

    /** Set the row and column of cursor position
    * @param row - The row of the display to set the cursor to (either 0 or 1)
    * @param column - The column of the display to set the cursor to (range 0 to 15)
    */
    void set_position(char row, char column);

    /** Enable or disable cursor
    * @param enable - Set to 1 to enable the cursor visibility
    */
    void set_cursor(char enable);

    /** Enable or disable cursor blink
    * @param enable - Set to 1 to enable the cursor blinking mode
    */
    void set_blink(char enable);

    /** Enable or disable display
    * @param enable - Set to 1 to enable the display output
    */
    void set_display(char enable);

    //Parts of initialisation routine
    void post_init(void);
    void post_post_init(void);

    // Send a 1-byte control message to the display
    int i2c_message(char byte);

    // Default initialisation sequence for the display
    void init(void);

    int disp_putc(int c);


private :

    I2C _i2c;

    char display_on;
    char cursor_on;
    char blink_on;

    void _set_display();

    virtual int _putc(int c);
    virtual int _getc();

};

#endif // DISPLAY_H

/*
 * Copyright 2017 University of York
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and limitations under the License.
 */