本文整理匯總了Golang中C.ushort函數的典型用法代碼示例。如果您正苦於以下問題:Golang ushort函數的具體用法?Golang ushort怎麽用?Golang ushort使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ushort函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Open
// Open HID by vendorId, productId and serialNumber.
// SerialNumber is optional and can be empty string ("").
// Returns a *Devica and an error.
func Open(vendorId uint16, productId uint16, serialNumber string) (*Device, error) {
var err error
// call hidInit(). hidInit() checks if actual call to hid_hidInit() is required.
if err = hidInit(); err != nil {
return nil, err
}
// serialNumberWchar value. Default nil.
serialNumberWcharPtr := (*C.wchar_t)(nil)
// if a serialNumber is given, create a WcharString and set the pointer to it's first position pointer
if len(serialNumber) > 0 {
serialNumberWchar, err := wchar.FromGoString(serialNumber)
if err != nil {
return nil, errors.New("Unable to convert serialNumber to WcharString")
}
serialNumberWcharPtr = (*C.wchar_t)(unsafe.Pointer(serialNumberWchar.Pointer()))
}
// call hid_open()
hidHandle := C.hid_open(C.ushort(vendorId), C.ushort(productId), serialNumberWcharPtr)
if hidHandle == nil {
return nil, errors.New("Unable to open device.")
}
dev := &Device{
hidHandle: hidHandle,
}
// done
return dev, nil
}
示例2: SetColorTemp
// SetColorTemp changes the Xrandr colors to reflect the specified color temperature.
func SetColorTemp(temp int) {
dpy := C.XOpenDisplay(nil)
screenCount := C.screenCount(dpy)
for screen := C.int(0); screen < screenCount; screen++ {
root := C.RootWindowMacro(dpy, screen)
res := C.XRRGetScreenResourcesCurrent(dpy, root)
if temp < 1000 || temp > 10000 {
temp = 6500
}
temp -= 1000
ratio := float64((temp-1000)%500) / 500.0
point := whitepoints[temp/500]
gammar := point.r*(1-ratio) + point.r*ratio
gammag := point.g*(1-ratio) + point.g*ratio
gammab := point.b*(1-ratio) + point.b*ratio
for c := C.int(0); c < res.ncrtc; c++ {
crtcxid := C.crtcxid(res.crtcs, c)
size := C.XRRGetCrtcGammaSize(dpy, crtcxid)
crtc_gamma := C.XRRAllocGamma(size)
for i := C.int(0); i < size; i++ {
g := 65535.0 * float64(i) / float64(size)
C.ushortSet(crtc_gamma.red, i, C.ushort(g*gammar))
C.ushortSet(crtc_gamma.green, i, C.ushort(g*gammag))
C.ushortSet(crtc_gamma.blue, i, C.ushort(g*gammab))
}
C.XRRSetCrtcGamma(dpy, crtcxid, crtc_gamma)
C.XFree(unsafe.Pointer(crtc_gamma))
}
}
}
示例3: open
func (t *pty) open(cols, rows int) error {
var winp = new(C.struct_winsize)
winp.ws_col = C.ushort(cols)
winp.ws_row = C.ushort(rows)
winp.ws_xpixel = 0
winp.ws_ypixel = 0
var master, slave C.int
var name = make([]C.char, 40)
if ret := int(C.GoOpenpty(&master, &slave, &name[0], winp)); ret == -1 {
return errors.New("openpty(3) failed")
}
t.master = int(master)
t.slave = int(slave)
t.pty = C.GoString(&name[0])
if err := syscall.SetNonblock(t.master, true); err != nil {
return err
}
if err := syscall.SetNonblock(t.slave, true); err != nil {
return err
}
return nil
}
示例4: makeCWindowSize
func makeCWindowSize(sz *WindowSize) C.struct_winsize {
var winsize C.struct_winsize
winsize.ws_row = C.ushort(sz.Rows)
winsize.ws_col = C.ushort(sz.Cols)
winsize.ws_xpixel = C.ushort(sz.PixelWidth)
winsize.ws_ypixel = C.ushort(sz.PixelHeight)
return winsize
}
示例5: Enumerate
// Retrieve a list of DeviceInfo objects that match the given vendorId and productId.
// To retrieve a list of all HID devices': use 0x0 as vendorId and productId.
func Enumerate(vendorId uint16, productId uint16) (DeviceInfoList, error) {
var err error
// call C.hid_enumerate with given parameters
first := C.hid_enumerate(C.ushort(vendorId), C.ushort(productId))
// check for failure
if first == nil {
return nil, errors.New("Could not enumerate devices. Failure.")
}
// defer free-ing first
defer C.hid_free_enumeration(first)
// make DeviceInfoList to fill
dil := make(DeviceInfoList, 0)
// loop over linked list to fill DeviceInfoList
for next := first; next != nil; next = next.next {
// create DeviceInfo instance from next hid_device_info
di := &DeviceInfo{
Path: C.GoString(next.path),
VendorId: uint16(next.vendor_id),
ProductId: uint16(next.product_id),
ReleaseNumber: uint16(next.release_number),
UsagePage: uint16(next.usage_page),
Usage: uint16(next.usage),
InterfaceNumber: int(next.interface_number),
}
// get and convert serial_number from next hid_device_info
di.SerialNumber, err = wchar.WcharStringPtrToGoString(unsafe.Pointer(next.serial_number))
if err != nil {
log.Println("Error converting the Serial Number, setting to empty string")
di.SerialNumber = ""
}
// get and convert manufacturer_string from next hid_device_info
di.Manufacturer, err = wchar.WcharStringPtrToGoString(unsafe.Pointer(next.manufacturer_string))
if err != nil {
log.Println("Error converting the Manufacturer, setting to empty string")
di.Manufacturer = ""
}
// get and convert product_string from next hid_device_info
di.Product, err = wchar.WcharStringPtrToGoString(unsafe.Pointer(next.product_string))
if err != nil {
return nil, fmt.Errorf("Could not convert *C.wchar_t product_string from hid_device_info to go string. Error: %s\n", err)
}
// store di in dil
dil = append(dil, di)
}
// all done
return dil, nil
}
示例6: ffi_type_make
func ffi_type_make(size int, alignment int, typ CType,
elements **C.ffi_type) C.ffi_type {
csize := C.size_t(size)
calign := C.ushort(alignment)
ctype := C.ushort(typ)
celem := (**_Cstruct__ffi_type)(elements)
return C.ffi_type{csize, calign, ctype, celem}
}
示例7: getInfo
func (s *Sheet) getInfo(i int, handle unsafe.Pointer) error {
var name *C.char
var numRow C.uint
var numCol C.ushort
ret := C.freexl_get_worksheet_name(handle, C.ushort(i), &name)
if ret != OK {
return fmt.Errorf("Freexl: error get sheet name :%d", ret)
}
s.Name = C.GoString(name)
ret = C.freexl_select_active_worksheet(handle, C.ushort(i))
if ret != OK {
return fmt.Errorf("Freexl: failed to selct worksheet: %s", ret)
}
ret = C.freexl_worksheet_dimensions(handle, &numRow, &numCol)
if ret != OK {
return fmt.Errorf("Freexl: failed to get dimensions: %s", ret)
}
s.MaxRow = int(numRow)
s.MaxCol = int(numCol)
s.Values = make([][]string, s.MaxRow)
for i, row := range s.Values {
row = make([]string, s.MaxCol)
var cell C.FreeXL_CellValue
for j := range row {
ret = C.freexl_get_cell_value(handle, C.uint(i), C.ushort(j), &cell)
if ret != OK {
continue
}
switch C.freexl_cell_get_type(cell) {
case CELL_DOUBLE:
row[j] = fmt.Sprintf("%1.12f", float64(C.freexl_cell_get_double_value(cell)))
case CELL_INT:
row[j] = fmt.Sprintf("%d", int(C.freexl_cell_get_int_value(cell)))
case CELL_TEXT, CELL_SST_TEXT, CELL_DATE, CELL_DATETIME, CELL_TIME:
row[j] = C.GoString(C.freexl_cell_get_text_value(cell))
default:
fallthrough
case CELL_NULL:
row[j] = ""
}
}
s.Values[i] = row
}
return nil
}
示例8: toPtr
func (this *GammaRamp) toPtr() (ptr *C.GLFWgammaramp) {
size := C.size_t(unsafe.Sizeof(ptr))
ptr = (*C.GLFWgammaramp)(C.malloc(size))
for i := 0; i < GammaRampSize; i++ {
ptr.red[i] = C.ushort(this.Red[i])
ptr.green[i] = C.ushort(this.Green[i])
ptr.blue[i] = C.ushort(this.Blue[i])
}
return
}
示例9: resize
func (t *pty) resize(cols, rows int) error {
var winp = new(C.struct_winsize)
winp.ws_col = C.ushort(cols)
winp.ws_row = C.ushort(rows)
winp.ws_xpixel = 0
winp.ws_ypixel = 0
if ret := int(C.GoResize(C.int(t.fd), winp)); ret == -1 {
return errors.New("ioctl(2) failed")
}
return nil
}
示例10: SetGammaRamp
//SetGammaRamp sets the current gamma ramp for the monitor.
func (m *Monitor) SetGammaRamp(ramp *GammaRamp) {
var rampC C.GLFWgammaramp
length := len(ramp.Red)
for i := 0; i < length; i++ {
C.SetGammaAtIndex(rampC.red, C.int(i), C.ushort(ramp.Red[i]))
C.SetGammaAtIndex(rampC.green, C.int(i), C.ushort(ramp.Green[i]))
C.SetGammaAtIndex(rampC.blue, C.int(i), C.ushort(ramp.Blue[i]))
}
C.glfwSetGammaRamp(m.data, &rampC)
}
示例11: addPrinter
func (z *zeroconf) addPrinter(name string, port uint16, ty, url, id string, online bool) error {
r := record{
name: C.CString(name),
port: port,
ty: ty,
url: url,
id: id,
online: online,
}
z.spMutex.Lock()
defer z.spMutex.Unlock()
if _, exists := z.printers[name]; exists {
return fmt.Errorf("printer %s was already added to Avahi publishing", name)
}
if z.state == C.AVAHI_CLIENT_S_RUNNING {
txt := prepareTXT(ty, url, id, online)
defer C.avahi_string_list_free(txt)
C.avahi_threaded_poll_lock(z.threadedPoll)
defer C.avahi_threaded_poll_unlock(z.threadedPoll)
if errstr := C.addAvahiGroup(z.threadedPoll, z.client, &r.group, r.name, C.ushort(r.port), txt); errstr != nil {
err := fmt.Errorf("Failed to add Avahi group: %s", C.GoString(errstr))
return err
}
}
z.printers[name] = r
return nil
}
示例12: updateParameters
func (s *Shout) updateParameters() {
// set hostname
p := C.CString(s.Host)
C.shout_set_host(s.struc, p)
C.free(unsafe.Pointer(p))
// set port
C.shout_set_port(s.struc, C.ushort(s.Port))
// set username
p = C.CString(s.User)
C.shout_set_user(s.struc, p)
C.free(unsafe.Pointer(p))
// set password
p = C.CString(s.Password)
C.shout_set_password(s.struc, p)
C.free(unsafe.Pointer(p))
// set mount point
p = C.CString(s.Mount)
C.shout_set_mount(s.struc, p)
C.free(unsafe.Pointer(p))
// set format
C.shout_set_format(s.struc, C.uint(s.Format))
// set protocol
C.shout_set_protocol(s.struc, C.uint(s.Protocol))
}
示例13: WaitZero
// WaitZero adds and operation that will block until a semaphore's number is 0.
func (so *SemOps) WaitZero(num uint16, flags *SemOpFlags) error {
*so = append(*so, C.struct_sembuf{
sem_num: C.ushort(num),
sem_op: C.short(0),
sem_flg: C.short(flags.flags()),
})
return nil
}
示例14: ConstDefined
// ConstDefined checks if the given constant is defined in the scope.
//
// This should be used, for example, before a call to Class, because a
// failure in Class will crash your program (by design). You can retrieve
// the Value of a Class by calling Value().
func (m *Mrb) ConstDefined(name string, scope Value) bool {
cs := C.CString(name)
defer C.free(unsafe.Pointer(cs))
scopeV := scope.MrbValue(m).value
b := C.mrb_const_defined(
m.state, scopeV, C.mrb_intern_cstr(m.state, cs))
return C.ushort(b) != 0
}
示例15: fork
func (t *pty) fork(file string, args, env []string, cwd string, cols, rows, uid, gid int) error {
var winp = new(C.struct_winsize)
winp.ws_col = C.ushort(cols)
winp.ws_row = C.ushort(rows)
winp.ws_xpixel = 0
winp.ws_ypixel = 0
//fork the pty
var master C.int = -1
var name []C.char = make([]C.char, 40)
var pid C.int = C.GoForkpty(&master, &name[0], winp)
t.fd = int(master)
t.pid = int(pid)
t.pty = C.GoString(&name[0])
switch t.pid {
case -1:
return errors.New("forkpty(3) failed")
case 0:
if cwd != "" {
if err := syscall.Chdir(cwd); err != nil {
panic("chdir failed")
}
}
if uid != -1 && gid != -1 {
if err := syscall.Setgid(gid); err != nil {
panic("setgid failed")
}
if err := syscall.Setuid(uid); err != nil {
panic("setuid failed")
}
}
syscall.Exec(file, args, env)
panic("exec failed")
}
return nil
}