Class: Phidgets::LCD

Inherits:
Common show all
Defined in:
ext/phidgets/phidgets_lcd.c

Constant Summary collapse

FONT_User1 =
INT2NUM(FONT_User1)
FONT_User2 =
INT2NUM(FONT_User2)
FONT_6x10 =
INT2NUM(FONT_6x10)
FONT_5x8 =
INT2NUM(FONT_5x8)
FONT_6x12 =
INT2NUM(FONT_6x12)
SCREEN_SIZE_NONE =
INT2NUM(SCREEN_SIZE_NONE)
SCREEN_SIZE_1x8 =
INT2NUM(SCREEN_SIZE_1x8)
SCREEN_SIZE_2x8 =
INT2NUM(SCREEN_SIZE_2x8)
SCREEN_SIZE_1x16 =
INT2NUM(SCREEN_SIZE_1x16)
SCREEN_SIZE_2x16 =
INT2NUM(SCREEN_SIZE_2x16)
SCREEN_SIZE_4x16 =
INT2NUM(SCREEN_SIZE_4x16)
SCREEN_SIZE_2x20 =
INT2NUM(SCREEN_SIZE_2x20)
SCREEN_SIZE_4x20 =
INT2NUM(SCREEN_SIZE_4x20)
SCREEN_SIZE_2x24 =
INT2NUM(SCREEN_SIZE_2x24)
SCREEN_SIZE_1x40 =
INT2NUM(SCREEN_SIZE_1x40)
SCREEN_SIZE_2x40 =
INT2NUM(SCREEN_SIZE_2x40)
SCREEN_SIZE_4x40 =
INT2NUM(SCREEN_SIZE_4x40)
SCREEN_SIZE_64x128 =
INT2NUM(SCREEN_SIZE_64x128)
PIXEL_STATE_OFF =
INT2NUM(PIXEL_STATE_OFF)
PIXEL_STATE_ON =
INT2NUM(PIXEL_STATE_ON)
PIXEL_STATE_INVERT =
INT2NUM(PIXEL_STATE_INVERT)

Instance Method Summary collapse

Methods inherited from Common

#close, #getAttached, #getChannel, #getChannelClass, #getChannelClassName, #getChannelName, #getChannelSubclass, #getDataInterval, #getDeviceChannelCount, #getDeviceClass, #getDeviceClassName, #getDeviceID, #getDeviceLabel, #getDeviceName, #getDeviceSKU, #getDeviceSerialNumber, #getDeviceVersion, #getHubPort, #getHubPortCount, #getIsChannel, #getIsHubPortDevice, #getIsLocal, #getIsRemote, #getServerHostname, #getServerName, #getServerPeerName, #getServerUniqueName, #open, #openWaitForAttachment, #setChannel, #setDataInterval, #setDeviceLabel, #setDeviceSerialNumber, #setHubPort, #setIsHubPortDevice, #setIsLocal, #setIsRemote, #setOnAttachHandler, #setOnDetachHandler, #setOnErrorHandler, #setOnPropertyChangeHandler, #setServerName, #writeDeviceLabel

Constructor Details

#newObject

Creates a Phidget LCD object.



5
6
7
8
9
# File 'ext/phidgets/phidgets_lcd.c', line 5

VALUE ph_lcd_initialize(VALUE self) {
  ph_data_t *ph = get_ph_data(self);
  ph_raise(PhidgetLCD_create((PhidgetLCDHandle *)(&(ph->handle))));
  return self;
}

Instance Method Details

#clearObject

Clears all pixels in the current frame buffer. Changes made to the frame buffer must be flushed to the LCD screen using flush.



43
44
45
46
# File 'ext/phidgets/phidgets_lcd.c', line 43

VALUE ph_lcd_clear(VALUE self) {
  ph_raise(PhidgetLCD_clear((PhidgetLCDHandle)get_ph_handle(self)));
  return Qnil;
}

#copy(src_framebuffer, dest_framebuffer, src_x1, src_y1, src_x2, src_y2, dest_x, dest_y, inverted) ⇒ Object

Copies all pixels from a specified rectangular region to another.



