Raw Print

Is there a raw print function that does not convert a number to ASCII but
passes it straight through, as opposed to print! which seems to convert to
ASCII? Or a conversion routine that translates a byte into a number such
that conversion to ASCII results in the same?

This tied me back to the printf stuff, which is a problem for arduino, but
I found support in arduino-ats for a print_char shown below. However, it
seems to convert the uint8 to an ASCII char, or something in the USB pipe
does it.

It is hard for me to believe that the underlying casting can do this,
because I think C just assigns the pointer along the way.

Am I not understanding something fundamental? Does the ATS casting do
anything more than pass the ptr through and deal with it as a type?

implement print_char (c) = {
val _ = serial_write c
}

fun serial_write (value: char): size_t
implement serial_write (c) = let
val () = ringbuf_insert_wait ($UN.cast{uchar}(c), tx_buffer)
val () = c_sbi (ADDR_UCSRB, BIT_UDRIE)
// clear the TXC bit – “can be cleared by writing a one to its bit
location”
val () = set_transmitting (true)
val () = c_sbi (ADDR_UCSRA, BIT_TXC0)
in
$UN.cast{size_t}(1)
end

(* App Code *)

fun write_frame(): void = let
fun loop {n: nat | n < 131} .. (cnt: int(n)): void =
if cnt > 0
then let
val i = packet[n7(!packetCount - u8(cnt))]
val _ = print_char(cast{char}(i))
in loop(cnt - 1) end
in loop(cast{natLt(131)}(!packetCount)) endOn Thursday, October 15, 2015 at 5:36:43 AM UTC-6, gmhwxi wrote:

Maybe this is what you need:

(* ****** ****** *)

#include
“share/atspre_staload.hats”
//
val x =
$UNSAFE.cast{uint8}(48)
//
val () = println! ("x = ", x)
//
fun
my_print_uint8
(i: uint8): void =
print($UNSAFE.cast{uchar}(i))
//
overload print with my_print_uint8 of 10
//
val () = println! ("x = ", x)
//
implement main0 () = ()

(* ****** ****** *)

On Thursday, October 15, 2015 at 12:04:19 AM UTC-4, Mike Jones wrote:

Is there a raw print function that does not convert a number to ASCII but
passes it straight through, as opposed to print! which seems to convert to
ASCII? Or a conversion routine that translates a byte into a number such
that conversion to ASCII results in the same?

I found my problem. I had an extra print elsewhere for debug putting a few
more characters over the USB.

I apologize for any time wasted on your part.

An example showing what you want?On Thursday, October 15, 2015 at 12:04:19 AM UTC-4, Mike Jones wrote:

Is there a raw print function that does not convert a number to ASCII but
passes it straight through, as opposed to print! which seems to convert to
ASCII? Or a conversion routine that translates a byte into a number such
that conversion to ASCII results in the same?

Maybe this is what you need:

(* ****** ****** *)

#include
“share/atspre_staload.hats”
//
val x =
$UNSAFE.cast{uint8}(48)
//
val () = println! ("x = ", x)
//
fun
my_print_uint8
(i: uint8): void =
print($UNSAFE.cast{uchar}(i))
//
overload print with my_print_uint8 of 10
//
val () = println! ("x = ", x)
//
implement main0 () = ()

(* ****** ****** *)On Thursday, October 15, 2015 at 12:04:19 AM UTC-4, Mike Jones wrote:

Is there a raw print function that does not convert a number to ASCII but
passes it straight through, as opposed to print! which seems to convert to
ASCII? Or a conversion routine that translates a byte into a number such
that conversion to ASCII results in the same?