forked from lvgl/lvgl
-
Notifications
You must be signed in to change notification settings - Fork 5
TI demo smart home backend #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
div2779
wants to merge
12
commits into
master
Choose a base branch
from
ti-demo-smart-home-backend
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5b8a0b6
high_res: Replace LVGL logo with TI logo
jsuhaas22 73045e4
demos: high_res: Add slides for "About" section
jsuhaas22 5f66886
demos/high_res: Add audio play and volume control from HMI
d-mittal-ti 623908c
demos/high_res: Add MQTT based audio volume control
d-mittal-ti 54eff31
demos/high_res: Add correct date-time in UTC timezone on HMI
d-mittal-ti c642125
demos/high_res: Add screen lock based on GPIO user switch
d-mittal-ti 4ed346a
demos/high_res: Add user led blink and its MQTT-based control from HMI
d-mittal-ti 0eb739f
demos/high_res: Add ADC data read and MQTT ADC data publish
d-mittal-ti 58c8ba7
demos/high_res: Add HMI evCharge data publish through MQTT
d-mittal-ti c8aa1e2
demo/high_res: add compatibility for board with no button configured
d-mittal-ti 6c3f1ce
demo/high_res: modify docstring for C files
d-mittal-ti 325872b
demo/high_res: remove bug causing 100% CPU utilization of one core
d-mittal-ti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| /* | ||
| * Simple sound playback using ALSA API and libasound. | ||
| * | ||
| * Compile: | ||
| * $ cc -o play sound_playback.c -lasound | ||
| * | ||
| * Copyright (C) 2009 Alessandro Ghedini <[email protected]> | ||
| * -------------------------------------------------------------- | ||
| * "THE BEER-WARE LICENSE" (Revision 42): | ||
| * Alessandro Ghedini wrote this file. As long as you retain this | ||
| * notice you can do whatever you want with this stuff. If we | ||
| * meet some day, and you think this stuff is worth it, you can | ||
| * buy me a beer in return. | ||
| * -------------------------------------------------------------- | ||
| */ | ||
|
|
||
| #include <alsa/asoundlib.h> | ||
| #include <stdio.h> | ||
| #include <pthread.h> | ||
|
|
||
| #define PCM_DEVICE "default" | ||
| extern pthread_mutex_t playing_now_lock; | ||
| extern int playing_now; | ||
|
|
||
| void *audio_play() { | ||
| unsigned int pcm, tmp, dir; | ||
| int rate, channels, seconds; | ||
| snd_pcm_t *pcm_handle; | ||
| snd_pcm_hw_params_t *params; | ||
| snd_pcm_uframes_t frames; | ||
| char *buff; | ||
| int buff_size, loops; | ||
|
|
||
| rate = 44100; | ||
| channels = 2; | ||
| seconds = 30; | ||
|
|
||
| /* Open the PCM device in playback mode */ | ||
| if (pcm = snd_pcm_open(&pcm_handle, PCM_DEVICE, SND_PCM_STREAM_PLAYBACK, 0) < 0){ | ||
| printf("ERROR: Can't open \"%s\" PCM device. %s\n", PCM_DEVICE, snd_strerror(pcm)); | ||
| return; | ||
| } | ||
|
|
||
| /* Allocate parameters object and fill it with default values*/ | ||
| snd_pcm_hw_params_alloca(¶ms); | ||
|
|
||
| snd_pcm_hw_params_any(pcm_handle, params); | ||
|
|
||
| /* Set parameters */ | ||
| if (pcm = snd_pcm_hw_params_set_access(pcm_handle, params, SND_PCM_ACCESS_RW_INTERLEAVED) < 0){ | ||
| printf("ERROR: Can't set interleaved mode. %s\n", snd_strerror(pcm)); | ||
| return; | ||
| } | ||
|
|
||
| if (pcm = snd_pcm_hw_params_set_format(pcm_handle, params, SND_PCM_FORMAT_S16_LE) < 0){ | ||
| printf("ERROR: Can't set format. %s\n", snd_strerror(pcm)); | ||
| return; | ||
| } | ||
|
|
||
| if (pcm = snd_pcm_hw_params_set_channels(pcm_handle, params, channels) < 0){ | ||
| printf("ERROR: Can't set channels number. %s\n", snd_strerror(pcm)); | ||
| return; | ||
| } | ||
|
|
||
| if (pcm = snd_pcm_hw_params_set_rate_near(pcm_handle, params, &rate, 0) < 0){ | ||
| printf("ERROR: Can't set rate. %s\n", snd_strerror(pcm)); | ||
| return; | ||
| } | ||
|
|
||
| /* Write parameters */ | ||
| if (pcm = snd_pcm_hw_params(pcm_handle, params) < 0){ | ||
| printf("ERROR: Can't set harware parameters. %s\n", snd_strerror(pcm)); | ||
| return; | ||
| } | ||
|
|
||
| /* Resume information */ | ||
| printf("PCM name: '%s'\n", snd_pcm_name(pcm_handle)); | ||
|
|
||
| printf("PCM state: %s\n", snd_pcm_state_name(snd_pcm_state(pcm_handle))); | ||
|
|
||
| snd_pcm_hw_params_get_channels(params, &tmp); | ||
| printf("channels: %i ", tmp); | ||
|
|
||
| if (tmp == 1) | ||
| printf("(mono)\n"); | ||
| else if (tmp == 2) | ||
| printf("(stereo)\n"); | ||
|
|
||
| snd_pcm_hw_params_get_rate(params, &tmp, 0); | ||
| printf("rate: %d bps\n", tmp); | ||
|
|
||
| printf("seconds: %d\n", seconds); | ||
|
|
||
| /* Allocate buffer to hold single period */ | ||
| snd_pcm_hw_params_get_period_size(params, &frames, 0); | ||
|
|
||
| buff_size = frames * channels * 2 /* 2 -> sample size */; | ||
| buff = (char *) malloc(buff_size); | ||
|
|
||
| snd_pcm_hw_params_get_period_time(params, &tmp, NULL); | ||
|
|
||
| while(1){ | ||
| int fd = open("/usr/share/ti-lvgl-demo/audio/mixkit-game-show-suspense-waiting-667.wav", O_RDONLY); | ||
| if (fd == -1) { | ||
| perror("Error opening audio file"); | ||
| return; | ||
| } | ||
| for (loops = (seconds * 1000000) / tmp; loops > 0; loops--) { | ||
| while(1){ | ||
| pthread_mutex_lock(&playing_now_lock); | ||
| if(playing_now){ | ||
| pcm = snd_pcm_pause(pcm_handle, 0); | ||
| pthread_mutex_unlock(&playing_now_lock); | ||
| break; | ||
| }else{ | ||
| pcm = snd_pcm_pause(pcm_handle, 1); | ||
| } | ||
| pthread_mutex_unlock(&playing_now_lock); | ||
| usleep(250000); | ||
| } | ||
|
|
||
| if (pcm = read(fd, buff, buff_size) == 0) { | ||
| printf("Early end of file.\n"); | ||
| return 0; | ||
| } | ||
|
|
||
| if (pcm = snd_pcm_writei(pcm_handle, buff, frames) == -EPIPE) { | ||
| printf("XRUN.\n"); | ||
| snd_pcm_prepare(pcm_handle); | ||
| } else if (pcm < 0) { | ||
| printf("ERROR. Can't write to PCM device. %s\n", snd_strerror(pcm)); | ||
| } | ||
| } | ||
| close(fd); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| #include <stdbool.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <unistd.h> | ||
|
|
||
| #include <linux/input.h> | ||
| #include <fcntl.h> | ||
|
|
||
| #include <stdarg.h> | ||
| #include <stdint.h> | ||
| #include <string.h> | ||
|
|
||
| #include <linux/fb.h> | ||
| #include <sys/mman.h> | ||
| #include "lv_demo_high_res_private.h" | ||
|
|
||
| int button_configured = 0; | ||
|
|
||
| const char *ev_type[EV_CNT] = { | ||
| [EV_SYN] = "EV_SYN", | ||
| [EV_KEY] = "EV_KEY", | ||
| [EV_REL] = "EV_REL", | ||
| [EV_ABS] = "EV_ABS", | ||
| [EV_MSC] = "EV_MSC", | ||
| [EV_SW] = "EV_SW", | ||
| [EV_LED] = "EV_LED", | ||
| [EV_SND] = "EV_SND", | ||
| [EV_REP] = "EV_REP", | ||
| [EV_FF] = "EV_FF", | ||
| [EV_PWR] = "EV_PWR", | ||
| [EV_FF_STATUS] = "EV_FF_STATUS", | ||
| [EV_MAX] = "EV_MAX", | ||
| }; | ||
|
|
||
| const char *ev_code_syn[SYN_CNT] = { | ||
| [SYN_REPORT] = "SYN_REPORT", | ||
| [SYN_CONFIG] = "SYN_CONFIG", | ||
| [SYN_MT_REPORT] = "SYN_MT_REPORT", | ||
| [SYN_DROPPED] = "SYN_DROPPED", | ||
| [SYN_MAX] = "SYN_MAX", | ||
| }; | ||
|
|
||
| void *button_init(lv_demo_high_res_api_t * api) | ||
| { | ||
| int fd; | ||
| char dev[] = "/dev/input/eventX"; | ||
| struct input_event ie; | ||
|
|
||
| char buffer[128]; | ||
| FILE *fp = popen("cat /proc/bus/input/devices | grep Phys=gpio-keys/input", "r"); | ||
|
|
||
| if (fp == NULL) { | ||
| perror("popen failed"); | ||
| return 1; | ||
| } | ||
|
|
||
| if (fgets(buffer, sizeof(buffer), fp) != NULL) { | ||
| int len_dev = strlen(dev); | ||
| int len_buffer = strlen(buffer); | ||
| dev[len_dev - 1] = buffer[len_buffer - 2]; | ||
| button_configured = 1; | ||
| } | ||
| else{ | ||
| printf("Button not Configured\n"); | ||
| return 0; | ||
| } | ||
|
|
||
| if ((fd = open(dev, O_RDONLY)) == -1) { | ||
| perror("opening device"); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
|
|
||
| int last_val=-1; | ||
| int curr_val=-1; | ||
| while (read(fd, &ie, sizeof(struct input_event))) { | ||
| if(ie.type != 1) | ||
| continue; | ||
| curr_val = ie.value; | ||
| if(curr_val==0 && last_val > 0){ | ||
| fprintf(stderr, "Button Released!!\n"); | ||
| lv_lock(); | ||
| int lock_status = lv_subject_get_int(&api->subjects.locked); | ||
| lv_subject_set_int(&api->subjects.locked, !lock_status); | ||
| lv_unlock(); | ||
| } | ||
| last_val = curr_val; | ||
| } | ||
|
|
||
| close(fd); | ||
|
|
||
| return EXIT_SUCCESS; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <fcntl.h> | ||
| #include <pthread.h> | ||
| #include <string.h> | ||
| #include "lv_demo_high_res_private.h" | ||
|
|
||
|
|
||
| static void slice(const char* str, char* result, size_t start, size_t end) { | ||
| strncpy(result, str + start, end - start); | ||
| } | ||
|
|
||
| void *clock_init(lv_demo_high_res_api_t * api) { | ||
| int last_minute = -1; | ||
| while(1){ | ||
| char buffer[128]; | ||
| FILE *fp = popen("date", "r"); | ||
|
|
||
| if (fp == NULL) { | ||
| perror("popen failed"); | ||
| return 1; | ||
| } | ||
|
|
||
| if (fgets(buffer, sizeof(buffer), fp) == NULL) { | ||
| continue; | ||
| } | ||
|
|
||
| char day[10]; | ||
| char sliced_day[5]; | ||
| slice(buffer, sliced_day, 0, 0 + 3); | ||
| if(strcmp(sliced_day, "Mon")==0){ | ||
| strcpy(day, "Monday"); | ||
| } | ||
| else if(strcmp(sliced_day, "Tue")==0){ | ||
| strcpy(day, "Tuesday"); | ||
| } | ||
| else if(strcmp(sliced_day, "Wed")==0){ | ||
| strcpy(day, "Wednesday"); | ||
| } | ||
| else if(strcmp(sliced_day, "Thu")==0){ | ||
| strcpy(day, "Thursday"); | ||
| } | ||
| else if(strcmp(sliced_day, "Fri")==0){ | ||
| strcpy(day, "Friday"); | ||
| } | ||
| else if(strcmp(sliced_day, "Sat")==0){ | ||
| strcpy(day, "Saturday"); | ||
| } | ||
| else if(strcmp(sliced_day, "Sun")==0){ | ||
| strcpy(day, "Sunday"); | ||
| } | ||
|
|
||
| char month[10]; | ||
| char sliced_month[5]; | ||
| slice(buffer, sliced_month, 4, 4 + 3); | ||
| if(strcmp(sliced_month, "Jan")==0){ | ||
| strcpy(month, "January"); | ||
| } | ||
| else if(strcmp(sliced_month, "Feb")==0){ | ||
| strcpy(month, "February"); | ||
| } | ||
| else if(strcmp(sliced_month, "Mar")==0){ | ||
| strcpy(month, "March"); | ||
| } | ||
| else if(strcmp(sliced_month, "Apr")==0){ | ||
| strcpy(month, "April"); | ||
| } | ||
| else if(strcmp(sliced_month, "May")==0){ | ||
| strcpy(month, "May"); | ||
| } | ||
| else if(strcmp(sliced_month, "Jun")==0){ | ||
| strcpy(month, "June"); | ||
| } | ||
| else if(strcmp(sliced_month, "Jul")==0){ | ||
| strcpy(month, "July"); | ||
| } | ||
| else if(strcmp(sliced_month, "Aug")==0){ | ||
| strcpy(month, "August"); | ||
| } | ||
| else if(strcmp(sliced_month, "Sep")==0){ | ||
| strcpy(month, "September"); | ||
| } | ||
| else if(strcmp(sliced_month, "Oct")==0){ | ||
| strcpy(month, "October"); | ||
| } | ||
| else if(strcmp(sliced_month, "Nov")==0){ | ||
| strcpy(month, "November"); | ||
| } | ||
| else if(strcmp(sliced_month, "Dec")==0){ | ||
| strcpy(month, "December"); | ||
| } | ||
|
|
||
| char sliced_date[4]; | ||
| slice(buffer, sliced_date, 8, 8 + 2); | ||
| int date = atoi(sliced_date); | ||
|
|
||
| char sliced_hour[4]; | ||
| slice(buffer, sliced_hour, 11, 11 + 2); | ||
| int hour = atoi(sliced_hour); | ||
|
|
||
| char sliced_minute[4]; | ||
| slice(buffer, sliced_minute, 14, 14 + 2); | ||
| int minute = atoi(sliced_minute); | ||
| if(last_minute==-1){ | ||
| lv_lock(); | ||
| lv_subject_set_pointer(&api->subjects.month_name, month); | ||
| lv_subject_set_int(&api->subjects.month_day, date); | ||
| lv_subject_set_pointer(&api->subjects.week_day_name, day); | ||
| lv_subject_set_int(&api->subjects.hour, hour); | ||
| lv_subject_set_int(&api->subjects.minute, minute); | ||
| lv_unlock(); | ||
| last_minute = minute; | ||
| } | ||
|
|
||
| char sliced_year[4]; | ||
| slice(buffer, sliced_year, 24, 24 + 4); | ||
| int year = atoi(sliced_year); | ||
|
|
||
| pclose(fp); | ||
|
|
||
| if(last_minute != minute){ | ||
| lv_lock(); | ||
| lv_subject_set_pointer(&api->subjects.month_name, month); | ||
| lv_subject_set_int(&api->subjects.month_day, date); | ||
| lv_subject_set_pointer(&api->subjects.week_day_name, day); | ||
| lv_subject_set_int(&api->subjects.hour, hour); | ||
| lv_subject_set_int(&api->subjects.minute, minute); | ||
| lv_unlock(); | ||
| } | ||
| last_minute = minute; | ||
| usleep(1000000); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.