65
66
67
68
# File 'ext/phidgets/phidgets_lcd.c', line 65

VALUE ph_lcd_copy(VALUE self, VALUE src_fb, VALUE dest_fb, VALUE src_x1, VALUE src_y1, VALUE src_x2, VALUE src_y2, VALUE dest_x, VALUE dest_y, VALUE invert) {
  ph_raise(PhidgetLCD_copy((PhidgetLCDHandle)get_ph_handle(self), NUM2INT(src_fb), NUM2INT(dest_fb), NUM2INT(src_x1), NUM2INT(src_y1), NUM2INT(src_x2), NUM2INT(src_y2), NUM2INT(dest_x), NUM2INT(dest_y), TYPE(invert) == T_TRUE ? PTRUE : PFALSE));
  return Qnil;
}

#drawLine(x1, y1, x2, y2) ⇒ Object Also known as: draw_line

Draws a straight line in the current frame buffer between two specified points. Changes made to the frame buffer must be flushed to the LCD screen using flush.



88
89
90
91
# File 'ext/phidgets/phidgets_lcd.c', line 88

VALUE ph_lcd_draw_line(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2) {
  ph_raise(PhidgetLCD_drawLine((PhidgetLCDHandle)get_ph_handle(self), NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2)));
  return Qnil;
}

#drawPixel(x, y, pixel_state) ⇒ Object Also known as: draw_pixel

Draws, erases, or inverts a single specified pixel. Changes made to the frame buffer must be flushed to the LCD screen using flush.



93
94
95
96
# File 'ext/phidgets/phidgets_lcd.c', line 93

VALUE ph_lcd_draw_pixel(VALUE self, VALUE x, VALUE y, VALUE pixel_state) {
  ph_raise(PhidgetLCD_drawPixel((PhidgetLCDHandle)get_ph_handle(self), NUM2INT(x), NUM2INT(y), NUM2INT(pixel_state)));
  return Qnil;
}

#drawRect(x1, y1, x2, y2, filled, inverted) ⇒ Object Also known as: draw_rect

Draws a rectangle in the current frame buffer using the specified points. Changes made to the frame buffer must be flushed to the LCD screen using flush.



98
99
100
101
# File 'ext/phidgets/phidgets_lcd.c', line 98

VALUE ph_lcd_draw_rect(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE filled, VALUE invert) {
  ph_raise(PhidgetLCD_drawRect((PhidgetLCDHandle)get_ph_handle(self), NUM2INT(x1), NUM2INT(y1), NUM2INT(x2), NUM2INT(y2), TYPE(filled) == T_TRUE ? PTRUE : PFALSE, TYPE(invert) == T_TRUE ? PTRUE : PFALSE));
  return Qnil;
}

#flushObject

Flushes the buffered LCD contents to the LCD screen.



103
104
105
106
# File 'ext/phidgets/phidgets_lcd.c', line 103

VALUE ph_lcd_flush(VALUE self) {
  ph_raise(PhidgetLCD_flush((PhidgetLCDHandle)get_ph_handle(self)));
  return Qnil;
}

#getBacklightObject Also known as: backlight

The Backlight affects the brightness of the LCD screen. Backlight is bounded by MinBackLight and MaxBacklight.



11
12
13
# File 'ext/phidgets/phidgets_lcd.c', line 11

VALUE ph_lcd_get_backlight(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetLCD_getBacklight);
}

#getContrastObject Also known as: contrast

Contrast level of the text or graphic pixels. A higher contrast will make the image darker. Contrast is bounded by MinContrast and MaxContrast.



48
49
50
# File 'ext/phidgets/phidgets_lcd.c', line 48

VALUE ph_lcd_get_contrast(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetLCD_getContrast);
}

When CursorBlink is true, the device will cause the cursor to periodically blink.



70
71
72
# File 'ext/phidgets/phidgets_lcd.c', line 70

VALUE ph_lcd_get_cursor_blink(VALUE self) {
  return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetLCD_getCursorBlink);
}

#getCursorOnObject Also known as: cursor_on?

When CursorOn is true, the device will underline to the cursor position.



