📄 ui.c
字号:
//*****************************************************************************
//
// ui.c - User interface for the CNC machine.
//
// Copyright (c) 2006-2007 Luminary Micro, Inc. All rights reserved.
//
// Software License Agreement
//
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
// exclusively on LMI's microcontroller products.
//
// The software is owned by LMI and/or its suppliers, and is protected under
// applicable copyright laws. All rights are reserved. Any use in violation
// of the foregoing restrictions may subject the user to criminal sanctions
// under applicable laws, as well as to civil liability for the breach of the
// terms and conditions of this license.
//
// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 220 of sw01246.
//
//*****************************************************************************
#include "hw_memmap.h"
#include "hw_types.h"
#include "gpio.h"
#include "sysctl.h"
#include "systick.h"
#include "i2ccmds.h"
#include "i2c_master.h"
#include "lcd.h"
#include "rasterfont.h"
#include "ts.h"
#include "ui.h"
//*****************************************************************************
//
//! \page ui_ui_intro Introduction
//!
//! The LCD and touch screen are utilized to provide a user interface to
//! control the operation of the CNC machine. A virtual keyboard is provided
//! to allow text to be entered, the demonstration mode to be selected, and
//! the machine to be started and stopped.
//!
//! In normal operation, a virtual keyboard with a selection of special
//! function keys is provided on the LCD. The keyboard itself is used to enter
//! strings that are optionally used by the demonstrations. The keyboard
//! operates in a similar manner to many cell phones; by default text is
//! entered in an auto-capitalization mode that makes the first letter of each
//! word be a capital and all other letters lower case. Alternatively, it can
//! be placed in all uppercase or all lowercase mode. A button near the lower
//! corner of the LCD displays the current mode; "Abc" for auto-capitalization
//! mode, "ABC" for all uppercase mode, and "abc" for all lowercase mode. A
//! manual shift key is provided to force the next character to be uppercase,
//! regardless of the current mode. The shift key is also used to provide the
//! US keyboard variants of the numeric and punctuation keys (i.e. "!" for
//! shift-"1"). A backspace key is provided to correct mistakes; holding it
//! down for a second will erase the entire string.
//!
//! There are also four sets of special keys for controlling the machine. The
//! first set of keys are the six buttons across the top left of the keyboard
//! that allow the demonstration mode to be selected. Each of these keys has
//! a picture on it that represents the demonstration mode. The second set of
//! keys are the two tool selection keys at the top right of the keyboard. A
//! pen or a router can be selected; when the router is selected pressing the
//! router key will change the routing depth. The third set of keys are the
//! two logo selection keys at the bottom left of the keyboard. The ARM and/or
//! Luminary Micro logos can be individually toggled on and off with these
//! keys; if both are selected then the Luminary Micro logo takes precedence.
//! The final set is the run key in the lower right corner of the display.
//! Holding this key for a second will cause the CNC machine to start running
//! the selected demonstration program. While the machine is running, the run
//! key will be inverted; pressing the run key while inverted will cause the
//! demonstration to abort and the machine to return to the home position.
//!
//! The final key on the display is a "hidden" key that allows entry into
//! diagnostic mode. If the text display area across the top of the display is
//! held for five seconds, the virtual keyboard will be replaced by a
//! diagnostic display. The diagnostic display has several indicators and
//! several keys for performing diagnostic tests of the CNC machine.
//!
//! Three numbers across the display near the bottom show the current position
//! of the three axes in steps. The numbers are the X, Y, and then Z
//! positions. Since the home position is at 0, 0, 0, and it is "impossible"
//! (outside of driving past the limit switches, which is not recommended) to
//! have a negative position value, these values are displayed as positive
//! numbers. If a position does become negative, it will be displayed as a
//! large positive number. Also, only six digits of the position value is
//! display; for a 800 step per inch machine such as the one built by Luminary
//! Micro, this corresponds to over 100 feet (31.75 m) which is well beyond the
//! practical mechanical limitations of a CNC machine. If the machine is in
//! need of a homing operation, the positions will be displayed as "967295",
//! which is the last six digits of (2^32)-1 (or negative one).
//!
//! There are six "L" keys down the left and right side of the display that
//! correspond to the limit switches on each axis of the machine. If a limit
//! switch is engaged, the corresponding key is inverted. The keys on the left
//! side of the display represent the home limit switches and the keys on the
//! right side of the display represent the limit switches.
//!
//! The other indicator is the "P" key in the lower left corner of the display.
//! It indicates the status of the panic switch, and will be inverted when the
//! panic switch is engaged (i.e. the machine is forced to a non-operational
//! mode). If the "P" key is inverted, it will be impossible for the machine
//! to move the motors on its own (though of course they can be turned by
//! hand).
//!
//! Next to each limit switch key is a "+" or "-" key that allows the indicated
//! axis to be jogged in either direction. This single axis move allows the
//! motor, power electronics, and mechanical assembly for each axis to be
//! tested in isolation, which is especially helpful for adjusting the
//! alignment of the mechanical assembly.
//!
//! The final two keys are at the bottom of the display; there is a "S" key is
//! in the middle and the "<" key is at the right. Pressing the "S" key will
//! cause the gantries to move to the shipping position; this mechanism allows
//! the gantries to be in precisely the same place each time the machine is
//! shipped so that the packaging for the machine can be formed appropriately.
//! The "<" key simply exits diagnostic mode and returns to the normal virtual
//! keyboard display.
//!
//! The code for the user interface is contained in <tt>ui_micro/ui.c</tt>,
//! with <tt>ui_micro/ui.h</tt> containing the API definitions for use by the
//! remainder of the application.
//
//*****************************************************************************
//*****************************************************************************
//
//! \defgroup ui_ui_api Definitions
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
//! The GPIO pin on port B to which the piezo speaker is connected.
//
//*****************************************************************************
#define BEEP GPIO_PIN_0
//*****************************************************************************
//
//! The number of interrupts per second for the user interface.
//
//*****************************************************************************
#define UI_TICKS_PER_SECOND 200
//*****************************************************************************
//
//! The number of consecutive user interface interrupts that the touch screen
//! state (touched or not) must be constant in order to debounce state changes.
//
//*****************************************************************************
#define DEBOUNCE_COUNT 8
//*****************************************************************************
//
//! The number of consecutive user interface interrupts that the "Run" button
//! must be held in order to start the machine.
//
//*****************************************************************************
#define RUN_COUNT UI_TICKS_PER_SECOND
//*****************************************************************************
//
//! The number of consecutive user interface interrupts that the "Backspace"
//! button must be held in order to erase the string.
//
//*****************************************************************************
#define BACKSPACE_COUNT UI_TICKS_PER_SECOND
//*****************************************************************************
//
//! The number of consecutive user interface interrupts that the "Diag" button
//! must be held in order to enter diagnostic mode.
//
//*****************************************************************************
#define DIAG_COUNT (5 * UI_TICKS_PER_SECOND)
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when the touch
//! screen is being pressed.
//
//*****************************************************************************
#define UI_FLAG_DOWN 0
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when the user
//! interface is in diagnostic mode.
//
//*****************************************************************************
#define UI_FLAG_DIAG 1
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when the "Run"
//! button is being pressed.
//
//*****************************************************************************
#define UI_FLAG_RUN 2
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when the user
//! interface needs to be updated on the LCD.
//
//*****************************************************************************
#define UI_FLAG_UPDATE 3
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when the CNC machine
//! is running.
//
//*****************************************************************************
#define UI_FLAG_RUNNING 4
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when the virtual
//! keyboard is in all uppercase mode.
//
//*****************************************************************************
#define UI_FLAG_UPPER_CASE 5
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when the virtual
//! keyboard is in all lowercase mode.
//
//*****************************************************************************
#define UI_FLAG_LOWER_CASE 6
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when the entire
//! user interface needs to be redrawn on the LCD.
//
//*****************************************************************************
#define UI_FLAG_UPDATE_SCREEN 7
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when the CNC machine
//! needs to be started.
//
//*****************************************************************************
#define UI_FLAG_START 8
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when the CNC machine
//! needs to be stopped.
//
//*****************************************************************************
#define UI_FLAG_STOP 9
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when a user
//! interface has occurred.
//
//*****************************************************************************
#define UI_FLAG_TICK 10
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when the "Backspace"
//! button is being pressed.
//
//*****************************************************************************
#define UI_FLAG_BACKSPACE 11
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when the invisible
//! "Diag" button is being pressed.
//
//*****************************************************************************
#define UI_FLAG_DIAG_BUTTON 12
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when the machine
//! should be stopped when the touch screen button is released. This is used
//! during diagnostic mode to start a movement with a button press and stop it
//! with a button release.
//
//*****************************************************************************
#define UI_FLAG_STOP_ON_RELEASE 13
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when diagnostic
//! number one is selected.
//
//*****************************************************************************
#define UI_FLAG_DEMO1 16
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when diagnostic
//! number two is selected.
//
//*****************************************************************************
#define UI_FLAG_DEMO2 17
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when diagnostic
//! number three is selected.
//
//*****************************************************************************
#define UI_FLAG_DEMO3 18
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when diagnostic
//! number four is selected.
//
//*****************************************************************************
#define UI_FLAG_DEMO4 19
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when diagnostic
//! number five is selected.
//
//*****************************************************************************
#define UI_FLAG_DEMO5 20
//*****************************************************************************
//
//! The bit number in #g_ulUIFlags of the flag that is set when diagnostic
//! number six is selected.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -