summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Shmidt <dimitrysh@google.com>2017-06-02 22:16:26 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-06-02 22:16:26 +0000
commit3c690569833c57b5d76b8ffa655fcf37b6bf683e (patch)
tree810739c70ce1dd07e67f8c6fa087227ef9e79b39
parent73a3285410d649347503783a1673e9af9947fbe7 (diff)
parent253f44c2b4cc2ffa1cd3696bb350770f6db42c51 (diff)
downloadcontexthub-3c690569833c57b5d76b8ffa655fcf37b6bf683e.tar.gz
Merge "util: nanoapp_cmd: Add leds and humidity support, add cfgdata for leds"
am: 253f44c2b4 Change-Id: I034a455ad3d15415c8eb31bbb9357d0d4f0c60a7
-rw-r--r--util/nanoapp_cmd/nanoapp_cmd.c53
1 files changed, 50 insertions, 3 deletions
diff --git a/util/nanoapp_cmd/nanoapp_cmd.c b/util/nanoapp_cmd/nanoapp_cmd.c
index 6c1f6da2..e0334efc 100644
--- a/util/nanoapp_cmd/nanoapp_cmd.c
+++ b/util/nanoapp_cmd/nanoapp_cmd.c
@@ -63,6 +63,7 @@ struct ConfigCmd
uint8_t sensorType;
uint8_t cmd;
uint16_t flags;
+ uint8_t data[];
} __attribute__((packed));
struct AppInfo
@@ -73,6 +74,11 @@ struct AppInfo
uint32_t size;
};
+struct LedsCfg {
+ uint32_t led_num;
+ uint32_t value;
+} __attribute__((packed));
+
static int setType(struct ConfigCmd *cmd, char *sensor)
{
if (strcmp(sensor, "accel") == 0) {
@@ -147,6 +153,12 @@ static int setType(struct ConfigCmd *cmd, char *sensor)
} else if (strcmp(sensor, "twist") == 0) {
cmd->sensorType = SENS_TYPE_DOUBLE_TWIST;
cmd->rate = SENSOR_RATE_ONCHANGE;
+ } else if (strcmp(sensor, "leds") == 0) {
+ cmd->sensorType = SENS_TYPE_LEDS;
+ } else if (strcmp(sensor, "leds_i2c") == 0) {
+ cmd->sensorType = SENS_TYPE_LEDS_I2C;
+ } else if (strcmp(sensor, "humidity") == 0) {
+ cmd->sensorType = SENS_TYPE_HUMIDITY;
} else {
return 1;
}
@@ -317,18 +329,21 @@ void resetHub()
int main(int argc, char *argv[])
{
struct ConfigCmd mConfigCmd;
+ struct ConfigCmd *pConfigCmd = &mConfigCmd;
+ size_t length = sizeof(mConfigCmd);
int fd;
int i;
if (argc < 3 && (argc < 2 || strcmp(argv[1], "download") != 0)) {
printf("usage: %s <action> <sensor> <data> -d\n", argv[0]);
- printf(" action: config|calibrate|flush|download\n");
+ printf(" action: config|cfgdata|calibrate|flush|download\n");
printf(" sensor: accel|(uncal_)gyro|(uncal_)mag|als|prox|baro|temp|orien\n");
printf(" gravity|geomag|linear_acc|rotation|game\n");
printf(" win_orien|tilt|step_det|step_cnt|double_tap\n");
printf(" flat|anymo|nomo|sigmo|gesture|hall|vsync\n");
- printf(" activity|twist\n");
+ printf(" activity|twist|leds|leds_i2c|humidity\n");
printf(" data: config: <true|false> <rate in Hz> <latency in u-sec>\n");
+ printf(" cfgdata: leds: led_num value\n");
printf(" calibrate: [N.A.]\n");
printf(" flush: [N.A.]\n");
printf(" -d: if specified, %s will keep draining /dev/nanohub until cancelled.\n", argv[0]);
@@ -363,6 +378,35 @@ int main(int argc, char *argv[])
printf("Unsupported sensor: %s For action: %s\n", argv[2], argv[1]);
return 1;
}
+ } else if (strcmp(argv[1], "cfgdata") == 0) {
+ mConfigCmd.evtType = EVT_NO_SENSOR_CONFIG_EVENT;
+ mConfigCmd.rate = 0;
+ mConfigCmd.latency = 0;
+ mConfigCmd.cmd = CONFIG_CMD_CFG_DATA;
+ if (setType(&mConfigCmd, argv[2])) {
+ printf("Unsupported sensor: %s For action: %s\n", argv[2], argv[1]);
+ return 1;
+ }
+ if (mConfigCmd.sensorType == SENS_TYPE_LEDS ||
+ mConfigCmd.sensorType == SENS_TYPE_LEDS_I2C) {
+ struct LedsCfg mLedsCfg;
+
+ if (argc != 5) {
+ printf("Wrong arg number\n");
+ return 1;
+ }
+ length = sizeof(struct ConfigCmd) + sizeof(struct LedsCfg *);
+ pConfigCmd = (struct ConfigCmd *)malloc(length);
+ if (!pConfigCmd)
+ return 1;
+ mLedsCfg.led_num = atoi(argv[3]);
+ mLedsCfg.value = atoi(argv[4]);
+ memcpy(pConfigCmd, &mConfigCmd, sizeof(mConfigCmd));
+ memcpy(pConfigCmd->data, &mLedsCfg, sizeof(mLedsCfg));
+ } else {
+ printf("Unsupported sensor: %s For action: %s\n", argv[2], argv[1]);
+ return 1;
+ }
} else if (strcmp(argv[1], "calibrate") == 0) {
if (argc != 3) {
printf("Wrong arg number\n");
@@ -419,9 +463,12 @@ int main(int argc, char *argv[])
return 1;
}
- while (!fileWriteData("/dev/nanohub", &mConfigCmd, sizeof(mConfigCmd)))
+ while (!fileWriteData("/dev/nanohub", pConfigCmd, length))
continue;
+ if (pConfigCmd != &mConfigCmd)
+ free(pConfigCmd);
+
if (drain) {
signal(SIGINT, sig_handle);
fd = open("/dev/nanohub", O_RDONLY);