79
80
81
# File 'ext/phidgets/phidgets_lcd.c', line 79

VALUE ph_lcd_get_cursor_on(VALUE self) {
  return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetLCD_getCursorOn);
}

#getFontSize(font) ⇒ Object Also known as: font_size

Gets the size of the specified font.



109
110
111
112
113
114
115
116
117
118
# File 'ext/phidgets/phidgets_lcd.c', line 109

VALUE ph_lcd_get_font_size(VALUE self, VALUE font) {
  PhidgetLCDHandle handle = (PhidgetLCDHandle)get_ph_handle(self);
  int width, height;
  VALUE rb_font_size = rb_hash_new();

  ph_raise(PhidgetLCD_getFontSize(handle, NUM2INT(font), &width, &height));
  rb_hash_aset(rb_font_size, rb_str_new2("width"), INT2NUM(width));
  rb_hash_aset(rb_font_size, rb_str_new2("height"), INT2NUM(height));
  return rb_font_size;
}

#getFrameBufferObject Also known as: frame_buffer

The frame buffer that is currently being used. Commands sent to the device are performed on this buffer.



125
126
127
# File 'ext/phidgets/phidgets_lcd.c', line 125

VALUE ph_lcd_get_frame_buffer(VALUE self) {
  return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetLCD_getFrameBuffer);
}

#getHeightObject Also known as: height

The height of the LCD screen attached to the channel.



134
135
136
# File 'ext/phidgets/phidgets_lcd.c', line 134

VALUE ph_lcd_get_height(VALUE self) {
  return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetLCD_getHeight);
}

#getMaxBacklightObject Also known as: max_backlight

The maximum value that Backlight can be set to.



24
25
26
# File 'ext/phidgets/phidgets_lcd.c', line 24

VALUE ph_lcd_get_max_backlight(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetLCD_getMaxBacklight);
}

#getMaxCharactersObject Also known as: max_characters

The maximum number of characters that can fit on the frame buffer for the specified font.



37
38
39
40
41
# File 'ext/phidgets/phidgets_lcd.c', line 37

VALUE ph_lcd_get_max_characters(VALUE self, VALUE font) {
  int max_chars;
  ph_raise(PhidgetLCD_getMaxCharacters((PhidgetLCDHandle)get_ph_handle(self), NUM2INT(font), &max_chars));
  return INT2NUM(max_chars);
}

#getMaxContrastObject Also known as: max_contrast

The maximum value that Contrast can be set to.



61
62
63
# File 'ext/phidgets/phidgets_lcd.c', line 61

VALUE ph_lcd_get_max_contrast(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetLCD_getMaxContrast);
}

#getMinBacklightObject Also known as: min_backlight

The minimum value that Backlight can be set to.



20
21
22
# File 'ext/phidgets/phidgets_lcd.c', line 20

VALUE ph_lcd_get_min_backlight(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetLCD_getMinBacklight);
}

#getMinContrastObject Also known as: min_contrast

The minimum value that Contrast can be set to.



57
58
59
# File 'ext/phidgets/phidgets_lcd.c', line 57

VALUE ph_lcd_get_min_contrast(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetLCD_getMinContrast);
}

#getScreenSizeObject Also known as: screen_size

The size of the LCD screen attached to the channel.



148
149
150
# File 'ext/phidgets/phidgets_lcd.c', line 148

VALUE ph_lcd_get_screen_size(VALUE self) {
  return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetLCD_getScreenSize);
}

#getSleepingObject Also known as: sleeping?

The on/off state of Sleeping. Putting the device to sleep turns off the display and backlight in order to save power. The device will still take commands while asleep, and will wake up if the screen is flushed, or if the contrast or backlight are changed. When the device wakes up, it will return to its last known state, taking into account any changes that happened while asleep.



157
158
159
# File 'ext/phidgets/phidgets_lcd.c', line 157

VALUE ph_lcd_get_sleeping(VALUE self) {
  return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetLCD_getSleeping);
}

#getWidthObject Also known as: width

The width of the LCD screen attached to the channel.



166
167
168
# File 'ext/phidgets/phidgets_lcd.c', line 166

