diff options
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 90 |
1 files changed, 1 insertions, 89 deletions
@@ -45,72 +45,6 @@ le_result_t ioutil_writeToFile (const char *path, void *value, size_t size, size return LE_OK; } -// TODO verify this is working -le_result_t gpio_exportPin (int pin) { - return ioutil_writeToFile("/sys/class/gpio/export", &pin, sizeof(int), 1); -} - -le_result_t gpio_unexportPin (int pin) { - return ioutil_writeToFile("/sys/class/gpio/unexport", &pin, sizeof(int), 1); -} - -void getGpioPath (char *outputStr, int pin, char *subDir) { - sprintf(outputStr, "/sys/class/gpio/gpio%d/%s", pin, subDir); -} - -le_result_t gpio_setDirection (int pin, char *direction) { - char path[50]; - getGpioPath(path, pin, "direction"); - return ioutil_writeToFile(path, direction, sizeof(char), strlen(direction)); -} - -le_result_t gpio_setInput (int pin) { - return gpio_setDirection(pin, "in"); -} - -le_result_t gpio_setOutput (int pin) { - return gpio_setDirection(pin, "out"); -} - -le_result_t gpio_setActiveState (int pin, bool isActiveLow) { - // Any non zero value toggles the existing value - // so we must read the existing value first - char path[50]; - int isActiveLowSet; - getGpioPath(path, pin, "active_low"); - le_result_t readRes = ioutil_readIntFromFile(path, &isActiveLowSet); - le_result_t writeRes = LE_OK; - if (isActiveLow != isActiveLowSet) { - writeRes = ioutil_writeToFile(path, "1", sizeof(char), 1); - } - return readRes == LE_OK && writeRes == LE_OK ? - LE_OK : LE_FAULT; -} - -le_result_t gpio_isActive (int pin, bool *isActive) { - char path[50]; - getGpioPath(path, pin, "value"); - int val; - le_result_t readRes = ioutil_readIntFromFile(path, &val); - LE_INFO("Raw value (from %s): %d", path, val); - *isActive = val; - return readRes; -} - -le_result_t gpio_setValue (int pin, bool state) { - char path[50]; - getGpioPath(path, pin, "value"); - return ioutil_writeToFile(path, &state, sizeof(bool), 1); -} - -le_result_t gpio_setLow (int pin) { - return gpio_setValue(pin, LOW); -} - -le_result_t gpio_setHigh (int pin) { - return gpio_setValue(pin, HIGH); -} - le_result_t util_flattenRes (le_result_t *res, int nRes) { for (int i = 0; i < nRes; i++) { le_result_t *resPtr = res + i; @@ -135,31 +69,9 @@ time_t util_getMTime (char *path) { else return st.st_mtime; } -/** - * Convenience function to get current time as uint64_t. - * - * @return - * Current time as a uint64_t - */ uint64_t GetCurrentTimestamp(void) { struct timeval tv; gettimeofday(&tv, NULL); uint64_t utcMilliSec = (uint64_t)(tv.tv_sec) * 1000 + (uint64_t)(tv.tv_usec) / 1000; return utcMilliSec; -} - -// Functions below are deprecated -void delayMicro (unsigned long microsecs) { - unsigned long retTime = getTimeMicrosecs() + microsecs; - while (getTimeMicrosecs() < retTime); -} - -void delayMilli (unsigned long millisecs) { - delayMicro(millisecs * 1000); -} - -long getTimeMicrosecs () { - struct timeval currentTime; - gettimeofday(¤tTime, NULL); - return currentTime.tv_sec * (int)1e6 + currentTime.tv_usec; -} +}
\ No newline at end of file |