6/27/2013

Detect web browser language


 $client_language=$_SERVER['HTTP_ACCEPT_LANGUAGE'];
 $find_str="KR";
 $find_pos=strpos($client_language,$find_str);
 if($find_pos==TRUE)
 {
    print("found ko");
 }
 else
 {
    print("not found ko");
 }
?>

6/20/2013

Google Chrome cash directory change.


open Chrome property dialog.

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"

Add cache directory name.

--disk-cache-dir="R:\TEMP\CHROME"


-- complete .

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"  --disk-cache-dir="R:\USERTEMP"


-- remove previous chrome cache dir.

C:\Users\ your name dir \AppData\Local\Google\Chrome\User Data\Default

/Default/Cache

/Default/Media Cache


Round View - android


- android Resource res drawable

rounded_corner_view.xml



http://schemas.android.com/apk/res/android
">   
   
   



Layour background


android:layout_height="wrap_content"
android:background="@drawable/rounded_corner_view"
android:padding="12dip"
android:orientation="vertical">
 

6/10/2013

visual studio 2012 initialize. reset


Visual Studio 2012 too slow.

initialize user data.


start menu --> command   

devenv.exe /resetuserdata 

For more information, http://www.microsoft.com

6/07/2013

serial port cts rts checking signal cable. linux and win32



// win32

int IsCTSEnabled(int handle)
{
  int status;

  GetCommModemStatus(handle, (LPDWORD)((void *)&status));

  if(status&MS_CTS_ON) return(1);
  else return(0);
}

// linux.