VALUE ph_lcd_get_width(VALUE self) {
  return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetLCD_getWidth);
}

#initObject

Initializes the Text LCD display.



138
139
140
141
# File 'ext/phidgets/phidgets_lcd.c', line 138

VALUE ph_lcd_init(VALUE self) {
  ph_raise(PhidgetLCD_initialize((PhidgetLCDHandle)get_ph_handle(self)));
  return Qnil;
}

#saveFrameBuffer(frame_buffer) ⇒ Object Also known as: save_frame_buffer

Writes the specified frame buffer to flash memory Use sparingly. The flash memory is only designed to be written to 10,000 times before it may become unusable. This method can only be called one time each time the channel is opened.



143
144
145
146
# File 'ext/phidgets/phidgets_lcd.c', line 143

VALUE ph_lcd_save_frame_buffer(VALUE self, VALUE frame_buffer) {
  ph_raise(PhidgetLCD_saveFrameBuffer((PhidgetLCDHandle)get_ph_handle(self), NUM2INT(frame_buffer)));
  return Qnil;
}

#setBacklight(backlight) ⇒ Object Also known as: backlight=

The Backlight affects the brightness of the LCD screen. Backlight is bounded by MinBackLight and MaxBacklight.



15
16
17
18
# File 'ext/phidgets/phidgets_lcd.c', line 15

VALUE ph_lcd_set_backlight(VALUE self, VALUE backlight) {
  ph_raise(PhidgetLCD_setBacklight((PhidgetLCDHandle)get_ph_handle(self), NUM2DBL(backlight)));
  return Qnil;
}

#setCharacterBitmap(font, character, bitmap) ⇒ Object Also known as: set_character_bitmap

Create a bitmap and select a character to represent it. Now, when you use the specific character, the bitmap will show in it’s place.



28
29
30
31
32
33
34
35
# File 'ext/phidgets/phidgets_lcd.c', line 28

VALUE ph_lcd_set_character_bitmap(VALUE self, VALUE font, VALUE character, VALUE bitmap) {
  int i, bitmap_len = RARRAY_LEN(bitmap);
  uint8_t *bm = malloc(bitmap_len);
  for(i=0; i<bitmap_len; i++) { bm[i] = (uint8_t)NUM2CHR(rb_ary_entry(bitmap, i)); }
  ph_raise(PhidgetLCD_setCharacterBitmap((PhidgetLCDHandle)get_ph_handle(self), NUM2INT(font), StringValueCStr(character), bm));
  free(bm);
  return Qnil;
}

#setContrast(contrast) ⇒ Object Also known as: contrast=

Contrast level of the text or graphic pixels. A higher contrast will make the image darker. Contrast is bounded by MinContrast and MaxContrast.



52
53
54
55
# File 'ext/phidgets/phidgets_lcd.c', line 52

VALUE ph_lcd_set_contrast(VALUE self, VALUE contrast) {
  ph_raise(PhidgetLCD_setContrast((PhidgetLCDHandle)get_ph_handle(self), NUM2DBL(contrast)));
  return Qnil;
}

When CursorBlink is true, the device will cause the cursor to periodically blink.



74
75
76
77
# File 'ext/phidgets/phidgets_lcd.c', line 74

VALUE ph_lcd_set_cursor_blink(VALUE self, VALUE cursor_blink) {
  ph_raise(PhidgetLCD_setCursorBlink((PhidgetLCDHandle)get_ph_handle(self), TYPE(cursor_blink) == T_TRUE ? PTRUE : PFALSE));
  return Qnil;
}

#setCursorOn(cursor_on) ⇒ Object Also known as: cursor_on=

When CursorOn is true, the device will underline to the cursor position.



83
84
85
86
# File 'ext/phidgets/phidgets_lcd.c', line 83

VALUE ph_lcd_set_cursor_on(VALUE self, VALUE cursor_on) {
  ph_raise(PhidgetLCD_setCursorOn((PhidgetLCDHandle)get_ph_handle(self), TYPE(cursor_on) == T_TRUE ? PTRUE : PFALSE));
  return Qnil;
}

