static int write_to_syslog( int level, int error, const char *file, int line, const char *func, const char *buffer) { char header_priority[2 + DECIMAL_STR_MAX(int) + 1], header_time[64], header_pid[4 + DECIMAL_STR_MAX(pid_t) + 1]; struct iovec iovec[5] = {}; struct msghdr msghdr = { .msg_iov = iovec, .msg_iovlen = ELEMENTSOF(iovec), }; time_t t; struct tm *tm; if (syslog_fd < 0) return 0; xsprintf(header_priority, "<%i>", level); t = (time_t) (now(CLOCK_REALTIME) / USEC_PER_SEC); tm = localtime(&t); if (!tm) return -EINVAL; if (strftime(header_time, sizeof(header_time), "%h %e %T ", tm) <= 0) return -EINVAL; xsprintf(header_pid, "["PID_FMT"]: ", getpid()); IOVEC_SET_STRING(iovec[0], header_priority); IOVEC_SET_STRING(iovec[1], header_time); IOVEC_SET_STRING(iovec[2], program_invocation_short_name); IOVEC_SET_STRING(iovec[3], header_pid); IOVEC_SET_STRING(iovec[4], buffer); /* When using syslog via SOCK_STREAM separate the messages by NUL chars */ if (syslog_is_stream) iovec[4].iov_len++; for (;;) { ssize_t n; n = sendmsg(syslog_fd, &msghdr, MSG_NOSIGNAL); if (n < 0) return -errno; if (!syslog_is_stream || (size_t) n >= IOVEC_TOTAL_SIZE(iovec, ELEMENTSOF(iovec))) break; IOVEC_INCREMENT(iovec, ELEMENTSOF(iovec), n); } return 1; }
static int write_to_kmsg( int level, int error, const char *file, int line, const char *func, const char *object_field, const char *object, const char *buffer) { char header_priority[2 + DECIMAL_STR_MAX(int) + 1], header_pid[4 + DECIMAL_STR_MAX(pid_t) + 1]; struct iovec iovec[5] = {}; if (kmsg_fd < 0) return 0; xsprintf(header_priority, "<%i>", level); xsprintf(header_pid, "["PID_FMT"]: ", getpid()); IOVEC_SET_STRING(iovec[0], header_priority); IOVEC_SET_STRING(iovec[1], program_invocation_short_name); IOVEC_SET_STRING(iovec[2], header_pid); IOVEC_SET_STRING(iovec[3], buffer); IOVEC_SET_STRING(iovec[4], "\n"); if (writev(kmsg_fd, iovec, ELEMENTSOF(iovec)) < 0) return -errno; return 1; }
/* Any time an access gets denied this callback will be called with the audit data. We then need to just copy the audit data into the msgbuf. */ static int audit_callback( void *auditdata, security_class_t cls, char *msgbuf, size_t msgbufsize) { const struct audit_info *audit = auditdata; uid_t uid = 0, login_uid = 0; gid_t gid = 0; char login_uid_buf[DECIMAL_STR_MAX(uid_t) + 1] = "n/a"; char uid_buf[DECIMAL_STR_MAX(uid_t) + 1] = "n/a"; char gid_buf[DECIMAL_STR_MAX(gid_t) + 1] = "n/a"; if (sd_bus_creds_get_audit_login_uid(audit->creds, &login_uid) >= 0) xsprintf(login_uid_buf, UID_FMT, login_uid); if (sd_bus_creds_get_euid(audit->creds, &uid) >= 0) xsprintf(uid_buf, UID_FMT, uid); if (sd_bus_creds_get_egid(audit->creds, &gid) >= 0) xsprintf(gid_buf, GID_FMT, gid); snprintf(msgbuf, msgbufsize, "auid=%s uid=%s gid=%s%s%s%s%s%s%s", login_uid_buf, uid_buf, gid_buf, audit->path ? " path=\"" : "", strempty(audit->path), audit->path ? "\"" : "", audit->cmdline ? " cmdline=\"" : "", strempty(audit->cmdline), audit->cmdline ? "\"" : ""); return 0; }
void CE_SetNumArg (CodeEntry* E, long Num) /* Set a new numeric argument for the given code entry that must already ** have a numeric argument. */ { char Buf[16]; /* Check that the entry has a numerical argument */ CHECK (E->Flags & CEF_NUMARG); /* Make the new argument string */ if (E->Size == 2) { Num &= 0xFF; xsprintf (Buf, sizeof (Buf), "$%02X", (unsigned) Num); } else if (E->Size == 3) { Num &= 0xFFFF; xsprintf (Buf, sizeof (Buf), "$%04X", (unsigned) Num); } else { Internal ("Invalid instruction size in CE_SetNumArg"); } /* Replace the argument by the new one */ CE_SetArg (E, Buf); /* Use the new numerical value */ E->Num = Num; }
void server_forward_kmsg( Server *s, int priority, const char *identifier, const char *message, const struct ucred *ucred) { struct iovec iovec[5]; char header_priority[DECIMAL_STR_MAX(priority) + 3], header_pid[sizeof("[]: ")-1 + DECIMAL_STR_MAX(pid_t) + 1]; int n = 0; char *ident_buf = NULL; assert(s); assert(priority >= 0); assert(priority <= 999); assert(message); if (_unlikely_(LOG_PRI(priority) > s->max_level_kmsg)) return; if (_unlikely_(s->dev_kmsg_fd < 0)) return; /* Never allow messages with kernel facility to be written to * kmsg, regardless where the data comes from. */ priority = syslog_fixup_facility(priority); /* First: priority field */ xsprintf(header_priority, "<%i>", priority); IOVEC_SET_STRING(iovec[n++], header_priority); /* Second: identifier and PID */ if (ucred) { if (!identifier) { get_process_comm(ucred->pid, &ident_buf); identifier = ident_buf; } xsprintf(header_pid, "["PID_FMT"]: ", ucred->pid); if (identifier) IOVEC_SET_STRING(iovec[n++], identifier); IOVEC_SET_STRING(iovec[n++], header_pid); } else if (identifier) { IOVEC_SET_STRING(iovec[n++], identifier); IOVEC_SET_STRING(iovec[n++], ": "); } /* Fourth: message */ IOVEC_SET_STRING(iovec[n++], message); IOVEC_SET_STRING(iovec[n++], "\n"); if (writev(s->dev_kmsg_fd, iovec, n) < 0) log_debug_errno(errno, "Failed to write to /dev/kmsg for logging: %m"); free(ident_buf); }
static void initTestNotes() { const int notesSize = 4; for (int i = 0; i < notesSize; i++) { xsprintf(noteTitles[i],"Titolo %d",i); xsprintf(notesSubtitles[i],"Sottotitolo %d",i); xsprintf(notes[i],"Nota %d",i); } }
/* * Read a capability attribute and return bitmask. * @param dev udev_device * @param attr sysfs attribute name (e. g. "capabilities/key") * @param bitmask: Output array which has a sizeof of bitmask_size */ static void get_cap_mask(struct udev_device *dev, struct udev_device *pdev, const char* attr, unsigned long *bitmask, size_t bitmask_size, bool test) { const char *v; char text[4096]; unsigned i; char* word; unsigned long val; v = udev_device_get_sysattr_value(pdev, attr); if (!v) v = ""; xsprintf(text, "%s", v); log_debug("%s raw kernel attribute: %s", attr, text); memzero(bitmask, bitmask_size); i = 0; while ((word = strrchr(text, ' ')) != NULL) { val = strtoul (word+1, NULL, 16); if (i < bitmask_size/sizeof(unsigned long)) bitmask[i] = val; else log_debug("ignoring %s block %lX which is larger than maximum size", attr, val); *word = '\0'; ++i; } val = strtoul (text, NULL, 16); if (i < bitmask_size / sizeof(unsigned long)) bitmask[i] = val; else log_debug("ignoring %s block %lX which is larger than maximum size", attr, val); if (test) { /* printf pattern with the right unsigned long number of hex chars */ xsprintf(text, " bit %%4u: %%0%zulX\n", 2 * sizeof(unsigned long)); log_debug("%s decoded bit map:", attr); val = bitmask_size / sizeof (unsigned long); /* skip over leading zeros */ while (bitmask[val-1] == 0 && val > 0) --val; for (i = 0; i < val; ++i) { DISABLE_WARNING_FORMAT_NONLITERAL; log_debug(text, i * BITS_PER_LONG, bitmask[i]); REENABLE_WARNING; } } }
const char *signal_to_string(int signo) { static thread_local char buf[sizeof("RTMIN+")-1 + DECIMAL_STR_MAX(int) + 1]; const char *name; name = __signal_to_string(signo); if (name) return name; if (signo >= SIGRTMIN && signo <= SIGRTMAX) xsprintf(buf, "RTMIN+%d", signo - SIGRTMIN); else xsprintf(buf, "%d", signo); return buf; }
static void pcconsole_probe(cfe_driver_t *drv, unsigned long probe_a, unsigned long probe_b, void *probe_ptr) { pcconsole_t *softc; char descr[80]; /* * probe_a is * probe_b is * probe_ptr is */ softc = (pcconsole_t *) KMALLOC(sizeof(pcconsole_t),0); if (softc) { memset(softc,0,sizeof(pcconsole_t)); vga_init(&(softc->vga),__ISAaddr(VGA_TEXTBUF_COLOR),outb); xsprintf(descr,"%s",drv->drv_description,probe_a,probe_b); cfe_attach(drv,softc,NULL,descr); } }
void update_tan_entry(void) { u8 current_level; current_level = get_current_tan_level(); xsprintf(tan_level_buffer, "Current tan level: %d", current_level); }
static void set_trackpoint_sensitivity(struct udev_device *dev, const char *value) { struct udev_device *pdev; char val_s[DECIMAL_STR_MAX(int)]; int r, val_i; assert(dev); assert(value); /* The sensitivity sysfs attr belongs to the serio parent device */ pdev = udev_device_get_parent_with_subsystem_devtype(dev, "serio", NULL); if (!pdev) { log_warning("Failed to get serio parent for '%s'", udev_device_get_devnode(dev)); return; } r = safe_atoi(value, &val_i); if (r < 0) { log_error("Unable to parse POINTINGSTICK_SENSITIVITY '%s' for '%s'", value, udev_device_get_devnode(dev)); return; } xsprintf(val_s, "%d", val_i); r = udev_device_set_sysattr_value(pdev, "sensitivity", val_s); if (r < 0) log_error_errno(r, "Failed to write 'sensitivity' attribute for '%s': %m", udev_device_get_devnode(pdev)); }
_public_ int sd_journal_printv(int priority, const char *format, va_list ap) { /* FIXME: Instead of limiting things to LINE_MAX we could do a C99 variable-length array on the stack here in a loop. */ char buffer[8 + LINE_MAX], p[sizeof("PRIORITY=")-1 + DECIMAL_STR_MAX(int) + 1]; struct iovec iov[2]; assert_return(priority >= 0, -EINVAL); assert_return(priority <= 7, -EINVAL); assert_return(format, -EINVAL); xsprintf(p, "PRIORITY=%i", priority & LOG_PRIMASK); memcpy(buffer, "MESSAGE=", 8); vsnprintf(buffer+8, sizeof(buffer) - 8, format, ap); /* Strip trailing whitespace, keep prefix whitespace. */ (void) strstrip(buffer); /* Suppress empty lines */ if (isempty(buffer+8)) return 0; zero(iov); IOVEC_SET_STRING(iov[0], buffer); IOVEC_SET_STRING(iov[1], p); return sd_journal_sendv(iov, 2); }
static int network_link_get_strv(int ifindex, const char *key, char ***ret) { char path[STRLEN("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex) + 1]; _cleanup_strv_free_ char **a = NULL; _cleanup_free_ char *s = NULL; int r; assert_return(ifindex > 0, -EINVAL); assert_return(ret, -EINVAL); xsprintf(path, "/run/systemd/netif/links/%i", ifindex); r = parse_env_file(path, NEWLINE, key, &s, NULL); if (r == -ENOENT) return -ENODATA; if (r < 0) return r; if (isempty(s)) { *ret = NULL; return 0; } a = strv_split(s, " "); if (!a) return -ENOMEM; strv_uniq(a); r = strv_length(a); *ret = TAKE_PTR(a); return r; }
//***************************************************************************** // 関数名 : remote_start // 引数 : 無し // 返り値 : 1(スタート)/0(待機) // 概要 : Bluetooth通信によるリモートスタート。 TeraTermなどのターミナルソフトから、 // ASCIIコードで1を送信すると、リモートスタートする。 //***************************************************************************** int remote_start(void) { int i; unsigned int rx_len; unsigned char start = 0; for (i=0; i< BT_MAX_RX_BUF_SIZE; i++) { rx_buf[i] = 0; /* 受信バッファをクリア */ } rx_len = ecrobot_read_bt(rx_buf, 0, BT_MAX_RX_BUF_SIZE); if (rx_len > 0) { /* 受信データあり */ if (rx_buf[0] == 'i' || rx_buf[0] == 'I') { start = R_course; /* IN 走行開始 */ } if (rx_buf[0] == 'o' || rx_buf[0] == 'O') { start = L_course; /* OUT 走行開始 */ } if (rx_buf[0] == 't' || rx_buf[0] == 'T') { start = TEST; /* OUT 走行開始 */ } ecrobot_send_bt(rx_buf, 0, rx_len); /* 受信データをエコーバック */ xsprintf(tx_buf,"\n course = %d\n",start); ecrobot_send_bt(tx_buf, 0, strlen(tx_buf)); } return start; }
static const char* LabelPlusOffs (const char* Label, long Offs) /* Generate "Label+xxx" in a static buffer and return a pointer to the buffer */ { static char Buf[256]; xsprintf (Buf, sizeof (Buf), "%s%+ld", Label, Offs); return Buf; }
static void sb1250_uart_probe(cfe_driver_t *drv, unsigned long probe_a, unsigned long probe_b, void *probe_ptr) { sb1250_uart_t *softc; char descr[80]; /* * probe_a is the DUART base address. * probe_b is the channel-number-within-duart (0 or 1) * probe_ptr is unused. */ softc = (sb1250_uart_t *) KMALLOC(sizeof(sb1250_uart_t),0); if (softc) { softc->uart_mode_reg_1 = probe_a + R_DUART_CHANREG(probe_b,R_DUART_MODE_REG_1); softc->uart_mode_reg_2 = probe_a + R_DUART_CHANREG(probe_b,R_DUART_MODE_REG_2); softc->uart_clk_sel = probe_a + R_DUART_CHANREG(probe_b,R_DUART_CLK_SEL); softc->uart_cmd = probe_a + R_DUART_CHANREG(probe_b,R_DUART_CMD); softc->uart_status = probe_a + R_DUART_CHANREG(probe_b,R_DUART_STATUS); softc->uart_tx_hold = probe_a + R_DUART_CHANREG(probe_b,R_DUART_TX_HOLD); softc->uart_rx_hold = probe_a + R_DUART_CHANREG(probe_b,R_DUART_RX_HOLD); softc->uart_imr = probe_a + R_DUART_IMRREG(probe_b); softc->uart_oprset = probe_a + R_DUART_SET_OPR; xsprintf(descr,"%s at 0x%X channel %d",drv->drv_description,probe_a,probe_b); softc->uart_speed = CFG_SERIAL_BAUD_RATE; softc->uart_flowcontrol = SERIAL_FLOW_NONE; cfe_attach(drv,softc,NULL,descr); } }
int cfe_attach_idx(cfe_driver_t *drv,int idx,void *softc, char *bootinfo,char *description) { char name[64]; cfe_device_t *dev; xsprintf(name,"%s%d",drv->drv_bootname,idx); if (bootinfo) { strcat(name,"."); strcat(name,bootinfo); } if (cfe_finddev(name) != NULL) { return 0; } dev = (cfe_device_t *) KMALLOC(sizeof(cfe_device_t),0); if (!dev) return -1; dev->dev_fullname = strdup(name); dev->dev_softc = softc; dev->dev_class = drv->drv_class; dev->dev_dispatch = drv->drv_dispatch; dev->dev_description = description ? strdup(description) : NULL; dev->dev_opencount = 0; q_enqueue(&cfe_devices,(queue_t *) dev); return 1; }
static void cfe_setup_default_env(void) { char buffer[80]; xsprintf(buffer,"%d.%d.%d",CFE_VER_MAJOR,CFE_VER_MINOR,CFE_VER_BUILD); env_setenv("CFE_VERSION",buffer,ENV_FLG_BUILTIN | ENV_FLG_READONLY); if (cfe_boardname) { env_setenv("CFE_BOARDNAME",(char *) cfe_boardname, ENV_FLG_BUILTIN | ENV_FLG_READONLY); } xsprintf(buffer,"%d",mem_totalsize); env_setenv("CFE_MEMORYSIZE",buffer,ENV_FLG_BUILTIN | ENV_FLG_READONLY); }
static const char* MakeLabelName (unsigned Addr) /* Make the default label name from the given address and return it in a * static buffer. */ { static char LabelBuf [32]; xsprintf (LabelBuf, sizeof (LabelBuf), "L%04X", Addr); return LabelBuf; }
static int write_to_console( int level, int error, const char *file, int line, const char *func, const char *buffer) { char location[256], prefix[1 + DECIMAL_STR_MAX(int) + 2]; struct iovec iovec[6] = {}; unsigned n = 0; bool highlight; if (console_fd < 0) return 0; if (log_target == LOG_TARGET_CONSOLE_PREFIXED) { xsprintf(prefix, "<%i>", level); IOVEC_SET_STRING(iovec[n++], prefix); } highlight = LOG_PRI(level) <= LOG_ERR && show_color; if (show_location) { snprintf(location, sizeof(location), "(%s:%i) ", file, line); IOVEC_SET_STRING(iovec[n++], location); } if (highlight) IOVEC_SET_STRING(iovec[n++], ANSI_HIGHLIGHT_RED); IOVEC_SET_STRING(iovec[n++], buffer); if (highlight) IOVEC_SET_STRING(iovec[n++], ANSI_NORMAL); IOVEC_SET_STRING(iovec[n++], "\n"); if (writev(console_fd, iovec, n) < 0) { if (errno == EIO && getpid() == 1) { /* If somebody tried to kick us from our * console tty (via vhangup() or suchlike), * try to reconnect */ log_close_console(); log_open_console(); if (console_fd < 0) return 0; if (writev(console_fd, iovec, n) < 0) return -errno; } else return -errno; } return 1; }
char* AnonName (char* Buf, const char* Spec) /* Get a name for an anonymous variable or type. The given buffer is expected * to be IDENTSIZE characters long. A pointer to the buffer is returned. */ { static unsigned ACount = 0; xsprintf (Buf, IDENTSIZE, "%s-%s-%04X", AnonTag, Spec, ++ACount); return Buf; }
static void test_get_process_comm(pid_t pid) { struct stat st; _cleanup_free_ char *a = NULL, *c = NULL, *d = NULL, *f = NULL, *i = NULL; _cleanup_free_ char *env = NULL; char path[strlen("/proc//comm") + DECIMAL_STR_MAX(pid_t)]; pid_t e; uid_t u; gid_t g; dev_t h; int r; xsprintf(path, "/proc/"PID_FMT"/comm", pid); if (stat(path, &st) == 0) { assert_se(get_process_comm(pid, &a) >= 0); log_info("PID"PID_FMT" comm: '%s'", pid, a); } else log_warning("%s not exist.", path); assert_se(get_process_cmdline(pid, 0, true, &c) >= 0); log_info("PID"PID_FMT" cmdline: '%s'", pid, c); assert_se(get_process_cmdline(pid, 8, false, &d) >= 0); log_info("PID"PID_FMT" cmdline truncated to 8: '%s'", pid, d); free(d); assert_se(get_process_cmdline(pid, 1, false, &d) >= 0); log_info("PID"PID_FMT" cmdline truncated to 1: '%s'", pid, d); assert_se(get_process_ppid(pid, &e) >= 0); log_info("PID"PID_FMT" PPID: "PID_FMT, pid, e); assert_se(pid == 1 ? e == 0 : e > 0); assert_se(is_kernel_thread(pid) == 0 || pid != 1); r = get_process_exe(pid, &f); assert_se(r >= 0 || r == -EACCES); log_info("PID"PID_FMT" exe: '%s'", pid, strna(f)); assert_se(get_process_uid(pid, &u) == 0); log_info("PID"PID_FMT" UID: "UID_FMT, pid, u); assert_se(u == 0 || pid != 1); assert_se(get_process_gid(pid, &g) == 0); log_info("PID"PID_FMT" GID: "GID_FMT, pid, g); assert_se(g == 0 || pid != 1); r = get_process_environ(pid, &env); assert_se(r >= 0 || r == -EACCES); log_info("PID"PID_FMT" strlen(environ): %zi", pid, env ? (ssize_t)strlen(env) : (ssize_t)-errno); if (!detect_container()) assert_se(get_ctty_devnr(pid, &h) == -ENXIO || pid != 1); getenv_for_pid(pid, "PATH", &i); log_info("PID"PID_FMT" $PATH: '%s'", pid, strna(i)); }
void fault_handler(regs_t* r) { if (r->int_no < 32) { char buffer[256]; xsprintf(buffer, "%s Exception. System Halted!", exception_messages[r->int_no]); PANIC(buffer); for (;;); } }
static const char* GetAddrArg (unsigned Flags, unsigned Addr) /* Return an address argument - a label if we have one, or the address itself */ { const char* Label = 0; if (Flags & flUseLabel) { Label = GetLabel (Addr, PC); } if (Label) { return Label; } else { static char Buf [32]; if (Addr < 0x100) { xsprintf (Buf, sizeof (Buf), "$%02X", Addr); } else { xsprintf (Buf, sizeof (Buf), "$%04X", Addr); } return Buf; } }
const char * signame(const int sig) { static char buf[sizeof("SIGRT_%u") + sizeof(int)*3]; if (sig >= 0) { const unsigned int s = sig; if (s < nsignals) return signalent[s]; #ifdef ASM_SIGRTMAX if (s >= ASM_SIGRTMIN && s <= (unsigned int) ASM_SIGRTMAX) { xsprintf(buf, "SIGRT_%u", s - ASM_SIGRTMIN); return buf; } #endif } xsprintf(buf, "%d", sig); return buf; }
static int stdout_stream_install(Server *s, int fd, StdoutStream **ret) { _cleanup_(stdout_stream_freep) StdoutStream *stream = NULL; sd_id128_t id; int r; assert(s); assert(fd >= 0); r = sd_id128_randomize(&id); if (r < 0) return log_error_errno(r, "Failed to generate stream ID: %m"); stream = new0(StdoutStream, 1); if (!stream) return log_oom(); stream->fd = -1; stream->priority = LOG_INFO; xsprintf(stream->id_field, "_STREAM_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(id)); r = getpeercred(fd, &stream->ucred); if (r < 0) return log_error_errno(r, "Failed to determine peer credentials: %m"); if (mac_selinux_use()) { r = getpeersec(fd, &stream->label); if (r < 0 && r != -EOPNOTSUPP) (void) log_warning_errno(r, "Failed to determine peer security context: %m"); } (void) shutdown(fd, SHUT_WR); r = sd_event_add_io(s->event, &stream->event_source, fd, EPOLLIN, stdout_stream_process, stream); if (r < 0) return log_error_errno(r, "Failed to add stream to event loop: %m"); r = sd_event_source_set_priority(stream->event_source, SD_EVENT_PRIORITY_NORMAL+5); if (r < 0) return log_error_errno(r, "Failed to adjust stdout event source priority: %m"); stream->fd = fd; stream->server = s; LIST_PREPEND(stdout_stream, s->stdout_streams, stream); s->n_stdout_streams++; if (ret) *ret = stream; stream = NULL; return 0; }
void addr2str (mem_addr_t *addr, char *dest) { #ifdef HAVE_ASI if (addr->asi != ASI_DEFAULT) xsprintf(dest, "[%x]", addr->asi); else #endif dest[0] = 0; strcat (dest, int2str (addr->addr, 16, sizeof (void *) * 2)); }
//It is unfortunate that QNH as argument here is different from global ONH... // TODO: Fix it sometime... void draw_alt(int pressure, int temperature, int altitude_m, int altitude_ft, int QNH) { //Display locations: const int BARO_x=2, BARO_y=13; //const int TEMP_x=4, TEMP_y=20; const int ALTM_x=4, ALTM_y=30; const int ALTFT_x=30, ALTFT_y=47; const int QNH_x=2, QNH_y=62; char array[BUFSIZE]; u8g_SetFont(&u8g, NORMALFONT); if(pressure>0){ xsprintf(array, "P:%uhpa T:%uC", pressure,temperature); }else{ xsprintf(array, "P:-%uhpa T:%uC", -pressure,temperature); } u8g_DrawStr(&u8g, BARO_x, BARO_y, array); // xsprintf(array, "Temp : %u", temperature); // u8g_DrawStr(&u8g, TEMP_x, TEMP_y, array); u8g_DrawStr (&u8g, 0, ALTFT_y-8, "Alt:"); u8g_DrawStr (&u8g, ALTFT_x+76, ALTFT_y-8, "ft"); xsprintf(array, "QNH: %uhpa", QNH); u8g_DrawStr(&u8g, QNH_x, QNH_y, array); u8g_SetFont(&u8g, u8g_font_fub25n); //This also works... if (altitude_ft>=0){ //Workaround with %u in displaying negative values. xsprintf(array, "%u",altitude_ft); }else{ xsprintf(array, "-%u",-altitude_ft); } u8g_DrawStr(&u8g, ALTFT_x, ALTFT_y, array); // xsprintf(array, "Alt : %u m",altitude_m); //u8g_DrawStr(&u8g, ALTM_x, ALTM_y, array); //u8g_DrawRFrame(&u8g, 8,6,96,38,8);// (x,y,h,l,radius) }
const char* MakeHexArg (unsigned Num) /* Convert Num into a string in the form $XY, suitable for passing it as an ** argument to NewCodeEntry, and return a pointer to the string. ** BEWARE: The function returns a pointer to a static buffer, so the value is ** gone if you call it twice (and apart from that it's not thread and signal ** safe). */ { static char Buf[16]; xsprintf (Buf, sizeof (Buf), "$%02X", (unsigned char) Num); return Buf; }
static FRESULT play ( const char *dir, /* Directory */ const char *fn /* File */ ) { DWORD sz; FRESULT res; BYTE sw; WORD btr; wdt_reset(); xsprintf((char*)Buff, PSTR("%s/%s"), dir, fn); res = pf_open((char*)Buff); /* Open sound file */ if (res == FR_OK) { sz = load_header(); /* Check file format and ready to play */ if (sz < 1024) return 255; /* Cannot play this file */ FifoCt = 0; FifoRi = 0; FifoWi = 0; /* Reset audio FIFO */ if (!TCCR1) { /* Enable audio out if not enabled */ PLLCSR = 0b00000110; /* Select PLL clock for TC1.ck */ GTCCR = 0b01100000; /* Enable OC1B as PWM */ TCCR1 = MODE ? 0b01100001 : 0b00000001; /* Start TC1 and enable OC1A as PWM if needed */ TCCR0A = 0b00000010; /* Statr TC0 as interval timer at 2MHz */ TCCR0B = 0b00000010; TIMSK = _BV(OCIE0A); ramp(1); } pf_read(0, 512 - (Fs.fptr % 512), &rb); /* Snip sector unaligned part */ sz -= rb; sw = 1; /* Button status flag */ do { /* Data transfer loop */ wdt_reset(); btr = (sz > 1024) ? 1024 : (WORD)sz;/* A chunk of audio data */ res = pf_read(0, btr, &rb); /* Forward the data into audio FIFO */ if (rb != 1024) break; /* Break on error or end of data */ sz -= rb; /* Decrease data counter */ sw <<= 1; /* Break on button down */ } while ((PINB & 1) || ++sw != 1); } while (FifoCt) ; /* Wait for audio FIFO empty */ OCR1A = 128; OCR1B = 128; /* Return output to center level */ return res; }