5/29/2013

Serial Port (RS232C) WaitCommEvent Timeout Method.


linux - use select time out check.

win32 - use overlapped method. 

Open Serial Port Option by Overlapped.

HANDLE SPortHandle=
CreateFile (.. .. FILE_FLAG_OVERLAPPED | FILE_ATTRIBUTE_NORMAL,NULL);

//
// check serial port data
//
int isindataserialport(Cport , msec )
{
    int ret=1; // true , false;
    DWORD fdwCommMask;
    SetCommMask (Cport,/*EV_CTS | EV_DSR| */ EV_RXCHAR);
    #ifdef _WIN32_WCE
        WaitCommEvent (Cport, &fdwCommMask, 0);
    #else
        OVERLAPPED OverLapped;
        memset ((char *)&OverLapped, 0, sizeof(OVERLAPPED));
        OverLapped.hEvent = CreateEvent (NULL, TRUE, TRUE, 0);
        if (!WaitCommEvent (Cport, &fdwCommMask, &OverLapped))
       {
            if (GetLastError() == ERROR_IO_PENDING)
            {
                if(WaitForSingleObject (OverLapped.hEvent,(DWORD) msec) != WAIT_OBJECT_0)
                {
                     ret=0;
                }
            }
        }
        CloseHandle(OverLapped.hEvent);
    #endif

    if((fdwCommMask & EV_RXCHAR) != EV_RXCHAR)
   {
        ret=0;
    }
    return ret;
}



gain root permission android

//
// method 1
//