// ref
/*
TIOCM_LE  DSR (data set ready/line enable)
TIOCM_DTR DTR (data terminal ready)
TIOCM_RTS RTS (request to send)
TIOCM_ST  Secondary TXD (transmit)
TIOCM_SR  Secondary RXD (receive)
TIOCM_CTS CTS (clear to send)
TIOCM_CAR DCD (data carrier detect)
TIOCM_CD  Synonym for TIOCM_CAR
TIOCM_RNG RNG (ring)
TIOCM_RI  Synonym for TIOCM_RNG
TIOCM_DSR DSR (data set ready)
*/
int RS232_IsCTSEnabled(int handle)
{
  int status;

  ioctl((int handle, TIOCMGET, &status);

  if(status&TIOCM_CTS) return(1);
  else return(0);
}








6/04/2013

lua c/c++ binding. LUNA


LUNA 

Author 

/*
 * Lenny Palozzi - lenny.palozzi@home.com
 */


Code 


/*
 * Lenny Palozzi - lenny.palozzi@home.com
 */
extern "C" {
#include
}

template
class Luna
{
 public:
   /* member function map */
   struct RegType { 
      const char* name; 
      const int(T::*mfunc)(lua_State*);
   };      
   /* register class T */
   static void Register(lua_State* L) {
      lua_pushcfunction(L, &Luna::constructor);
      lua_setglobal(L, T::className);
      
      if (otag == 0) {
otag = lua_newtag(L);
lua_pushcfunction(L, &Luna::gc_obj);
lua_settagmethod(L, otag, "gc"); /* tm to release objects */
      }
   }
 private:
   static int otag; /* object tag */
   
   /* member function dispatcher */
   static int thunk(lua_State* L) {
      /* stack = closure(-1), [args...], 'self' table(1) */
      int i = static_cast(lua_tonumber(L,-1));
      lua_pushnumber(L, 0); /* userdata object at index 0 */
      lua_gettable(L, 1);
      T* obj = static_cast(lua_touserdata(L,-1));
      lua_pop(L, 2); /* pop closure value and obj */
      return (obj->*(T::Register[i].mfunc))(L);
   }
   
   /* constructs T objects */
   static int constructor(lua_State* L) {
      T* obj= new T(L); /* new T */
      /* user is expected to remove any values from stack */
      
      lua_newtable(L); /* new table object */
      lua_pushnumber(L, 0); /* userdata obj at index 0 */
      lua_pushusertag(L, obj, otag); /* have gc call tm */
      lua_settable(L, -3);
      
      /* register the member functions */
      for (int i=0; T::Register[i].name; i++) {
lua_pushstring(L, T::Register[i].name);
lua_pushnumber(L, i);
lua_pushcclosure(L, &Luna::thunk, 1);
lua_settable(L, -3);
      }
      return 1; /* return the table object */
   }

   /* releases objects */
   static int gc_obj(lua_State* L) {
      T* obj = static_cast(lua_touserdata(L, -1));
      delete obj;
      return 0;
   }
 protected: 
   Luna(); /* hide default constructor */
};
template
int Luna::otag = 0;



LICENSE



Copyright (c) 2005 Leonardo Palozzi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.




6/02/2013

Some Very good VC++/MFC resources beside Codeproject.com


(from http://www.codeproject.com)


List of Best Open Souce projects written in VC++/MFC

  1. 7-Zip (http://sourceforge.net/projects/sevenzip/) :
    7-Zip is a file archiver with the high compression ratio. The program supports 7z, ZIP, CAB, RAR, ARJ, LZH, CHM, GZIP, BZIP2, Z, TAR, CPIO, RPM and DEB formats. Compression ratio in the new 7z format is 30-50% better than ratio in ZIP format.
  2. eMule (http://sourceforge.net/projects/emule/):
    eMule is a filesharing client which is based on the eDonkey2000 network but offers more features than the standard client.
  3. eMule Plus (http://sourceforge.net/projects/emuleplus/) :
    eMule Plus is an evolution of the original eMule project, created to improve its abilities and features, in both work efficiency and user interface.
  4. eMule Morph (http://sourceforge.net/projects/emulemorph/):
    eMule Morph Mod - eMule Modding Project.
  5. FileZilla (http://sourceforge.net/projects/filezilla/):
    FileZilla is a fast FTP and SFTP client for Windows with a lot of features. FileZilla Server is a reliable FTP server.
  6. KeePass Password Safe (http://sourceforge.net/projects/keepass/):
    KeePass Password Safe is a free, open source, light-weight and easy-to-use password manager for Windows. You can store your passwords in a highly-encrypted database, which is locked with one master password or key file.
  7. K-Meleon (http://sourceforge.net/projects/kmeleon/):
    K-Meleon is a fast and customizable web browser that can be used instead of Internet Explorer on Windows. Powered by the same Gecko engine as the Firefox and Mozilla browsers, K-Meleon provides users with a secure browsing experience.
  8. MiKTeX (http://sourceforge.net/projects/miktex/):
    MiKTeX is an up-to-date implementation of TeX & Friends for Windows (all current variants).
  9. MyNapster (http://sourceforge.net/projects/mynapster/):
    MyNapster is a Win32 client using Gnutella and IRC for chat. It is based on Gnucleus and utilizes MFC (works with WINE).
  10. Nokia Composer (http://sourceforge.net/projects/nokiacomposer/):
    This is a Win32, VC++ MFC application to manage Nokia mobile phones melodies. Includes VC++ source code and Rational Rose UML model.
  11. Peters Backup (http://sourceforge.net/projects/pbackup):
    Peters Backup is a program for backing up your important data files on to diskette, zip drive, fixed disk or CD/RW. It uses an extremely efficient compression algorithm. It keeps track of all versions of your files in full and incremental backups.
  12. Password Safe (https://sourceforge.net/projects/passwordsafe/):
    Password Safe is a password database utility. Users can keep their passwords securely encrypted on their computers. A single Safe Combination unlocks them all.
  13. RenFile (http://sourceforge.net/projects/renfile/):
    rename files and folders in bulk using this vc++ .net program.
  14. Shareaza (https://sourceforge.net/projects/shareaza/):
    Multi-network peer-to-peer file-sharing client supporting Gnutella2, Gnutella1, eDonkey2000/eMule and BitTorrent protocols. Using C++, MFC and ATL, for Windows.
  15. SunshineUN (http://sourceforge.net/projects/sunshineun/):
    SunshineUN is a free Napster based file sharing program for Opennap/Slavanap which allows you to share and download multiple files of different types for example music, pictures and videos. It is for Windows and it is written in C++ using MFC .
  16. TortoiseCVS (http://sourceforge.net/projects/tortoisecvs/):
    TortoiseCVS is an extension for Microsoft Windows Explorer that makes using CVS fun and easy. Features include: colored icons, tight integration with SSH, and context-menu interactivity.
  17. TortoiseSVN (http://sourceforge.net/projects/tortoisesvn):
    TortoiseSVN is a Subversion (SVN) client, implemented as a windows shell extension. It's intuitive and easy to use, since it doesn't require the Subversion command line client to run. Simply the coolest Interface to (Sub)Version Control!
  18. WinDirStat: Windows Directory Statistics (http://sourceforge.net/projects/windirstat/):
    WinDirStat (WDS) is a disk usage statistics viewer and cleanup tool for Windows. It shows disk, file and directory sizes in a treelist as well as graphically in a treemap, much like KDirStat or SequoiaView.
  19. WinDjView (http://sourceforge.net/projects/windjview):
    WinDjView is a fast, compact and powerful DjVu viewer for Windows with continuous scrolling and advanced printing options, based on free DjVuLibre library. MacDjView is a simple DjVu viewer for Mac OS X, also with continuous scrolling.
  20. C++ Library for Windows (http://sourceforge.net/projects/rulib):
    A C++ library for the Windows platform containing classes for MIME, video capture, socket, Windows registry, files, images, and other basic purposes.
  21. WinMerge (https://sourceforge.net/projects/winmerge/):
    WinMerge is a Win32 tool for visual difference display and merging, for both files and directories. Unicode support. Flexible syntax coloring editor. Windows Shell integration. Regexp filtering. Side-by-side line diff and highlights diffs inside lines.
  22. Disk Cleaner (http://sourceforge.net/projects/dclean/):
    Disk Cleaner is a tool to quickly and easily free disk space that is used by temporary files like the system temporary folder, the Internet Explorer Cache and Cookies folder, and the Recycle Bin. It can be expanded with text-based plug-ins & DLLs.
  23. Shared IIS Server Log/Bandwidth-Analyzer (http://sourceforge.net/projects/sharediis/):
    This utility is intended to be used to analyze and present a per-site (in case of WWW logs), or (in case of FTP logs) a per-web summary of bandwidth used, hits, and average bandwidth used.
  24. Remote Control Center (http://sourceforge.net/projects/remotectrlctr/):
    Remote Control Center is an application designed to help a system/network administrators taking control of remote devices in the network from a single GUI.
  25. RevConnect - Enhanced DC++ (http://sourceforge.net/projects/reverseconnect/):
    RevConnect is a file sharing program based on DC++. It is fully compatible with the Direct Connect network and made some major features.
  26. Show Traffic (http://sourceforge.net/projects/showtraf):
    "Show Traffic" monitors network traffic on the chosen network interface and displays it continuously. It could be used for locating suspicious network traffic or to evaluate current utilization of the network interface.
  27. War FTP Daemon Engine (http://sourceforge.net/projects/wfde/):
    A generic C++ class library for FTP server implementations, including a full-featured, mature FTP server.
  28. AxCrypt - File Encryption for Windows (http://sourceforge.net/projects/axcrypt/):
    AxCrypt - Personal Privacy and Security with AES-128 File Encryption and Compression for Windows 98/ME/NT/2K/XP. Double-click to automatically decrypt and open documents. Store strong keys on removable USB-devices.
  29. Open Source Firewall For Windows (http://sourceforge.net/projects/firewallpapi/):
    FirewallPAPI is an open source firewall for Windows 2000 and above. It is a simple utility for filter network traffic.
  30. MinkSonic Jukebox (http://sourceforge.net/projects/minksonic):
    MFC-based front-end to Winamp that provides jukebox behavior as well as "explorer-like" MP3 library management, a web-based network interface and MP3 frame error detection/correction.
  31. p2pfire: super p2p driver firewall (http://sourceforge.net/projects/p2pfire):
    Super P2P firewall 32/64 bits (driver + aplication).
  32. WABAccess (http://sourceforge.net/projects/wabaccess/):
    The WABAccess component give an access to the Windows Address Book (or WAB) used by Outlook Express. It's a COM/ATL component that give an access from Visual Basic language or Scripting language (VBS) to WAB.
  33. Yet Another Fractal Explorer (http://sourceforge.net/projects/yafe):
    Yet Another Fractal Explorer is an interactive fractal renderer for Windows. It features extremely simple and intuitive user interface and is capable of producing mathematically-sound renderings.
  34. CDDA Ripper XP (http://sourceforge.net/projects/cddarip):
    CDDA Ripper XP is an audio CD ripper program that provides support for NT/2000/XP natively (ASPI manager is optional). It supports WAV-MP3-OGG-FLAC-ACM codec encoding and can be used to rip multiple CDs. It uses newest encoders like LAME and Ogg/Vorbis.
  35. [ mp3 - explorer ] (http://sourceforge.net/projects/mp3explorer):
    [ mp3 - explorer ] is a MP3 Manager providing advanced features : multi-folders file scaning with cache - id3v1 and id3v2 tagging - Intellitag - Html view of the tracks displaying album cover and Lyrics.
  36. ultraMaGE (http://sourceforge.net/projects/ultramage):
    ultraMage is a powerful dual-window file manager for Windows with many useful features like bookmarks, advanced file operations and folder synchronisation. It is still very easy to use, because the user interface is similar to that of Windows Explorer.
  37. WinTarBall (http://sourceforge.net/projects/wintarball/):
    WinTarBall adds a control panel and an Explorer shell extension that allow users to compress directories into .tgz or .tbz files simply by right-clicking on them and choosing "compress to tarball".
  38. XML Explorer (http://sourceforge.net/projects/xpathexplorer/):
    A utility to query xml files using XPath and also extend XPath to more documents than one. Win32 platform/MFC.
  39. Emerge Desktop (http://sourceforge.net/projects/emerge/):
    emerge is an alternate windows shell. It's purpose is to replace Windows Explorer as your desktop user interface, providing similar functionality, with the additional plugins to provide even more.
  40. Folder Size for Windows (http://sourceforge.net/projects/foldersize/):
    Folder Size for Windows adds a new column to the Windows Explorer details view that displays the sizes of files and folders. A service scans your hard disk in the background and caches the results. Designed for performance!
  41. Rename-It! (https://sourceforge.net/projects/renameit/):
    Define some filters to apply to a list of files, which can be in multiple folders, to rename the whole list at once. It checks the file names, integrates in the Shell (via Explorer context menu), supports regular expressions, ID3 tags, and much more.
  42. ShellWM (http://sourceforge.net/projects/shellwm/):
    Windows skinning application to be used with a Win32 Shell replacement (like Litestep, geOshell, sharpE, etc.) or just native Explorer.
  43. Blackbox for Windows (http://sourceforge.net/projects/bb4win/):
    Blackbox for Windows is an alternative shell for Microsoft Windows. It is based stylistically on the Blackbox window manager for the X Window System, however it does not use the same codebase except for the gradient rendering code.
  44. HideThatWindow! (http://sourceforge.net/projects/hidethatwindow/):
    HideThatWindow! enables you to Hide or Show a window; minimize, maximize and restore its original size (or change the size to fit your needs). Disable the window's taskbar button or send it to tray. Other features are transparency, docking and top-most.
  45. Security & Privacy Complete 3 (http://sourceforge.net/projects/cmia/):
    Security & Privacy Complete is mainly a security tool for Windows. It can disable all services which might be a securit-risk, harden registry settings... Also included privacy features for Internet Explorer, Media Player, and of course: Mozilla Firefox.
  46. TaskSwitchXP (http://sourceforge.net/projects/taskswitchxp/):
    TaskSwitchXP provides the same functionality as the existing application switching mechanism in Windows XP today. In addition to displaying an icon list, however, the application will also show a thumbnail preview of the window that will be switched to.
  47. Windows Process Tools (http://sourceforge.net/projects/winpstools):
    Command-line utilities to find, list, and terminate running processes under Windows, similar to the Unix ps and kill commands. Good for command-line folks who don't like to use the Windows Task Manager.
  48. OpenSTA (http://sourceforge.net/projects/opensta/):
    Open System Testing Architecture - a distributed software testing architecture designed around CORBA. The current toolset has the capability of performing scripted Web (HTTP and HTTPS) heavy load tests with performance measurements from Win32 platforms.
  49. MFC MUTE (http://sourceforge.net/projects/mfc-mute-net/):
    MFC MUTE is a MS Windows *ONLY* client for the MUTE anonymous P2P network. This application derives from the original MUTE (mute-net.sourceforge.net) app supporting anonymous file sharing. The GUI is the best/most polished Windows MUTE available.
  50. DeepNetScanner (http://sourceforge.net/projects/nbtenum):
    This is a internet security scanner which scans a specified machine or a range of IPs for all possible information like NetBIOS enumeration, gathering sharelist, domain, os, lan manager, remote connection, SNMP walking, ...
  51. WinSCP (http://sourceforge.net/projects/winscp/):
    WinSCP is a SFTP and SCP client for Windows using SSH. Its main function is secure copying of files between a local and a remote computer. Beyond this basic function, WinSCP manages some other actions with files. Plugin to FAR manager is available too.
  52. winfingerprint (http://sourceforge.net/projects/winfingerprint/):
    Winfingerprint is a Win32 MFC VC++ .NET based security tool that is able to Determine OS, enumerate users, groups, shares, SIDs, transports, sessions, services, service pack and hotfix level, date and time, disks, and open tcp and udp ports.
  53. Visual Component Framework (http://vcf-online.org/): The Visual Component Framework is an advanced C++ application framework that makes it easy to produce powerful C++ applications. The framework is a based on a thoroughly modern C++ design and has built in support for Rapid Application Development (RAD)

Some Very good VC++/MFC resources beside Codeproject.com

  1. http://www.naughter.com/ (VC++/MFC huge code repository)
    By PJ naughter Personally my favorite beside codeproject.com. This site contains huge source code repository for MFC programmer. It has some of the best addon classes written for MFC programmers. What I like most about PJ naughter is that he keeps on improving these classes and fix each and every bug in the code. Some of the classes has now is 70 to 80th version.
  2. http://flounder.com/mvp_tips.htm (VC++/MFC)
    BY Joseph M. Newcomer
    This is very nice site containing lots and lots of VC++ tips tricks and very detailed essays + great code examples. Main focus is on how to write the code in right way.
  3. http://www.cheztabor.com/ (ATL/WTL)
    by cheztabor
    This site contains very nice code examples for ATL , WTL and Shell programming.
  4. http://www.viksoe.dk/code/ (ATL/WTL)
    By author of Gmail Drive
    Although code for GmailDrive is not provided but this site contains lots of other code example covering MFC, ATL, WTL and Shell programming.
  5. http://www.codeguru.com/ (VC++/MFC/ATL and lot more)
    Does not need any introduction. I think most of us already know about this site.
  6. http://programmerworld.net/personal/projects.htm (VC++/MFC )
    This is my personal web site. It has one firewall software with source code. Will be adding more code soon.
  7. http://vcfaq.mvps.org/ (VC++/MFC FAQs)
    This is the MVP's Frequently Asked Questions Page for Microsoft Visual C++. In here you'll find answers to several common asked questions about Visual C++, MFC and Windows development in C/C++, as well as other.
  8. http://www.developersvoice.com/programming/article/vc-mfc (VC++/MFC)
    VC++/ MFC related FAQS
  9. http://www.functionx.com/ (VC++/MFC )
    A beginners site for VC++ and MFC programming. Contains some very nice beginner articles.
  10. http://www.softlookup.com/tutorial/vc++/index.asp A beginners site for VC++ and MFC programming. Contains some very nice beginner articles.
  11. http://www.mathcs.sjsu.edu/faculty/pearce/mfc/ A very vice web site. Very well written. One of the best resource for beginner in the field of VC++/MFC.

MFC tip #1




- Disable esc key exit for MFC Dialog

virtual PreTranslateMessage

{
if (pMsg->message == WM_KEYDOWN)
{
  if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE)
  {  
   return TRUE;
  }
}
}


- Position Child Control in Dialog

CRect rect;
GetDlgItem(your dialog control id)->GetWindowRect(&rect);
ScreenToClient(&rect); //

Free 3D Models


Free 3D Models resources sites.


TurboSquid
TheFree3DModels

All3dmodel

RockThe3D

Free3DModelz

Artist-3d

Dmi-3d

Archibase

3Delicious

Sharecg

Wirecase

3D Auto Club

3Dmodelfree

Trekmeshes

Sci-Fi 3D

Reference - Micro Touch (3M) Serial Interface Driver - directFB


This is DirectFB Input Micro Touch (3M) Driver Source.
if you want direct control Touch Device, first understand this source.


http://www.directfb.org


/*
   (c) Copyright 2000-2002  Fulgid Technology Co., Ltd.

   All rights reserved.

   Written by Simon Ueng

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   This driver is a re-write from the MuTouch driver provided in XFree86.
   Extended options in the MuTouch firmware are not used as it wasn't
   an issue during the writing of this driver.
   Baudrate has also been rewritting to automatically adjust to 19200 if
   its support else it uses 9600.

   Feel free to change according to your needs, but changing both
   MuT_MINX as well as MuT_MINY is required to adjust the orientation
   of the touchscreen. We've had numerous occasions where the one
   touchscreen was installed in a different orientation than others.
   Also don't forget to adjust the MuT_SCREENWIDTH and MuT_SCREENHEIGHT
   for the appropriate screen dimension.

   Not much time has been spent writing this driver therefore expect errors.
   Calibration process has also been omitted since there are applications
   to do the calibration process.

   Lastly, please don't email me regarding technical informations. I
   don't work for 3M. But if you have any new ideas on improving this
   driver, please don't hesitate to share it with me.
   */
/*
 * Jacques Luder j.luder@laposte.net
 * Baudrate adjust now realy working !
 * version 0.3 10/09/2006 Jacques Luder j.luder@laposte.net
 * Can now work also with a keyspan USB-Serial line.
 * Can start OK even if someone touch the screen during probing.
 */

#include

#include
#include
#include
#include
#include
#include

#include

#include
#include

#include

#include

#include
#include

#include
#include

#include

#include
#include
#include
#include
#include

#include


DFB_INPUT_DRIVER( mutouch )


#define BAUDRATE         B9600
#define OPTIMAL_BAUDRATE B19200
#define MAX_TIMEOUT      5

#define MuT_REPORT_SIZE  5
#define MuT_PACKET_SIZE  10
#define MuT_SCREENWIDTH  4096
#define MuT_SCREENHEIGHT 4096
#define MuT_MINX         0
#define MuT_MINY         0

#define MuT_LEAD_BYTE    0x01
#define MuT_TRAIL_BYTE   0x0d


#define ERROR_NOT_SUITABLE    -1110  /* The touchpanel firmware is not
                                        suitable for IMP2001 */
#define ERROR_NOT_FOUND       -1111  /* Touchpanel not found */
#define ERROR_INIT            -1112  /* Error occurred while initializing */

#define MUT_PANEL_TOUCH       0x01
#define MUT_PANEL_UNTOUCH     0x00


/* Commands */
#define MuT_RESET             "R"
#define MuT_AUTOBAUD_DISABLE  "AD"
#define MuT_RESTORE_DEFAULTS  "RD"
#define MuT_QUERY             "Z"
#define MuT_FORMAT_TABLET     "FT"
#define MuT_FORMAT_RAW        "FR"
#define MuT_CALIBRATE_RAW     "CR"
#define MuT_CALIBRATE_EXT     "CX"
#define MuT_OUTPUT_IDENT      "OI"
#define MuT_UNIT_TYPE         "UT"
#define MuT_FINGER_ONLY       "FO"
#define MuT_PEN_ONLY          "PO"
#define MuT_PEN_FINGER        "PF"
#define MuT_MODE_STREAM       "MS"
#define MuT_MODE_DOWN_UP      "MDU"

/* Command reply */
#define MuT_OK                '0'
#define MuT_ERROR             '1'

/* Offsets in status byte of touch and motion reports */
#define MuT_WHICH_DEVICE      0x20
#define MuT_CONTACT           0x40

/* Identity and friends */
#define MuT_SMT3_IDENT        "Q1"
#define MuT_THRU_GLASS_IDENT  "T1"

/* Event mask */
#define MuT_PANEL_TOUCH_MASK  0x40
#define MuT_PANEL_SYNC_MASK   0x80

typedef struct __MuTData__ {
     int fd;
     DirectThread *thread;
     CoreInputDevice *device;
     unsigned short x;
     unsigned short y;
     unsigned short screen_width;
     unsigned short screen_height;
     unsigned short min_x;
     unsigned short min_y;
     unsigned char action;
} MuTData;

/* Global Variables */
static unsigned char packet[MuT_PACKET_SIZE];


static inline void __mdelay(unsigned int msec)
{
     struct timespec delay;

     delay.tv_sec = 0;
     delay.tv_nsec = msec * 1000000;
     nanosleep (&delay, NULL);
}

static inline void MuTSendPacket(int file, char *packet, unsigned char len)
{
     int res;
     unsigned char tmp_packet[MuT_PACKET_SIZE];

     direct_memcpy (&tmp_packet[1], packet, len);
     *tmp_packet = MuT_LEAD_BYTE;
     tmp_packet[len + 1] = MuT_TRAIL_BYTE;
     res = write (file, tmp_packet, len + 2);
     (void)res;
}

static inline void MuTReadPacket(int file, unsigned char *packet)
{
     int n = 0;
     int res;

     while ( n < MuT_REPORT_SIZE ) {
          res = read( file, &packet[n], 1 );
          (void)res;
          if ( (packet[0] & MuT_PANEL_SYNC_MASK) != 0) {
               n++;
          }
     }
}

static int MuTSetToOptimalCTRL(int file, unsigned long baud)
{
     unsigned char packet[3]={0,0,0};
     struct termios options;
     struct termios save_options;
     /*
     * We are now in a mode who "works" but may be not the good one !
     * So we will make a test if a "good" mode works fine ...
     */

     tcgetattr(file, &options);
     tcgetattr(file, &save_options);   // Save mode who works.
     /*
     * Send a command to change to suitable mode.
     */
     switch (baud) {
          case B19200:
               MuTSendPacket (file, "PN811", 5);
               break;
          case B9600:
               MuTSendPacket (file, "PN812", 5);
               break;
     }
     // Note answer from driver will be lost ! there is no way to catch it with some
     // USB-Serial device. we have only to wait !
     __mdelay (20);

     /*
     * We can't work on CS7 mode messages format are not the same !
     */
     options.c_cflag =  CS8 | CLOCAL | CREAD;
     /*
     * POSIX says speed is ONLY here !
     */
     cfsetospeed( &options, baud);
     cfsetispeed( &options, 0);    // Same as output.

     tcsetattr (file, TCSANOW, &options);
     __mdelay (100);
     tcflush (file, TCIFLUSH);
     /*
     * With some USB-Serial device flush may occurs after sending message and answer from driver
     * may be lost ! ... so we wait !
     */
     __mdelay (100);

     switch (baud) {
          case B19200:
               MuTSendPacket (file, "PN811", 5);
               break;
          case B9600:
               MuTSendPacket (file, "PN812", 5);
               break;
     }
     /*
     * note if someone touch screen, we have also to strip "touch" message by testing MuT_LEAD_BYTE.
     */
     __mdelay (100);
     int n = 0;
     while ( n <3 p="">          if (read( file, &packet[n], 1 ) <=0)
               break;
          if ( packet[n] == MuT_LEAD_BYTE ) {       // new start
               n = 0;
               packet[0] = MuT_LEAD_BYTE;
          }
          if ( (n==1) && (packet[1] != MuT_OK)) {
               n = 0;
               packet[0]= 0;
          }
          if ( (n==2) && (packet[2] != MuT_TRAIL_BYTE) ) {
               n = 0;
               packet[0]= 0;
          }
          if ( packet[0] == MuT_LEAD_BYTE)
               n++;
     }

     if ( n == 3 ) {
          /* Unset O_NONBLOCK */
          int flags;
          flags = fcntl( file,  F_GETFL );
          flags &= ~O_NONBLOCK;
          fcntl( file, F_SETFL, flags );
          /* Unset VTIME */
          options.c_cc[VMIN] = 1;
          options.c_cc[VTIME] = 0;
          tcsetattr (file, TCSANOW, &options);
          __mdelay (100);

          return 1;   // OK
     }
     // KO return to old termios options.
     tcsetattr (file, TCSANOW, &save_options);
     __mdelay (100);
     return 0;
}


static int MuTPollDevice(char *device)
{
     int file;
     struct termios options;
     unsigned char i, m;
     unsigned char packet[MuT_PACKET_SIZE];
     unsigned long baud[2] = {B9600, B19200};
     unsigned long misc[2] = {CS8, CS7 | CSTOPB};

     file = open (device, O_RDWR | O_NOCTTY);

     /* Set O_NONBLOCK */
     int flags;
     flags = fcntl( file,  F_GETFL );
     flags |= O_NONBLOCK;
     fcntl( file, F_SETFL, flags );


     /* Make raw I/O */
     memset (&options, 0, sizeof (struct termios));

     /* cfmakeraw(&options) */
     options.c_cc[VMIN] = 0;
     options.c_cc[VTIME] = 10;

     /* loop through the bauds */
     for (i = 0; i < 2; i++) {
          /* loop through the misc configs */
          for (m = 0; m < 2; m++) {
               options.c_cflag =  misc[m] | CLOCAL | CREAD;
               /*
               * POSIX
               */
               cfsetospeed( &options, baud[i]);
               cfsetispeed( &options, 0);
               tcsetattr (file, TCSANOW, &options);
               /* wait for some USB-Serial device */
               __mdelay (100);
               tcflush (file, TCIFLUSH);
               __mdelay (100);

               MuTSendPacket (file, MuT_QUERY, strlen (MuT_QUERY));
               /* we are in O_NONBLOCK  need wait before read  */
               __mdelay (100);

               int n = 0;
               while ( n <3 p="">                    if (read( file, &packet[n], 1 ) <=0)
                         break;
                    if ( packet[n] == MuT_LEAD_BYTE ) {       // new start
                         n = 0;
                         packet[0] = MuT_LEAD_BYTE;
                    }
                    if ( (n==1) && (packet[1] != MuT_OK)) {    // false start
                         n = 0;
                         packet[0]= 0;
                    }
                    if ( (n==2) && (packet[2] != MuT_TRAIL_BYTE) ) {  // false start
                         n = 0;
                         packet[0]= 0;
                    }
                    if ( packet[0] == MuT_LEAD_BYTE)
                         n++;
               }

               if ( n == 3 ) {


                    if (MuTSetToOptimalCTRL (file, B19200)) {
                         return file;
                    }
                    else if (MuTSetToOptimalCTRL (file, B9600)) {
                         return file;
                    }
                    else return ERROR_NOT_SUITABLE;
               }
          }
     }
     close(file);
     return ERROR_NOT_FOUND;
}

static int MuTInitCmd(int file, char *cmd)
{
     unsigned char timeout = 0;
     unsigned char packet[MuT_PACKET_SIZE];

     do {
          MuTSendPacket (file, cmd, strlen (cmd));

          /*
          * Strip out 'touch" message
          */
          int n = 0;
          while ( n <3 p="">               if (read( file, &packet[n], 1 ) <=0)
                    break;
               if ( packet[0] == MuT_LEAD_BYTE)
                    n++;
          }

          timeout++;
          if (timeout >= MAX_TIMEOUT)
               return ERROR_INIT;
     } while (packet[1] != MuT_OK);

     return 1;
}

static inline int MuTInitialize(int file)
{
     if (!MuTInitCmd (file, MuT_RESET))
          return 0;
     if (!MuTInitCmd (file, MuT_FINGER_ONLY))
          return 0;
     if (!MuTInitCmd (file, MuT_MODE_DOWN_UP))
          return 0;
     if (!MuTInitCmd (file, MuT_FORMAT_TABLET))
          return 0;

     return 1;
}

static int MuTOpenDevice(char *device)
{
     int fd;
     int res;

     fd = MuTPollDevice (device);
     if ((res = MuTInitialize (fd)) == 0) {
          close (fd);
          return res;
     }

     return fd;
}

#define WORD_ASSEMBLY(byte1, byte2) (((byte2) << 7) | (byte1))
static int MuTGetEvent(MuTData *event)
{
     MuTReadPacket(event->fd, packet);
   
     /* Sync bit always must be set to 1 */
     if ((*packet & MuT_PANEL_SYNC_MASK) == 0)
          return 0;
   
     if (*packet & MuT_PANEL_TOUCH_MASK)
          event->action = MUT_PANEL_TOUCH;
     else
          event->action = MUT_PANEL_UNTOUCH;

     event->x = (event->screen_width *
                 WORD_ASSEMBLY(packet[1], packet[2])) / 16383;
     event->y = (event->screen_height *
                 WORD_ASSEMBLY(packet[3], packet[4])) / 16383;

     if (event->min_x)
          event->x = event->min_x - event->x;
     if (event->min_y)
          event->y = event->min_y - event->y;

     return 1;
}

/* The main routine for MuTouch */
static void *MuTouchEventThread(DirectThread *thread, void *driver_data)
{
     MuTData *data = (MuTData *) driver_data;

     /* Read data */
     while (1) {
          DFBInputEvent evt;

          if (!MuTGetEvent (data))
               continue;
          direct_thread_testcancel (thread);

          /* Dispatch axis */
          evt.type    = DIET_AXISMOTION;
          evt.flags   = DIEF_AXISABS;
          evt.axis    = DIAI_X;
          evt.axisabs = data->x;
          dfb_input_dispatch (data->device, &evt);

          evt.type    = DIET_AXISMOTION;
          evt.flags   = DIEF_AXISABS;
          evt.axis    = DIAI_Y;
          evt.axisabs = data->y;
          dfb_input_dispatch (data->device, &evt);

          /* Dispatch touch event */
          switch (data->action) {
               case MUT_PANEL_TOUCH:
                    evt.type = DIET_BUTTONPRESS;
                    break;
               case MUT_PANEL_UNTOUCH:
                    evt.type = DIET_BUTTONRELEASE;
                    break;
          }

          evt.flags  = DIEF_NONE;
          evt.button = DIBI_LEFT;

          dfb_input_dispatch (data->device, &evt);
          direct_thread_testcancel (thread);
     }

     return NULL;
}

/* exported symbols */

static int driver_get_available( void )
{
     int fd;

     if (!dfb_config->mut_device)
          return 0;

     fd = MuTOpenDevice (dfb_config->mut_device);
     if (fd < 0)
          return 0;

     close(fd);

     return 1;
}

static void driver_get_info( InputDriverInfo *info )
{
     /* fill driver info structure */
     snprintf(info->name, DFB_INPUT_DRIVER_INFO_NAME_LENGTH,
              "MuTouch" );
     snprintf(info->vendor, DFB_INPUT_DRIVER_INFO_VENDOR_LENGTH,
              "Microtouch" );

     info->version.major = 0;
     info->version.minor = 3;
}

static DFBResult driver_open_device(CoreInputDevice *device,
                                    unsigned int number,
                                    InputDeviceInfo *info,
                                    void **driver_data)
{
     int fd;
     MuTData *data;

     /* open device */
     fd = MuTOpenDevice (dfb_config->mut_device);
     D_INFO("MuTouch:driver_open_device %s fd %d\n", dfb_config->mut_device,fd);

     if (fd < 0) {
          return DFB_INIT;
     }

     data = D_CALLOC (1, sizeof(MuTData));
     if (!data) {
          close (fd);
          return D_OOM ();
     }

     data->fd     = fd;
     data->device = device;

     /* Must define the correct resolution of screen */
     data->screen_width  = MuT_SCREENWIDTH;
     data->screen_height = MuT_SCREENHEIGHT;

     /* The following variable are defined to adjust the orientation of
      * the touchscreen. Variables are either max screen height/width or 0.
      */
     data->min_x = MuT_MINX;
     data->min_y = MuT_MINY;

     /* fill device info structure */
     snprintf(info->desc.name, DFB_INPUT_DEVICE_DESC_NAME_LENGTH,
              "MuTouch");
     snprintf(info->desc.vendor, DFB_INPUT_DEVICE_DESC_VENDOR_LENGTH,
              "Microtouch");

     info->prefered_id     = DIDID_MOUSE;
     info->desc.type       = DIDTF_MOUSE;
#ifndef DIRECTFB_DISABLE_DEPRECATED
     info->desc.caps       = DICAPS_AXES | DICAPS_BUTTONS;
#else
     info->desc.caps       = DIDCAPS_AXES | DIDCAPS_BUTTONS;
#endif
     info->desc.max_axis   = DIAI_Y;
     info->desc.max_button = DIBI_LEFT;

     /* start input thread */
     data->thread = direct_thread_create (DTT_INPUT, MuTouchEventThread, data, "MuTouch Input");

     /* set private data pointer */
     *driver_data = data;

     return DFB_OK;
}

/*
 * Fetch one entry from the device's keymap if supported.
 */
static DFBResult driver_get_keymap_entry(CoreInputDevice *device,
                                         void        *driver_data,
                                         DFBInputDeviceKeymapEntry *entry)
{
     return DFB_UNSUPPORTED;
}

static void driver_close_device(void *driver_data)
{
     MuTData *data = (MuTData *)driver_data;

     /* stop input thread */
     direct_thread_cancel (data->thread);
     direct_thread_join (data->thread);
     direct_thread_destroy (data->thread);

     /* close device */
     close (data->fd);

     /* free private data */
     D_FREE (data);
}





6/01/2013

visual studio 2012 intellisense off


Turn off intellisense off.

Tools --> Options --> Text Editor  --> Advanced

Disable intellisense true
Disable Database true