Posted by 구차니
회사일/USB PD2024. 12. 3. 14:34

PDP Rating
• Power Delivery Power Rating
[링크 : https://usb.org/sites/default/files/D2T2-1%20-%20USB%20Power%20Delivery.pdf]


PDO(Power Data Object)
APDO(Augmented Power Data Object) = PPS(Programmable Power supply)
[링크 : https://smartchoice.kr/usb-고속충전의-종류와-usb-pd-충전에-대해-자세히-알아보자/]

 

AMS (Atomic message sequence)

[링크 : https://www.st.com/resource/en/user_manual/um2552-managing-usb-power-delivery-systems-with-stm32-microcontrollers-stmicroelectronics.pdf]

 

PDO는 또 머냐...

[링크 : https://velog.io/@zhemdrawer/USB-PD-이해]

 

+

2024.12.08

PPS(Programmable Power Supply) 

[링크 : https://www.belkin.com/kr/support-article/?articleNum=318878]

 

USB PD 1.0 - profile

USB PD 2.0 - PDO

USB PD 3.0 - APDO / PPS

[링크 : https://namu.wiki/w/USB%20PD]

 

 

+

2024.12.13

[링크 : https://velog.io/@zhemdrawer/USB-PD-이해]

'회사일 > USB PD' 카테고리의 다른 글

i.mx8 evk uboot usb pd 메시지  (0) 2024.12.05
linux kernel USB PD 관련 검색  (0) 2024.12.04
USB PD SOP*?  (0) 2024.12.03
USB-C PTN5110 케이블 방향에 따른 데이터 차이  (0) 2024.11.27
USB PD - DRP?  (0) 2024.11.25
Posted by 구차니
회사일/USB PD2024. 12. 3. 12:45

걍 패킷을 보낸다 라는걸 죄다 SOP라고 퉁치는것 같은데

SOP

SOP'

SOP''

SOP* 이런게 나와서 헷갈리는 중..

 

SOP*
• Start of packet (SOP/SOP’/SOP’’)

[링크 : https://usb.org/sites/default/files/D2T2-1%20-%20USB%20Power%20Delivery.pdf]

 

SOP* - The Start of Frame field in a USB Power Delivery packet indicates the intended recipient of the packet.

[링크 : https://ww1.microchip.com/downloads/en/AppNotes/00001974A.pdf]

 

50h 에 TRANSMIT 이라는 레지스터가 있는데 Read / Write 이고 [2:0] 3비트는 아래의 값을 지닌댄다.

도대체 cable reset은 왜 저기서 튀어나오는걸까?

[링크 : https://www.nxp.com/docs/en/data-sheet/PTN5110.pdf]

 

각 패킷별 전송이나 응답할 녀석이 달라지는건가?

[링크 : https://www.graniteriverlabs.com/en-us/technical-blog/usb-pd-power-delivery-spec-versions]

 

 

5
Sending a USB PD message
The general steps of transmitting a SOP* message are listed below. Please consult
sections 4.7.1, 4.7.2, and 4.7.3 of the TCPC specification[3] for more detailed
implementation and examples.
• Step 0: TCPM writes the content of the message to be transmitted into the
TRANSMIT_BUFFER
• Step 1: TCPM writes to TRANSMIT requesting SOP* transmission
• Step 2: The outcome reported by the TCPC may be one of three indications after
asserting the Alert# pin:
– If the TCPC PHY layer successfully transmits the message, the TCPC sets the
Transmission Successful bit in the ALERT register.
– If the TCPC PHY layer did not get any response after retries, the TCPC sets the
Transmission Failed bit in the ALERT register.
– If the transmission was discarded due to an incoming message, the TCPC sets the
Transmission Discarded bit in the ALERT register.
• Step 3: Before requesting another transmission, the TCPM shall clear the alert by
writing a 1 to the asserted bit in the ALERT register.
When transitioning through the steps of transmitting SOP* message, TCPC may assert
ALERT.ReceiveStatus or ALERT.ReceivedHardReset bit at any time to notify that a
message was received.

[링크 : https://www.nxp.com/docs/en/application-note/AN12137.pdf]

 

위에서 4.7.1~4.7.3을 보라는데 제목만 봐서는.. 흐음..

4.7 USB PD Communication Operational Model
4.7.1 Transmitting an SOP* USB PD Message with Less than or Equal to 128 Data Bytes
4.7.2 Transmitting an SOP* USB PD Message with Greater than 128 Data Bytes
4.7.3 Transmitting a Hard Reset Message

[링크 : https://www.usb.org/sites/default/files/documents/usb-port_controller_specification_rev2.0_v1.0_0.pdf]

 

RDO (Request Data Object)

[링크 : https://www.ti.com/lit/an/slva842/slva842.pdf]

 

 

 

'회사일 > USB PD' 카테고리의 다른 글

linux kernel USB PD 관련 검색  (0) 2024.12.04
USB PD 용어 정리중  (0) 2024.12.03
USB-C PTN5110 케이블 방향에 따른 데이터 차이  (0) 2024.11.27
USB PD - DRP?  (0) 2024.11.25
TCPC, TCPM  (0) 2024.11.22
Posted by 구차니
회사일/BQ25703A2024. 12. 2. 18:00

RESET_REG랑 RESET_VINDPM을 둘다 set 하고 하니 VINDPM의 값이 변경되지 않는 현상이 발생함.

그냥 RESET_VINDPM 만 설정해주면 된다.

해당 값은 0x0B/0x0A 의 InputVoltage Register 값에 있는데

 

VBUS-1.28V 로 초기화 되는 값이라는데

반대로 보면.. 1.28V를 더해줘야 하냐.. 그게 아니라면 DC offset이 3.2V 니까(0x00) 일때 3.2V를 더해주는게 맞냐 좀 헷갈린다.

'회사일 > BQ25703A' 카테고리의 다른 글

bq25703A NVDC  (0) 2024.11.29
배터리 충전  (0) 2024.11.28
bq25703A i2c 읽기, 쓰기  (0) 2024.11.22
Posted by 구차니

node.js 이동경로  3d로 그리기 등

[링크 : https://github.com/austinbaccus/forza-telemetry/]

 

c#, 텍스트

[링크 : https://github.com/geeooff/forza-data-web]

 

M5Stack-CoreS3 기반

Horizon은 324 byte?

 if (packet.length() > 310 && packet.length() < 332) // packet length now 331 for motorsport?
                         {                                                   // Check we have a correctly-sized Forza packet. Note Horizon packets are 324 bytes, Motorsport packets are 311 bytes
                             if (packet.length() == 324)
                             {
                                //  USBSerial.println("Got Horizon packet");
                             }
                            else
                             { // Motorsport packet
                             }
                         }

[링크 : https://github.com/richstokes/Forza-TCS/tree/master]

 

python

[링크 : https://github.com/nettrom/forza_motorsport]

 

golang, 웹기반

[링크 : https://github.com/richstokes/Forza-data-tools]

'모종의 음모 > force feedback' 카테고리의 다른 글

dirt rally 2.0 telemetry udp  (0) 2024.12.08
forza horizon 4 telemetry 수정  (0) 2024.12.07
forza horizon 4, 리눅스용 c언어 대시보드  (0) 2024.11.30
forza horizon 4 data format  (0) 2024.11.20
dirt rally 2.0 motion data  (0) 2024.11.03
Posted by 구차니
프로그램 사용/ncurses2024. 12. 2. 10:22

screen - window 계층 구조인 것 같고

상자는 세로, 가로로 쓸 문자만 넣어주면 되는 듯. 터미널 사이즈에 따른 동적 변화는 따로 찾아봐야겠네.

#include <ncurses.h>

int main(void){
    initscr();
    start_color();
    init_color(1, 0, 1000, 0);      // 1번 색상(글자색): 초록색
    init_color(2, 0, 0, 1000);      // 2번 색상(배경색): 파랑색
    init_pair(1, 1, 2);             // 1번 Color pair를 초록 글자색과 파랑 배경색으로 지정
    
    WINDOW * win = newwin(20, 20, 10, 10);
    box(win, '|', '-');
    waddch(win, 'A' | COLOR_PAIR(1));   // 1번 Color pair를 적용해 문자 출력

    refresh();
    wrefresh(win);
    getch();
    endwin();
}

 

start_color() 로 색상을 사용할 수 있도록 설정하고

init_color(index, , , ,)로 팔레트를 초기화 하고

attron(attribute on), attroff(attribute off) 함수로 색상을 적용/해제 한다.

#include <ncurses.h>

int main(void){
    initscr();
    start_color();

    init_color(1, 0, 1000, 0);
    init_color(2, 0, 0, 1000);
    init_pair(1, 1, 2);

    attron(COLOR_PAIR(1));    // 출력 색상을 1번 Color pair로 변경
    printw("Hello");
    attroff(COLOR_PAIR(1));   // 속성 해제

    refresh();
    getch();
    endwin();
}

[링크 : https://magmatart.dev/development/2017/06/15/ncurses4.html]

'프로그램 사용 > ncurses' 카테고리의 다른 글

ncurses 예제  (0) 2024.11.30
ncurse  (0) 2015.04.27
Posted by 구차니

음.. 요즘 정신이 계속 없었나 적어두지도 않아서 헤매는 중

 

올해 중순에 샀다는데

내 기억으로는 연 초에 갈고는 필터가 없어서 못 갈고 있었는데

새로산 건 어디로 갔으며, 내 기억은 어떻게 되었는가..(!)

 

'개소리 왈왈 > 육아관련 주저리' 카테고리의 다른 글

아내 대장내시경  (0) 2024.11.23
실손보험 면책기간이라..  (0) 2024.11.19
내 쉬는날 하루 어디갔어?!?!  (0) 2024.11.17
오랫만에 장보기  (0) 2024.11.16
퇴원! 집이 최고여!  (2) 2024.11.10
Posted by 구차니

배틀넷

눈이 오고 그러면 산책도 힘들테니 살...까?

근데 8250원.. 흐음... 5천원이면 고민 안하고 질렀을 것 같은디...

 

스팀

NFS unbound 첨 봤는데 nfs 라니 끌리고

cities skylines는 epic에서 받은적 있으니 패스

ace combat 7은 끌리네

'게임 > 오리진&스팀&유플레이' 카테고리의 다른 글

아 몰라 질러  (1) 2024.12.17
epic 무료 게임!  (0) 2024.12.06
오늘의 게임 다운로드  (0) 2024.11.02
게임 지름 + 선물 강요  (0) 2024.10.28
daemon x machina 100% side goal 완료!  (6) 2024.10.27
Posted by 구차니

324 바이트를 받고 있고

데이터 포맷이 맞는지 모르겠지만 일단은 pause / racing은 확실한데..

가속도 값이 저게 맞나..?

324 received
let's fly
acc X 10.054599
acc Y -0.817630
acc Z 2.089930
vel X -6.518519
vel Y -0.198055
vel Z 17.591864
yaw   -2.862235
roll  -0.191706
pitch 0.158119

 

packed 하지 않으면 아래 사이즈

232 sizeof(FORZA_SLED)
332 sizeof(FORZA_DASH)

 

packed 하면 아래 사이즈

232 sizeof(FORZA_SLED)
331 sizeof(FORZA_DASH)

 

forza horizon 은 sled 보단 dash 구조체 인가?

구조체 두개를 비교해보니, 실린더 수까진 동일하고 그 이후로 추가 데이터가 들어온다.

그렇다면.. 가속도가 맞다는건데.. 도대체(?) 왜 기어랑은 브레이크는 값이 왜 안들어 올까!

[링크 : https://support.forzamotorsport.net/hc/en-us/articles/21742934024211-Forza-Motorsport-Data-Out-Documentation]

 

리눅스 / ncurses / c 니까 어디든 쉽게 이식은 가능하겠지?

 

소스코드

더보기
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <ncurses.h>

 

#define BUF_SIZE 500

 

typedef char S8;
typedef unsigned char U8;
typedef unsigned short U16;
typedef int S32;
typedef unsigned int U32;
typedef float F32;

 

typedef struct _sled_
{
// = 1 when race is on. = 0 when in menus/race stopped …
S32 IsRaceOn;

 

// Can overflow to 0 eventually
U32 TimestampMS;
F32 EngineMaxRpm;
F32 EngineIdleRpm;
F32 CurrentEngineRpm;

 

// In the car's local space; X = right, Y = up, Z = forward
F32 AccelerationX;
F32 AccelerationY;
F32 AccelerationZ;

 

// In the car's local space; X = right, Y = up, Z = forward
F32 VelocityX;
F32 VelocityY;
F32 VelocityZ;

 

// In the car's local space; X = pitch, Y = yaw, Z = roll
F32 AngularVelocityX;
F32 AngularVelocityY;
F32 AngularVelocityZ;

 

F32 Yaw;
F32 Pitch;
F32 Roll;

 

// Suspension travel normalized: 0.0f = max stretch; 1.0 = max compression
F32 NormalizedSuspensionTravelFrontLeft;
F32 NormalizedSuspensionTravelFrontRight;
F32 NormalizedSuspensionTravelRearLeft;
F32 NormalizedSuspensionTravelRearRight;

 

// Tire normalized slip ratio, = 0 means 100% grip and |ratio| > 1.0 means loss of grip.
F32 TireSlipRatioFrontLeft;
F32 TireSlipRatioFrontRight;
F32 TireSlipRatioRearLeft;
F32 TireSlipRatioRearRight;

 

// Wheels rotation speed radians/sec.
F32 WheelRotationSpeedFrontLeft;
F32 WheelRotationSpeedFrontRight;
F32 WheelRotationSpeedRearLeft;
F32 WheelRotationSpeedRearRight;

 

// = 1 when wheel is on rumble strip, = 0 when off.
S32 WheelOnRumbleStripFrontLeft;
S32 WheelOnRumbleStripFrontRight;
S32 WheelOnRumbleStripRearLeft;
S32 heelOnRumbleStripRearRight;

 

// = from 0 to 1, where 1 is the deepest puddle
F32 WheelInPuddleDepthFrontLeft;
F32 WheelInPuddleDepthFrontRight;
F32 WheelInPuddleDepthRearLeft;
F32 WheelInPuddleDepthRearRight;

 

// Non-dimensional surface rumble values passed to controller force feedback
F32 SurfaceRumbleFrontLeft;
F32 SurfaceRumbleFrontRight;
F32 SurfaceRumbleRearLeft;
F32 SurfaceRumbleRearRight;

 

// Tire normalized slip angle, = 0 means 100% grip and |angle| > 1.0 means loss of grip.
F32 TireSlipAngleFrontLeft;
F32 TireSlipAngleFrontRight;
F32 TireSlipAngleRearLeft;
F32 TireSlipAngleRearRight;

 

// Tire normalized combined slip, = 0 means 100% grip and |slip| > 1.0 means loss of grip.
F32 TireCombinedSlipFrontLeft;
F32 TireCombinedSlipFrontRight;
F32 TireCombinedSlipRearLeft;
F32 TireCombinedSlipRearRight;

 

// Actual suspension travel in meters
F32 SuspensionTravelMetersFrontLeft;
F32 SuspensionTravelMetersFrontRight;
F32 SuspensionTravelMetersRearLeft;
F32 SuspensionTravelMetersRearRight;

 

// Unique ID of the car make/model
S32 CarOrdinal;

 

// Between 0 (D -- worst cars) and 7 (X class -- best cars) inclusive
S32 CarClass;

 

// Between 100 (worst car) and 999 (best car) inclusive
S32 CarPerformanceIndex;

 

// 0 = FWD, 1 = RWD, 2 = AWD
S32 DrivetrainType;

 

// Number of cylinders in the engine
S32 NumCylinders;
} __attribute__((packed)) FORZA_SLED;

 

typedef struct _dash_
{
// = 1 when race is on. = 0 when in menus/race stopped …
S32 IsRaceOn;

 

// Can overflow to 0 eventually
U32 TimestampMS;
F32 EngineMaxRpm;
F32 EngineIdleRpm;
F32 CurrentEngineRpm;

 

// In the car's local space; X = right, Y = up, Z = forward
F32 AccelerationX;
F32 AccelerationY;
F32 AccelerationZ;

 

// In the car's local space; X = right, Y = up, Z = forward
F32 VelocityX;
F32 VelocityY;
F32 VelocityZ;

 

// In the car's local space; X = pitch, Y = yaw, Z = roll
F32 AngularVelocityX;
F32 AngularVelocityY;
F32 AngularVelocityZ;

 

F32 Yaw;
F32 Pitch;
F32 Roll;

 

// Suspension travel normalized: 0.0f = max stretch; 1.0 = max compression
F32 NormalizedSuspensionTravelFrontLeft;
F32 NormalizedSuspensionTravelFrontRight;
F32 NormalizedSuspensionTravelRearLeft;
F32 NormalizedSuspensionTravelRearRight;

 

// Tire normalized slip ratio, = 0 means 100% grip and |ratio| > 1.0 means loss of grip.
F32 TireSlipRatioFrontLeft;
F32 TireSlipRatioFrontRight;
F32 TireSlipRatioRearLeft;
F32 TireSlipRatioRearRight;

 

// Wheels rotation speed radians/sec.
F32 WheelRotationSpeedFrontLeft;
F32 WheelRotationSpeedFrontRight;
F32 WheelRotationSpeedRearLeft;
F32 WheelRotationSpeedRearRight;

 

// = 1 when wheel is on rumble strip, = 0 when off.
S32 WheelOnRumbleStripFrontLeft;
S32 WheelOnRumbleStripFrontRight;
S32 WheelOnRumbleStripRearLeft;
S32 heelOnRumbleStripRearRight;

 

// = from 0 to 1, where 1 is the deepest puddle
F32 WheelInPuddleDepthFrontLeft;
F32 WheelInPuddleDepthFrontRight;
F32 WheelInPuddleDepthRearLeft;
F32 WheelInPuddleDepthRearRight;

 

// Non-dimensional surface rumble values passed to controller force feedback
F32 SurfaceRumbleFrontLeft;
F32 SurfaceRumbleFrontRight;
F32 SurfaceRumbleRearLeft;
F32 SurfaceRumbleRearRight;

 

// Tire normalized slip angle, = 0 means 100% grip and |angle| > 1.0 means loss of grip.
F32 TireSlipAngleFrontLeft;
F32 TireSlipAngleFrontRight;
F32 TireSlipAngleRearLeft;
F32 TireSlipAngleRearRight;

 

// Tire normalized combined slip, = 0 means 100% grip and |slip| > 1.0 means loss of grip.
F32 TireCombinedSlipFrontLeft;
F32 TireCombinedSlipFrontRight;
F32 TireCombinedSlipRearLeft;
F32 TireCombinedSlipRearRight;

 

// Actual suspension travel in meters
F32 SuspensionTravelMetersFrontLeft;
F32 SuspensionTravelMetersFrontRight;
F32 SuspensionTravelMetersRearLeft;
F32 SuspensionTravelMetersRearRight;

 

// Unique ID of the car make/model
S32 CarOrdinal;

 

// Between 0 (D -- worst cars) and 7 (X class -- best cars) inclusive
S32 CarClass;

 

// Between 100 (worst car) and 999 (best car) inclusive
S32 CarPerformanceIndex;

 

// 0 = FWD, 1 = RWD, 2 = AWD
S32 DrivetrainType;

 

// Number of cylinders in the engine
S32 NumCylinders;

 

// add for DASH
F32 PositionX;
F32 PositionY;
F32 PositionZ;
F32 Speed;
F32 Power;
F32 Torque;
F32 TireTempFrontLeft;
F32 TireTempFrontRight;
F32 TireTempRearLeft;
F32 TireTempRearRight;
F32 Boost;
F32 Fuel;
F32 DistanceTraveled;
F32 BestLap;
F32 LastLap;
F32 CurrentLap;
F32 CurrentRaceTime;
U16 LapNumber;
U8 RacePosition;
U8 Accel;
U8 Brake;
U8 Clutch;
U8 HandBrake;
U8 Gear;
S8 Steer;
S8 NormalizedDrivingLine;
S8 NormalizedAIBrakeDifference;

 

F32 TireWearFrontLeft;
F32 TireWearFrontRight;
F32 TireWearRearLeft;
F32 TireWearRearRight;

 

// ID for track
S32 TrackOrdinal;
} __attribute__((packed)) FORZA_DASH;

 

int last_raceon = 0;
void parse_forza(char *message)
{
int row = 0;
FORZA_DASH forza;
memcpy(&forza, message, sizeof(FORZA_DASH));

 

static unsigned int pack_cnt = 0;

 

if(last_raceon != forza.IsRaceOn)
{
clear();
last_raceon = forza.IsRaceOn;
}

 

if(forza.IsRaceOn)
{
mvprintw(row++, 0, "let's fly %d\n",pack_cnt++);

 

mvprintw(row++, 0, "RPM %f / %f", forza.CurrentEngineRpm, forza.EngineMaxRpm);

 

mvprintw(row++, 0, "acc X %f", forza.AccelerationX);
mvprintw(row++, 0, "acc Y %f", forza.AccelerationY);
mvprintw(row++, 0, "acc Z %f", forza.AccelerationZ);

 

mvprintw(row++, 0, "vel X %f", forza.VelocityX);
mvprintw(row++, 0, "vel Y %f", forza.VelocityY);
mvprintw(row++, 0, "vel Z %f", forza.VelocityZ);

 

mvprintw(row++, 0, "ang vel X %f", forza.AngularVelocityX);
mvprintw(row++, 0, "ang vel Y %f", forza.AngularVelocityY);
mvprintw(row++, 0, "ang vel Z %f", forza.AngularVelocityZ);
 
mvprintw(row++, 0, "yaw %f", forza.Yaw);
mvprintw(row++, 0, "roll %f", forza.Pitch);
mvprintw(row++, 0, "pitch %f", forza.Roll);



mvprintw(row++, 0, "CarOrdinal %d", forza.CarOrdinal);
mvprintw(row++, 0, "CarClass %d", forza.CarClass);
mvprintw(row++, 0, "CarPerformanceIndex %d", forza.CarPerformanceIndex);
mvprintw(row++, 0, "DrivetrainType %d", forza.DrivetrainType);
mvprintw(row++, 0, "NumCylinders %d", forza.NumCylinders);

 

mvprintw(row++, 0, "clutch[%d] brake[%d] accel[%d] handbrake[%d] gear[%d]"
, forza.Clutch
, forza.Brake
, forza.Accel
, forza.HandBrake
, forza.Gear);

 

}
else mvprintw(row++, 0, "pause");

 

refresh();
}

 

void error_handling(char *message);

 

int main(int argc, char *argv[]){
int serv_sock;
char message[BUF_SIZE];
int str_len;
socklen_t clnt_adr_sz;

 

struct sockaddr_in serv_adr, clnt_adr;

 

printf("%d sizeof(FORZA_SLED)\n", sizeof(FORZA_SLED));
printf("%d sizeof(FORZA_DASH)\n", sizeof(FORZA_DASH));

 

if(argc!=2){
printf("Usage:%s <port>\n", argv[0]);
exit(1);
}

 

serv_sock = socket(PF_INET, SOCK_DGRAM, 0);
if(serv_sock == -1)
error_handling("UDP socket creation error");

 

memset(&serv_adr, 0, sizeof(serv_adr));
serv_adr.sin_family=AF_INET;
serv_adr.sin_addr.s_addr=htonl(INADDR_ANY);
serv_adr.sin_port=htons(atoi(argv[1]));

 

if(bind(serv_sock, (struct sockaddr*)&serv_adr, sizeof(serv_adr)) == -1)
error_handling("bind() error");
 
initscr();

 

while(1){
clnt_adr_sz = sizeof(clnt_adr);
str_len = recvfrom(serv_sock, message, BUF_SIZE, 0, (struct sockaddr*)&clnt_adr, &clnt_adr_sz);
message[str_len] = 0x00;
// printf("%d received [%s]\n", str_len, message);
// printf("%d received, %d sizeof(FORZA_SLED)\n", str_len, sizeof(FORZA_SLED));
parse_forza(message);
sendto(serv_sock, message, str_len, 0, (struct sockaddr*)&clnt_adr, clnt_adr_sz);
}
close(serv_sock);
return 0;
}

 

void error_handling(char *message){
fputs(message, stderr);
fputc('\n', stderr);

 

endwin();
exit(1);
}

'모종의 음모 > force feedback' 카테고리의 다른 글

forza horizon 4 telemetry 수정  (0) 2024.12.07
forza telemetry  (0) 2024.12.02
forza horizon 4 data format  (0) 2024.11.20
dirt rally 2.0 motion data  (0) 2024.11.03
F1 2015 motion data  (0) 2024.11.03
Posted by 구차니
프로그램 사용/ncurses2024. 11. 30. 15:11

forza horizon 모션 데이터 출력을 위해서 ncurse 사용하게 될 줄이야..

 

일단 패키지를 설치해주고

$ sudo apt-get install libncurses-dev

 

소스를 가져오고

#include <ncurses.h>
#include <unistd.h>

int func1(){
    initscr();
    mvprintw(0, 0, "Hello, World"); // 화면의 0행, 0열부터 Hello, World를 출력합니다.
    refresh(); // 화면에 출력하도록 합니다.
    sleep(1);
    endwin();
    return 0;
}

int main(){
    return func1();
}
#include <ncurses.h>
#include <unistd.h>

int timer(){
    int row = 10, col = 10;
    initscr();
    noecho(); // 입력을 자동으로 화면에 출력하지 않도록 합니다.
    curs_set(FALSE); // cursor를 보이지 않게 합니다. 

    keypad(stdscr, TRUE);
    while(1){
        int input = getch();
        clear();
        switch(input){
            case KEY_UP:
            mvprintw(--row, col, "A"); // real moving in your screen
            continue;
            case KEY_DOWN:
            mvprintw(++row, col, "A");
            continue;
            case KEY_LEFT:
            mvprintw(row, --col, "A");
            continue;
            case KEY_RIGHT:
            mvprintw(row, ++col, "A");
            continue;

        }
        if(input == 'q') break;
    }

    endwin();
    return 0;
}

int main(){
    return timer();
}

 

아래의 링커 옵션을 주고 빌드하면 끝

$ gcc ncruse_example.c -lncurses -o bin/ex1

 

mvprintw() 만 쓰면 원하는 위치에 꾸준히 갱신할 수 있을 듯

[링크 : https://blackinkgj.github.io/ncurses/]

 

 

[링크 : https://www.ibm.com/docs/ko/aix/7.3?topic=p-printw-wprintw-mvprintw-mvwprintw-subroutine]

'프로그램 사용 > ncurses' 카테고리의 다른 글

ncurses 상자 및 색상 적용하기  (0) 2024.12.02
ncurse  (0) 2015.04.27
Posted by 구차니