#setFontSize(font, width, height) ⇒ Object Also known as: set_font_size

Sets the size of the specified font.



120
121
122
123
# File 'ext/phidgets/phidgets_lcd.c', line 120

VALUE ph_lcd_set_font_size(VALUE self, VALUE font, VALUE width, VALUE height) {
  ph_raise(PhidgetLCD_setFontSize((PhidgetLCDHandle)get_ph_handle(self), NUM2INT(font), NUM2INT(width), NUM2INT(height)));
  return Qnil;
}

#setFrameBuffer(frame_buffer) ⇒ Object Also known as: frame_buffer=

The frame buffer that is currently being used. Commands sent to the device are performed on this buffer.



129
130
131
132
# File 'ext/phidgets/phidgets_lcd.c', line 129

VALUE ph_lcd_set_frame_buffer(VALUE self, VALUE frame_buffer) {
  ph_raise(PhidgetLCD_setFrameBuffer((PhidgetLCDHandle)get_ph_handle(self), NUM2INT(frame_buffer)));
  return Qnil;
}

#setScreenSize(screen_size) ⇒ Object Also known as: screen_size=

The size of the LCD screen attached to the channel.



152
153
154
155
# File 'ext/phidgets/phidgets_lcd.c', line 152

VALUE ph_lcd_set_screen_size(VALUE self, VALUE screen_size) {
  ph_raise(PhidgetLCD_setScreenSize((PhidgetLCDHandle)get_ph_handle(self), NUM2INT(screen_size)));
  return Qnil;
}

#setSleeping(sleeping) ⇒ Object Also known as: sleeping=

The on/off state of Sleeping. Putting the device to sleep turns off the display and backlight in order to save power. The device will still take commands while asleep, and will wake up if the screen is flushed, or if the contrast or backlight are changed. When the device wakes up, it will return to its last known state, taking into account any changes that happened while asleep.



161
162
163
164
# File 'ext/phidgets/phidgets_lcd.c', line 161

VALUE ph_lcd_set_sleeping(VALUE self, VALUE sleeping) {
  ph_raise(PhidgetLCD_setSleeping((PhidgetLCDHandle)get_ph_handle(self), TYPE(sleeping) == T_TRUE ? PTRUE : PFALSE));
  return Qnil;
}

#writeBitmap(x_pos, y_pos, x_size, y_size, bitmap) ⇒ Object Also known as: write_bitmap

Draws a bitmap to the current frame buffer at the given location. Each byte in the array represents one pixel in row-major order. Changes made to the frame buffer must be flushed to the LCD screen using flush.



170
171
172
173
174
175
176
177
# File 'ext/phidgets/phidgets_lcd.c', line 170

VALUE ph_lcd_write_bitmap(VALUE self, VALUE x_pos, VALUE y_pos, VALUE x_size, VALUE y_size, VALUE bitmap) {
  int i, bitmap_len = RARRAY_LEN(bitmap);
  uint8_t *bm = malloc(bitmap_len);
  for(i=0; i<bitmap_len; i++) { bm[i] = (uint8_t)NUM2CHR(rb_ary_entry(bitmap, i)); }
  ph_raise(PhidgetLCD_writeBitmap((PhidgetLCDHandle)get_ph_handle(self), NUM2INT(x_pos), NUM2INT(y_pos), NUM2INT(x_size), NUM2INT(y_size), bm));
  free(bm);
  return Qnil;
}

#writeText(font, x_pos, y_pos, text) ⇒ Object Also known as: write_text

Writes text to the current frame buffer at the specified location Changes made to the frame buffer must be flushed to the LCD screen using flush.



179
180
181
182
# File 'ext/phidgets/phidgets_lcd.c', line 179

VALUE ph_lcd_write_text(VALUE self, VALUE font, VALUE x_pos, VALUE y_pos, VALUE text) {
  ph_raise(PhidgetLCD_writeText((PhidgetLCDHandle)get_ph_handle(self), NUM2INT(font), NUM2INT(x_pos), NUM2INT(y_pos), StringValueCStr(text)));
  return Qnil;
}