Process p; 
try {
   p = Runtime.getRuntime().exec("su"); 

   DataOutputStream os = new DataOutputStream(p.getOutputStream()); 
   os.writeBytes("echo \"root?\" >/data/temporary.txt\n");


   os.writeBytes("exit\n"); 
   os.flush(); 
   try { 
      p.waitFor(); 
           if (p.exitValue() != 255) { 
              // TODO Code to run on success 
              toastMessage("root"); 
           } 
           else { 
               // TODO Code to run on unsuccessful 
               toastMessage("not root"); 
           } 
   } catch (InterruptedException e) { 
      // TODO Code to run in interrupted exception 
       toastMessage("not root"); 
   } 
} catch (IOException e) { 
   // TODO Code to run in input/output exception 
    toastMessage("not root"); 

5/25/2013

Android get Device ID & MAC address




-- getDeviceID()
TelephonyManager

public String getDeviceId ()

Return null if device ID is not available.
Requires Permission: READ_PHONE_STATE

-- MAC address

permission.

"android.permission.INTERNET">
"android.permission.ACCESS_NETWORK_STATE">
 
ConnectivityManager manager =
    (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);

 

NetworkInfo ni = manager.getActiveNetworkInfo();
String netname = ni.getTypeName();
if (netname.equals("MOBILE")) {
    Log.d(TAG, "Network - > " + netname);
}else{
    Log.d(TAG, "Network - > " + netname);
}

WifiInfo wifiInfo = mWifiMgr.getConnectionInfo();
Log.d(TAG,"MAC:"+wifiInfo.getMacAddress());


5/24/2013

진격의 커피잔

ㅋㅋ

 

세숫대야 커피 잔 등장 ‘시선 집중’



직장인 남성을 위한 제품들을 판매하는 미국의 한 인터넷 쇼핑몰에 커다란 커피잔이 등장해 화제다.

세숫대야 커피 잔이라도 불러도 될 이 골리앗 커피 잔은 지름이 25cm이고 무게는 4.5kg 가량이다. 보통 커피 잔의 20배 용량이라고 하니 커피를 채우고 들고 있으면 이두박근이 금방 아플 것이다.

판매 사이트에서는 이 골리앗 커피 잔이 어떤 커피 중독자도 만족시킬 것이라고 자신한다. 또 고객 앞에 내놓으면 큰 웃음을 터뜨리게 한다고. 해외 네티즌 중 커피를 좋아하는 이들의 도전욕구를 자극하는 세숫대야 커피 잔은 가격이 40달러이다.
원문주소
http://news.naver.com/main/read.nhn?mid=hot&sid1=104&cid=845614&iid=22043897&oid=105&aid=0000019869

5/22/2013

prevent duplication message Toast dialog android

Android에서 Toast를 사용할 때, 메시지 중복 지속되는 경우 방지.
  
Toast 변수를 선언한다. 
 
 
public static Toast mToast;
 
 onCreate() 또는 적절한 함수에서  1회 초기화한다. Toast.makeText()
{ 
    ...
    mToast = Toast.makeText(this, "null", Toast.LENGTH_SHORT); 
    ...
}
 
 
mToast 사용.
Func()
{
    mToast.setText(show this text); 
    mToast.show(); 
}
 
 
// 다른 클래스 ..모듈등에서 사용하기 편하게 유틸리티 클래스 생성후 사용해도 무방하다.
 

class appGlobalUtil 
{ 
    public static Toast mToast; 
 
    public  toast_message(  message)
    {
        mToast.setText(message); 
        mToast.show(); 
    }

 
} 

5/17/2013

dynamic allocation 3d c/c++ pointer variable.


// method 1
//
int _objCache[100][200][300];


 // method 2

int ***_objCache;
 

// allocation.

int x;
int y;

_objCache = new int ** [100];

for(x = 0; x < 100; x++)
{
        _objCache[x] = new int * [200];

        for(y = 0; y < 200; y++)
        {
                _objCache[x][y] = new int [300];
        }
}

// deallocation. 

for(x = 0; x < 100; x++)
{
        for(y = 0; y < 200; y++)
        {
                delete [] _objCache[x][y];
        }
}

for(x = 0; x < 100; x++)
{
        delete [] _objCache[x];
}

delete [] _objCache;

//////

Point-In-Polygon Algorithm


very simple and smart Algorithm.

http://alienryderflex.com/polygon/

Figure 1

Figure 1 demonstrates a typical case of a severely concave polygon with 14 sides.  The red dot is a point which needs to be tested, to determine if it lies inside the polygon.

The solution is to compare each side of the polygon to the Y (vertical) coordinate of the test point, and compile a list of nodes, where each node is a point where one side crosses the Y threshold of the test point. In this example, eight sides of the polygon cross the Y threshold, while the other six sides do not.  Then, if there are an odd number of nodes on each side of the test point, then it is inside the polygon; if there are an even number of nodes on each side of the test point, then it is outside the polygon.  In our example, there are five nodes to the left of the test point, and three nodes to the right.  Since five and three are odd numbers, our test point is inside the polygon.

(Note:  This algorithm does not care whether the polygon is traced in clockwise or counterclockwise fashion.)


Figure 2

Figure 2 shows what happens if the polygon crosses itself.  In this example, a ten-sided polygon has lines which cross each other.  The effect is much like “exclusive or,” or XOR as it is known to assembly-language programmers.  The portions of the polygon which overlap cancel each other out.  So, the test point is outside the polygon, as indicated by the even number of nodes (two and two) on either side of it.


Figure 3

In Figure 3, the six-sided polygon does not overlap itself, but it does have lines that cross.  This is not a problem; the algorithm still works fine.


Figure 4

Figure 4 demonstrates the problem that results when a vertex of the polygon falls directly on the Y threshold.  Since sides a and b both touch the threshold, should they both generate a node?  No, because then there would be two nodes on each side of the test point and so the test would say it was outside of the polygon, when it clearly is not!

The solution to this situation is simple.  Points which are exactly on the Y threshold must be considered to belong to one side of the threshold.  Let’s say we arbitrarily decide that points on the Y threshold will belong to the “above” side of the threshold.  Then, side a generates a node, since it has one endpoint below the threshold and its other endpoint on-or-above the threshold.  Side b does not generate a node, because both of its endpoints are on-or-above the threshold, so it is not considered to be a threshold-crossing side.


Figure 5

Figure 5 shows the case of a polygon in which one of its sides lies entirely on the threshold.  Simply follow the rule as described concerning Figure 4.  Side c generates a node, because it has one endpoint below the threshold, and its other endpoint on-or-above the threshold.  Side d does not generate a node, because it has both endpoints on-or-above the threshold.  And side e also does not generate a node, because it has both endpoints on-or-above the threshold.


Figure 6

Figure 6 illustrates a special case brought to my attention by John David Munch of Cal Poly.  One interior angle of the polygon just touches the Y-threshold of the test point.  This is OK.  In the upper picture, only one side (hilited in red) generates a node to the left of the test point, and in the bottom example, three sides do.  Either way, the number is odd, and the test point will be deemed inside the polygon.


Polygon Edge

If the test point is on the border of the polygon, this algorithm will deliver unpredictable results; i.e. the result may be “inside” or “outside” depending on arbitrary factors such as how the polygon is oriented with respect to the coordinate system.  (That is not generally a problem, since the edge of the polygon is infinitely thin anyway, and points that fall right on the edge can go either way without hurting the look of the polygon.)


C Code Sample

//  Globals which should be set before calling this function:
//
//  int    polySides  =  how many corners the polygon has
//  float  polyX[]    =  horizontal coordinates of corners
//  float  polyY[]    =  vertical coordinates of corners
//  float  x, y       =  point to be tested
//
//  (Globals are used in this example for purposes of speed.  Change as
//  desired.)
//
//  The function will return YES if the point x,y is inside the polygon, or
//  NO if it is not.  If the point is exactly on the edge of the polygon,
//  then the function may return YES or NO.
//
//  Note that division by zero is avoided because the division is protected
//  by the "if" clause which surrounds it.


bool pointInPolygon() {

  int   i, j=polySides-1 ;
  bool  oddNodes=NO      ;

  for (i=0; i     if (polyY[i]=y
    ||  polyY[j]=y) {
      if (polyX[i]+(y-polyY[i])/(polyY[j]-polyY[i])*(polyX[j]-polyX[i])         oddNodes=!oddNodes; }}
    j=i; }

  return oddNodes; }


Here’s an efficiency improvement provided by Nathan Mercer.  The blue code eliminates calculations on sides that are entirely to the right of the test point.  Though this might be occasionally slower for some polygons, it is probably faster for most.

//  Globals which should be set before calling this function:
//
//  int    polySides  =  how many corners the polygon has
//  float  polyX[]    =  horizontal coordinates of corners
//  float  polyY[]    =  vertical coordinates of corners
//  float  x, y       =  point to be tested
//
//  (Globals are used in this example for purposes of speed.  Change as
//  desired.)
//
//  The function will return YES if the point x,y is inside the polygon, or
//  NO if it is not.  If the point is exactly on the edge of the polygon,
//  then the function may return YES or NO.
//
//  Note that division by zero is avoided because the division is protected
//  by the "if" clause which surrounds it.


bool pointInPolygon() {

  int   i, j=polySides-1 ;
  bool  oddNodes=NO      ;

  for (i=0; i     if ((polyY[i]< y && polyY[j]>=y
    ||   polyY[j]< y && polyY[i]>=y)
    &&  (polyX[i]<=x || polyX[j]<=x)) {
      if (polyX[i]+(y-polyY[i])/(polyY[j]-polyY[i])*(polyX[j]-polyX[i])         oddNodes=!oddNodes; }}
    j=i; }

  return oddNodes; }


Here’s another efficiency improvement provided by Lascha Lagidse.  The inner “if” statement is eliminated and replaced with an exclusive-OR operation.

//  Globals which should be set before calling this function:
//
//  int    polySides  =  how many corners the polygon has
//  float  polyX[]    =  horizontal coordinates of corners
//  float  polyY[]    =  vertical coordinates of corners
//  float  x, y       =  point to be tested
//
//  (Globals are used in this example for purposes of speed.  Change as
//  desired.)
//
//  The function will return YES if the point x,y is inside the polygon, or
//  NO if it is not.  If the point is exactly on the edge of the polygon,
//  then the function may return YES or NO.
//
//  Note that division by zero is avoided because the division is protected
//  by the "if" clause which surrounds it.


bool pointInPolygon() {

  int   i, j=polySides-1 ;
  bool  oddNodes=NO      ;

  for (i=0; i     if ((polyY[i]< y && polyY[j]>=y
    ||   polyY[j]< y && polyY[i]>=y)
    &&  (polyX[i]<=x || polyX[j]<=x)) {
      oddNodes^=(polyX[i]+(y-polyY[i])/(polyY[j]-polyY[i])*(polyX[j]-polyX[i])     j=i; }

  return oddNodes; }


Integer Issue

What if you’re trying to make a polygon like the blue one below (Figure 7), but it comes out all horizontal and vertical lines, like the red one?  That indicates that you have defined some of your variables as integers instead of floating-point.  Check your code carefully to ensure that your test point and all the corners of your polygon are defined as, and passed as, floating-point numbers.

   Figure 7

5/16/2013

orientation event fix - android


Reacting to Configuration Changes

Start be adding the android:configChanges node to your Activity's manifest node

android:configChanges="keyboardHidden|orientation"

setContentView to force the GUI layout to be re-done in the new orientation.


@Override
public void onConfigurationChanged(Configuration newConfig) {
  super.onConfigurationChanged(newConfig);
  setContentView(R.layout.myLayout);
}

5/01/2013

ELO / MTouch Serial Interface direct control.



Development sequence.

1. Serial Port Open ( linux / win32 )

serial port setting.

elo -- rx/tx

mtouch - rx/tx  -- and cts/rts 


2. Detect ELO or MTouch

reference serial protocol from the "xinput-calibrate"  "DirectFB"  "touchcal"

3. calibrate minX,maxX,minY,maxY

calibrate UI  X11 Window / Win32 Window

4. use touch.

current status - developing.

linux - almsot finished.
win32 - win32 ui development.