Koraidon

Форк
0
/
main.c 
141 строка · 3.5 Кб
1
#include <stdlib.h>
2
#include <stdio.h>
3
#include <sys/ioctl.h>
4
#include <fcntl.h>
5
#include <time.h>
6
#include <unistd.h>
7

8
#include "video/screen.h"
9
#include "video/backfb.h"
10
#include "video/tga_image.h"
11
#include "video/pixel.h"
12
#include "image_formats/tga.h"
13
#include "sensors/battery.h"
14
#include "ui/rect.h"
15
#include "ui/psf_font.h"
16

17
#include <linux/input.h>
18
#include <linux/soundcard.h>
19

20

21
struct snd_xferi {
22
	int result;
23
	void *buf;
24
	unsigned int frames;
25
};
26

27
union snd_pcm_sync_id {
28
	unsigned char id[16];
29
	unsigned short id16[8];
30
	unsigned int id32[4];
31
};
32

33
struct snd_pcm_info {
34
	unsigned int device;		/* RO/WR (control): device number */
35
	unsigned int subdevice;		/* RO/WR (control): subdevice number */
36
	int stream;			/* RO/WR (control): stream direction */
37
	int card;			/* R: card number */
38
	unsigned char id[64];		/* ID (user selectable) */
39
	unsigned char name[80];		/* name of this device */
40
	unsigned char subname[32];	/* subdevice name */
41
	int dev_class;			/* SNDRV_PCM_CLASS_* */
42
	int dev_subclass;		/* SNDRV_PCM_SUBCLASS_* */
43
	unsigned int subdevices_count;
44
	unsigned int subdevices_avail;
45
	union snd_pcm_sync_id sync;	/* hardware synchronization ID */
46
	unsigned char reserved[64];	/* reserved for future... */
47
};
48

49
#define SNDRV_PCM_IOCTL_WRITEI_FRAMES _IOW('A', 0x50, struct snd_xferi);
50
#define SNDRV_PCM_IOCTL_PREPARE		_IO('A', 0x40)
51
#define SNDRV_PCM_IOCTL_INFO		_IOR('A', 0x01, struct snd_pcm_info)
52

53
int main(void) {
54
    srand(time(NULL));
55

56
    koraidon_screen_t screen = init_screen("/dev/graphics/fb0");
57
    koraidon_backfb_t framebuffer = backfb_from_screen(screen);
58

59
    // CODE GOES HERE...
60

61
	// AUDIO
62

63
    int fd = open("/dev/snd/pcmC1D1p", O_RDWR | O_NONBLOCK);
64

65
    if(fd) {
66
        printf("Sound FD Ok\n");
67

68
        struct snd_pcm_info info;
69

70
        int result = ioctl(fd, SNDRV_PCM_IOCTL_INFO, &info);
71

72
        printf("%d\n", result);
73

74
        if(result >= 0) {
75
            printf("Card Ok!\n");
76
            printf("Card ID: %s\n", info.id);
77
            printf("Card Name: %s\n", info.name);
78
            printf("Card Subname: %s\n", info.subname);
79
            printf("Card Stream: %d\n", info.stream);
80
            printf("Card Class/Subclass: %d/%d\n", info.dev_class, info.dev_subclass);
81
        }
82

83
        close(fd);
84
    }
85

86
    // BATTERY
87

88
	 koraidon_battery_info_t battery;
89

90
     battery = battery_get_info("/sys/class/power_supply/battery/");
91

92
     printf("Level: %d\nTemperature: %f *C\nVolatge: %f V\n", battery.level, battery.temp, battery.voltage);
93
     printf("Is charging: %s\n", battery.status == BATTERY_CHARGING ? "yes" : "no");
94

95
    // BATTERY END
96

97
    // EVENTS
98

99
    // struct input_event event;
100

101
    // int fd = open("/dev/input/event1", O_RDONLY | O_NONBLOCK);
102

103
    // while(true) {
104
    //     ssize_t rdbytes = read(fd, &event, sizeof(event));
105
    
106
    //     if(rdbytes == sizeof(event)) {
107
    //         printf("Event: Type: %d -> %d = %d\n", event.type, event.code, event.value);
108
    //     }
109
    // }
110

111
    // close(fd);
112

113
	// IMAGES
114

115

116
	char timebuf[32] = {0};
117

118
	while(1) {
119
		time_t curtime_val = time(NULL);
120
		struct tm* curtime = localtime(&curtime_val);
121

122
		tga_scale_draw(
123
			framebuffer,
124
			0, 0,
125
			screen.real_info.width, screen.real_info.height,
126
			"/sdcard/test.tga"
127
		);
128

129
		draw_fill_rect(set_pixel_alpha, framebuffer, 0, 0, screen.real_info.width, 36, 0xACFFFFFF);
130

131
		strftime(timebuf, 32, "[%H:%M:%S]", curtime);
132
		draw_string(set_pixel_alpha, framebuffer, timebuf, 10, 10, 0xFF000000);
133

134
		backfb_flush(framebuffer);
135
	}
136

137
    backfb_deinit(framebuffer);
138
	deinit_screen(screen);
139

140
    return 0;
141
}
142

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.