Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | /* * Copyright (c) 2016 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <device.h> #include <ipm.h> #include <ipm/ipm_quark_se.h> #include <misc/printk.h> #include <misc/util.h> #include <sensor.h> #include <zephyr.h> #ifdef CONFIG_GROVE_LCD_RGB #include <display/grove_lcd.h> #include <stdio.h> #include <string.h> #endif QUARK_SE_IPM_DEFINE(ess_ipm, 0, QUARK_SE_IPM_OUTBOUND); struct channel_info { int chan; char *dev_name; }; /* change device names if you want to use different sensors */ static struct channel_info info[] = { {SENSOR_CHAN_TEMP, "HDC1008"}, {SENSOR_CHAN_HUMIDITY, "HDC1008"}, {SENSOR_CHAN_PRESS, "BMP280"}, }; void main(void) { struct device *ipm, *dev[ARRAY_SIZE(info)]; struct sensor_value val[ARRAY_SIZE(info)]; unsigned int i; int rc; ipm = device_get_binding("ess_ipm"); if (ipm == NULL) { printk("Failed to get ESS IPM device\n"); return; } for (i = 0; i < ARRAY_SIZE(info); i++) { dev[i] = device_get_binding(info[i].dev_name); if (dev[i] == NULL) { printk("Failed to get \"%s\" device\n", info[i].dev_name); return; } } #ifdef CONFIG_GROVE_LCD_RGB struct device *glcd; glcd = device_get_binding(GROVE_LCD_NAME); if (glcd == NULL) { printk("Failed to get Grove LCD\n"); return; } /* configure LCD */ glcd_function_set(glcd, GLCD_FS_ROWS_2 | GLCD_FS_DOT_SIZE_LITTLE | GLCD_FS_8BIT_MODE); glcd_display_state_set(glcd, GLCD_DS_DISPLAY_ON); #endif while (1) { /* fetch sensor samples */ for (i = 0; i < ARRAY_SIZE(info); i++) { rc = sensor_sample_fetch(dev[i]); if (rc) { printk("Failed to fetch sample for device %s (%d)\n", info[i].dev_name, rc); } } /* send sensor data to x86 core via IPM */ for (i = 0; i < ARRAY_SIZE(info); i++) { rc = sensor_channel_get(dev[i], info[i].chan, &val[i]); if (rc) { printk("Failed to get data for device %s (%d)\n", info[i].dev_name, rc); continue; } rc = ipm_send(ipm, 1, info[i].chan, &val[i], sizeof(val[i])); if (rc) { printk("Failed to send data for device %s (%d)\n", info[i].dev_name, rc); } } #ifdef CONFIG_GROVE_LCD_RGB char row[16]; /* clear LCD */ memset(row, ' ', sizeof(row)); glcd_cursor_pos_set(glcd, 0, 0); glcd_print(glcd, row, sizeof(row)); glcd_cursor_pos_set(glcd, 0, 1); glcd_print(glcd, row, sizeof(row)); /* display temperature on LCD */ glcd_cursor_pos_set(glcd, 0, 0); sprintf(row, "T:%d.%d%cC", val[0].val1, val[0].val2/100000, 223 /* degree symbol */); glcd_print(glcd, row, strlen(row)); /* display himidity on LCD */ glcd_cursor_pos_set(glcd, 17 - strlen(row), 0); sprintf(row, "RH:%d%c", val[1].val1/1000, 37 /* percent symbol */); glcd_print(glcd, row, strlen(row)); /* display pressure on LCD */ glcd_cursor_pos_set(glcd, 0, 1); sprintf(row, "P:%d.%02dkPa", val[2].val1, val[2].val2 / 10000); glcd_print(glcd, row, strlen(row)); #endif task_sleep(sys_clock_ticks_per_sec); } } |