Programming/C++ STL2016. 7. 11. 13:14

도대체 객체지향이 머길래 IF를 없앨수 있나 라고 글들을 찾아 보니..

객체 타입에 따라서 자동화 되어 버린(?) C로 치면 모델병 미친듯한 if문에서

조금은 해방될 수 있다 정도로 이해하면 되려나?


논리 조거식 조차도 없애야 한다는 줄 알았네 ㄷㄷㄷ


[링크 : https://kldp.org/node/31629]

[링크 : http://alankang.tistory.com/249]

    [링크 : http://silverktk.tistory.com/353]

[링크 : http://www.gpgstudy.com/forum/viewtopic.php?t=7803]

'Programming > C++ STL' 카테고리의 다른 글

cpp dlopen / gcc -l  (0) 2016.07.12
cpp thread.... / pthread  (0) 2016.07.11
cpp 클래스 구성  (0) 2016.07.11
cpp enum in class  (0) 2016.07.01
cpp const  (0) 2016.06.22
Posted by 구차니
Programming/C++ STL2016. 7. 11. 11:28

좋은 내용들이 있어서 저장

Shape::Shape (const Point center,

const int color)

{

_center = center;

_color = color;

}


Shape::Shape (const Pointer center,

const int color)

: _center(center)

, _color (color)

{


[링크 : http://ogoons.tistory.com/59]


상식을 깨는(!)

초기화를 위해 constructor에 너무 많은걸 넣지 말라라던가(객체 생성시 오버헤드로 인해 초기화 연산자로?)

등등?

'Programming > C++ STL' 카테고리의 다른 글

cpp thread.... / pthread  (0) 2016.07.11
객체지향과 if문?  (0) 2016.07.11
cpp enum in class  (0) 2016.07.01
cpp const  (0) 2016.06.22
const 멤버 변수 초기화(member variable initializer)  (0) 2016.06.22
Posted by 구차니
게임/c&c generals2016. 7. 10. 21:04

역시 돈은 위대하다?



아무생각없이 계속하다가 핵 맞음 ㅠㅠ


'게임 > c&c generals' 카테고리의 다른 글

c&c generals zero hour - usa 1  (0) 2016.07.16
c&c generals - usa 7  (0) 2016.07.15
c&c generals - usa 5  (0) 2016.07.09
c&c generals - usa 4  (0) 2016.07.09
c&c generals - usa 3  (0) 2016.07.09
Posted by 구차니
embeded/raspberry pi2016. 7. 10. 16:18

어딜 좀 더 수정해야하려나..


1. 거리가 짧아지면 응답이 빨리 되니 짧을때는 더 빠르게 거리 측정

2. openMP나 thread이용 병렬처리

3. 클래스화?

4. 인터럽트 사용?


$ cat temp_ss.c

/*

 *  dht11.c:

 *      Simple test program to test the wiringPi functions

 *      DHT11 test

 */


#include <wiringpi.h>


#include <stdio.h>

#include <stdlib.h>

#include <stdint.h>

#include <sys/time.h>


#define TRIG_PIN        4

#define ECHO_PIN        5


float mach = 34300.0;


void read_sr04_dat()

{

        int counter = 0;

        struct timeval start_point, end_point;

        double operating_time;

        double len;


        pinMode(TRIG_PIN, OUTPUT);

        pinMode(ECHO_PIN, INPUT);

        digitalWrite(TRIG_PIN, LOW);

//      delay(500); // 500 msec


        digitalWrite(TRIG_PIN, HIGH);

        delayMicroseconds( 10 );

        digitalWrite(TRIG_PIN, LOW);


        while ( digitalRead(ECHO_PIN) == LOW)

        {

                counter++;

                delayMicroseconds( 1 );

                if ( counter == 38000 )

                {

                        return;

                }

        }

        gettimeofday(&start_point, NULL);



        while ( digitalRead(ECHO_PIN) == HIGH)

        {

                counter++;

                delayMicroseconds( 1 );

                if ( counter == 38000 )

                {

                        return;

                }

        }

        gettimeofday(&end_point, NULL);


        operating_time = (double)(end_point.tv_sec)+(double)(end_point.tv_usec)/1000000.0-(double)(start_point.tv_sec)-(double)(start_point.tv_usec)/1000000.0;

        len = operating_time * mach / 2;


        printf("%f sec %4.2f cm %d\n",operating_time, len, counter);

}


#define MAXTIMINGS      85

#define DHTPIN          7

int dht11_dat[5] = { 0, 0, 0, 0, 0 };


void read_dht11_dat()

{

        uint8_t laststate       = HIGH;

        uint8_t counter         = 0;

        uint8_t j               = 0, i;

        float   f; /* fahrenheit */


        dht11_dat[0] = dht11_dat[1] = dht11_dat[2] = dht11_dat[3] = dht11_dat[4] = 0;


        /* pull pin down for 18 milliseconds */

        pinMode( DHTPIN, OUTPUT );

        digitalWrite( DHTPIN, LOW );

        delay( 18 );

        /* then pull it up for 40 microseconds */

        digitalWrite( DHTPIN, HIGH );

        delayMicroseconds( 40 );

        /* prepare to read the pin */

        pinMode( DHTPIN, INPUT );



        /* detect change and read data */

        for ( i = 0; i < MAXTIMINGS; i++ )

        {

                counter = 0;

                while ( digitalRead( DHTPIN ) == laststate )

                {

                        counter++;

                        delayMicroseconds( 1 );

                        if ( counter == 255 )

                        {

                                break;

                        }

                }

                laststate = digitalRead( DHTPIN );


                if ( counter == 255 )

                        break;


                /* ignore first 3 transitions */

                if ( (i >= 4) && (i % 2 == 0) )

                {

                        /* shove each bit into the storage bytes */

                        dht11_dat[j / 8] <<= 1;

                        if ( counter > 16 )

                                dht11_dat[j / 8] |= 1;

                        j++;

                }

        }


        /*

         * check we read 40 bits (8bit x 5 ) + verify checksum in the last byte

         * print it out if data is good

         */

        if ( (j >= 40) &&

             (dht11_dat[4] == ( (dht11_dat[0] + dht11_dat[1] + dht11_dat[2] + dht11_dat[3]) & 0xFF) ) )

        {

                f = dht11_dat[2] * 9. / 5. + 32;

                printf( "Humidity = %d.%d %% Temperature = %d.%d *C (%.1f *F)\n",

                        dht11_dat[0], dht11_dat[1], dht11_dat[2], dht11_dat[3], f );


                printf("%f -> ",mach);

                mach = 33150 + (60 * dht11_dat[2]);

                printf("%f\n",mach);

        }else  {


                f = dht11_dat[2] * 9. / 5. + 32;

                printf( "Humidity = %d.%d %% Temperature = %d.%d *C (%.1f *F) ",

                                                dht11_dat[0], dht11_dat[1], dht11_dat[2], dht11_dat[3], f );


                printf( "- Data not good, skip j[%d] par[%d] calc[%d]\n",

                j, dht11_dat[4], (dht11_dat[0] + dht11_dat[1] + dht11_dat[2] + dht11_dat[3]) & 0xFF

                 );

        }

}


int main( void )

{

        unsigned char tempcount = 0;


        if ( wiringPiSetup() == -1 )

                exit( 1 );


        while ( 1 )

        {

                        if(tempcount % 10 == 0)

                                read_dht11_dat();

                        tempcount++;


                        read_sr04_dat();


                delay( 1000 ); /* wait 1sec to refresh */

        }


        return(0);

}  


'embeded > raspberry pi' 카테고리의 다른 글

freeRTOS on rpi  (0) 2016.07.18
redmine 백업  (0) 2016.07.14
초음파 센서 wiring pi 버전  (0) 2016.07.10
초음파/온습도 센서 데이터 시트 복사  (0) 2016.07.10
rpi gstreamer mux  (0) 2016.06.28
Posted by 구차니
embeded/raspberry pi2016. 7. 10. 12:31

파이썬만 보여서 대충 바꿔봄.

대충.. 2cm ~ 400cm로 제한을 줘야하나..

데이터 시트는 아래 링크 참조해서 작성

[링크 : https://docs.google.com/document/d/1Y-yZnNhMYy7rwhAgyL_pfa39RsB-x2qR4vP8saG73rE/edit]


시간재는건 아래 참조

[링크 : http://hwangdo83.tistory.com/123]


$ cat sr04.c

/*

 *  dht11.c:

 *      Simple test program to test the wiringPi functions

 *      DHT11 test

 */


#include <wiringPi.h>


#include <stdio.h>

#include <stdlib.h>

#include <stdint.h>

#include <sys/time.h>


#define TRIG_PIN        4

#define ECHO_PIN        5


void read_sr04_dat()

{

        int counter = 0;

        struct timeval start_point, end_point;

        double operating_time;

        double len;


        pinMode(TRIG_PIN, OUTPUT);

        pinMode(ECHO_PIN, INPUT);

        digitalWrite(TRIG_PIN, LOW);

//      delay(500); // 500 msec


        digitalWrite(TRIG_PIN, HIGH);

        delayMicroseconds( 10 );

        digitalWrite(TRIG_PIN, LOW);



        while ( digitalRead(ECHO_PIN) == LOW)

        {

                counter++;

                delayMicroseconds( 1 );

                if ( counter == 38000 )

                {

                        return;

                }

        }

        gettimeofday(&start_point, NULL);


        while ( digitalRead(ECHO_PIN) == HIGH)

        {

                counter++;

                delayMicroseconds( 1 );

                if ( counter == 38000 )

                {

                        return;

                }

        }


        gettimeofday(&end_point, NULL);


        operating_time = (double)(end_point.tv_sec)+(double)(end_point.tv_usec)/1000000.0-(double)(start_point.tv_sec)-(double)(start_point.tv_usec)/1000000.0;

        len = operating_time * 34300 / 2;


        printf("%f sec %4.2f cm %d\n",operating_time, len, counter);

}


int main( void )

{

        if ( wiringPiSetup() == -1 )

                exit( 1 );


        while ( 1 )

        {

                read_sr04_dat();

                delay( 100 ); /* wait 1sec to refresh */

        }


        return(0);



한번 보냈는데 못 재면 이상한 값을 뱉는건 왜그럴까나..

'embeded > raspberry pi' 카테고리의 다른 글

redmine 백업  (0) 2016.07.14
초음파 거리 + 온/습도 센서  (0) 2016.07.10
초음파/온습도 센서 데이터 시트 복사  (0) 2016.07.10
rpi gstreamer mux  (0) 2016.06.28
beowulf / openMPI  (0) 2016.06.28
Posted by 구차니
embeded/raspberry pi2016. 7. 10. 10:59

백업용


초음파 센서 HC-SR04

           - Power Supply :+5V DC

           - Quiescent Current : <2mA

           - Working Currnt: 15mA

           - Effectual Angle: <15°

           - Ranging Distance : 2cm – 400 cm/1" - 13ft

           - Resolution : 0.3 cm

           - Measuring Angle: 30 degree

           - Trigger Input Pulse width: 10uS

           - Dimension: 45mm x 20mm x 15mm

[링크 : http://eleparts.co.kr/EPXF6C83]


온/습도 센서

어.. 의외로 온도 범위가 좁다?


Specifications

Temperature measuring range: 0℃~ 50℃  

Temperature tolerance: ±2℃ 

Humidity measuring range: 20% ~ 95% (0℃ ~ 50℃) 

Humidity tolerance: ±5% 

Dimension: 29.0mm * 18.0mm 

Mounting holes size: 2.0mm


Applications

Ambient temperature and humidity detection


How to Use

In the case of working with a MCU:


-VCC ↔ 3.3V ~ 5.5V 

-GND ↔ power supply ground 

-DOUT ↔ MCU.IO

[링크 : http://eleparts.co.kr/EPXF43N9]

'embeded > raspberry pi' 카테고리의 다른 글

초음파 거리 + 온/습도 센서  (0) 2016.07.10
초음파 센서 wiring pi 버전  (0) 2016.07.10
rpi gstreamer mux  (0) 2016.06.28
beowulf / openMPI  (0) 2016.06.28
redmine on raspberrypi  (9) 2016.06.23
Posted by 구차니
게임/c&c generals2016. 7. 9. 23:09

조금.. 빡센 미션


 UN 대사가 탄 차가 폭파당하고

다리를 건너오는 GLA를 막으라는데

여기서 최대한 오래 끌면서 유닛을 뽑아주는게 유리..

병원을 점령하면 병사들 모두 자동 치료!

다리 건너 GLA를 괴멸시키면 댐을 터트려 길을 막는다.

유닛 조금 주는데 돈이 없는 상황이라. 털리고..

스커드 미사일 맞고 멘붕.. 그래서 다시 시작

스샷에는 잘 안나오지만.. 빡쳐서 밀기 전에 돈 다 뽑아내고 코만치 10대 넘게 해서

한방에 스커드 발사대 파괴시도했으나 실패.. 두번에 파괴하고

GLA 점령해서 방어선 구축 및 유닛 뽑아두니 편리


'게임 > c&c generals' 카테고리의 다른 글

c&c generals - usa 7  (0) 2016.07.15
c&c generals - usa 6  (0) 2016.07.10
c&c generals - usa 4  (0) 2016.07.09
c&c generals - usa 3  (0) 2016.07.09
c&c generals - usa 2  (0) 2016.07.08
Posted by 구차니
게임/c&c generals2016. 7. 9. 21:45

노르망디 상륙작전이 이런 느낌이었을려나?

토마호크를 최대한 살려야 하는데 간간히 오는 자폭테러가 자쯩..

아무튼 처음에는 토마호크로 벙커와 진지를 격파하고

그 다음에는 험머 + 로켓 3 + 저격 1 이런식으로 인원 채워서 하면 끗


'게임 > c&c generals' 카테고리의 다른 글

c&c generals - usa 6  (0) 2016.07.10
c&c generals - usa 5  (0) 2016.07.09
c&c generals - usa 3  (0) 2016.07.09
c&c generals - usa 2  (0) 2016.07.08
c&c generals - usa 1  (0) 2016.07.08
Posted by 구차니
게임/c&c generals2016. 7. 9. 21:44

아군보호 계획.. 이라고 하면되려나?

아래쪽 길에서 계속 아군이 오고 뒤를 따라 GLA가 온다.



이유는 모르겠지만.. war factory가 건설불가..

그런 이유로 보병으로 싸우던가(나의 사랑 험비가 안되다니!!)

코만치를 왕창 뽑는수 밖에...

우측에 정유기지 두개 있으니

후딱 먹어주면 자금줄 확보가 무난!

'게임 > c&c generals' 카테고리의 다른 글

c&c generals - usa 5  (0) 2016.07.09
c&c generals - usa 4  (0) 2016.07.09
c&c generals - usa 2  (0) 2016.07.08
c&c generals - usa 1  (0) 2016.07.08
c&c general - gla 7  (0) 2016.07.03
Posted by 구차니
Linux2016. 7. 9. 11:09


$ grep --exclude-dir=".svn"

[링크 : http://stackoverflow.com/questions/1491514/exclude-svn-directories-from-grep]


svn 관리용 디렉토리 무시하니 편하네

'Linux' 카테고리의 다른 글

strip 된 so 파일의 symbol 보기  (0) 2016.09.21
sysbench  (0) 2016.09.04
nptl - Native POSIX Threads Library  (0) 2016.06.27
cp -Lr  (0) 2016.06.14
libxml 크로스컴파일. (shared library)  (0) 2016.06.13
Posted by 구차니